Utils¶
This package provides utility functions as image operations, various decorators, path operations and time operations.
-
classtype_func
(class_object)[source]¶ Decorator to Check whether the first argument of the decorated function is a subclass of a certain type
Parameters: class_object (Any) – type the first function argument should be subclassed from Returns: Return type: Wrapped Function Raises: AssertionError
– First argument of decorated function is not a subclass of given type
-
dtype_func
(class_object)[source]¶ Decorator to Check whether the first argument of the decorated function is of a certain type
Parameters: class_object (Any) – type the first function argument should have Returns: Return type: Wrapped Function Raises: AssertionError
– First argument of decorated function is not of given type
-
make_deprecated
(new_func)[source]¶ Decorator which raises a DeprecationWarning for the decorated object
Parameters: new_func (Any) – new function which should be used instead of the decorated one Returns: Return type: Wrapped Function Raises: Deprecation Warning
-
numpy_array_func
(func)¶
-
torch_module_func
(func)¶
-
torch_tensor_func
(func)¶
-
bounding_box
(mask, margin=None)[source]¶ Calculate bounding box coordinates of binary mask
Parameters: - mask (SimpleITK.Image) – Binary mask
- margin (int, default: None) – margin to be added to min/max on each dimension
Returns: bounding box coordinates of the form (xmin, xmax, ymin, ymax, zmin, zmax)
Return type:
-
calculate_origin_offset
(new_spacing, old_spacing)[source]¶ Calculates the origin offset of two spacings
Parameters: Returns: origin offset
Return type: np.ndarray
-
max_energy_slice
(img)[source]¶ Determine the axial slice in which the image energy is max
Parameters: img (SimpleITK.Image) – given image Returns: slice index Return type: int
-
sitk_copy_metadata
(img_source, img_target)[source]¶ Copy metadata (=DICOM Tags) from one image to another
Parameters: - img_source (SimpleITK.Image) – Source image
- img_target (SimpleITK.Image) – Source image
Returns: Target image with copied metadata
Return type: SimpleITK.Image
-
sitk_new_blank_image
(size, spacing, direction, origin, default_value=0.0)[source]¶ Create a new blank image with given properties
Parameters: Returns: Blank image with given properties
Return type: SimpleITK.Image
-
sitk_resample_to_image
(image, reference_image, default_value=0.0, interpolator=<sphinx.ext.autodoc.importer._MockObject object>, transform=None, output_pixel_type=None)[source]¶ Resamples Image to reference image
Parameters: - image (SimpleITK.Image) – the image which should be resampled
- reference_image (SimpleITK.Image) – the resampling target
- default_value (float) – default value
- interpolator (Any) – implements the actual interpolation
- transform (Any (default: None)) – transformation
- output_pixel_type (Any (default:None)) – type of output pixels
Returns: resampled image
Return type: SimpleITK.Image
-
sitk_resample_to_shape
(img, x, y, z, order=1)[source]¶ Resamples Image to given shape
Parameters: Returns: Resampled Image
Return type: SimpleITK.Image
-
sitk_resample_to_spacing
(image, new_spacing=(1.0, 1.0, 1.0), interpolator=<sphinx.ext.autodoc.importer._MockObject object>, default_value=0.0)[source]¶ Resamples SITK Image to a given spacing
Parameters: Returns: resampled Image with target spacing
Return type: SimpleITK.Image
-
subdirs
(d)[source]¶ For a given directory, return a list of all subdirectories (full paths)
Parameters: d (string) – given root directory Returns: list of strings of all subdirectories Return type: list
-
class
LookupConfig
(*args, **kwargs)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Helper class to have nested lookups in all subdicts of Config
-
nested_get
(key, *args, **kwargs)[source]¶ Returns all occurances of
key
inself
and subdictsParameters: - key (str) – the key to search for
- *args – positional arguments to provide default value
- **kwargs – keyword arguments to provide default value
Raises: KeyError
– Multiple Values are found for key (unclear which value should be returned) OR No Value was found for key and no default value was givenReturns: value corresponding to key (or default if value was not found)
Return type: Any
-