Intensity Module#
Module: pyradise.process.intensity
General#
The intensity module provides intensity-modifying filters, such as a
ZScoreNormFilter. Furthermore, the intensity module
provides separate intensity filter base classes (i.e., IntensityFilter and
IntensityLoopFilter) to simplify implementation of new intensity-modifying filters
and to facilitate the user-driven implementation.
Class Overview#
The following classes are provided by the intensity module:
Class |
Description |
|---|---|
Parameterization base class for the |
|
Simplified base class for intensity filters. |
|
Parameterization base class for the |
|
Simplified base class for intensity filters that process the images via looping over a predefined axis. |
|
Parameterization class for the |
|
Filter for z-score normalization of |
|
Parameterization class for the |
|
Filter for zero-one (1-0) normalization of |
|
Parameterization class for the |
|
Filter to rescale intensity values of |
|
Parameterization class for the |
|
Filter to limit intensity values of |
|
Parameterization class for the |
|
Filter for Gaussian blurring of |
|
Parameterization class for the |
|
Filter for median blurring of |
|
Parameterization class for the |
|
Filter for Laplacian sharpening of |
Details#
- class IntensityFilterParams(modalities=None)[source]#
Bases:
FilterParamsA filter parameter class for the
IntensityFilterbase class. In addition to theFilterParamsclass, this class also provides amodalitiesparameter to specify the images to be processed by the filters.- Parameters:
modalities (Optional[Tuple[Union[Modality, str], ...]]) – The modalities associated with the corresponding
IntensityImageinstances that should be processed. IfNoneis provided, allIntensityImageinstances will be processed (default: None).
- class IntensityFilter(warning_on_non_invertible=False)[source]#
Bases:
FilterAn abstract filter base class for intensity modifying filters which process the whole image content. In contrast to the
Filterbase class, this class provides two additional abstract methods ( i.e._process_image()and_process_image_inverse()) for processing the image content as whole. Thus, this base class is intended to be used for intensity modifying filters which process the whole image content at once.Note
The selection of the
IntensityImageinstances to be processed is specified by theIntensityFilterParamsinstance. If themodalitiesparameter is set toNone, allIntensityImageinstances will be processed. Otherwise, only theIntensityImageinstances with the specified modalities will be processed. If the user wants to implement its own intensity modifying filter, the user do not need to implement the selection of the images to be processed. The selection mechanism is already provided in the implementedexecute()andexecute_inverse()methods.Example
An example implementation of an intensity clippling filter:
>>> class ClipFilterParams(IntensityFilterParams): >>> def __init__(self, >>> min_out: float, >>> max_out: float, >>> modalities: Optional[Tuple[Union[Modality, str], ...]] = None >>> ) -> None: >>> super().__init__(modalities) >>> >>> if min_out == max_out: >>> raise ValueError('The min and max output intensity ' >>> 'values must not be equal because ' >>> 'the resulting image ' >>> 'will have constant intensity.') >>> >>> if min_out > max_out: >>> min_out, max_out = max_out, min_out >>> >>> self.min_value: float = min_out >>> self.max_value: float = max_out >>> >>> >>> class ClipFilter(IntensityFilter): >>> >>> @staticmethod >>> def is_invertible() -> bool: >>> # return False because the clipping is not invertible >>> return False >>> >>> def _process_image(self, >>> image: IntensityImage, >>> params: ClipFilterParams >>> ) -> IntensityImage: >>> # get the image data >>> sitk_image = image.get_image_data() >>> >>> # apply the clipping >>> clipped_image_sitk = sitk.Clamp(sitk_image, >>> sitk_image.GetPixelIDValue(), >>> params.min_value, >>> params.max_value) >>> >>> # add the clipped SimpleITK image to the image >>> image.set_image_data(clipped_image_sitk) >>> >>> # track the necessary information >>> self._register_tracked_data(image, sitk_image, >>> clipped_image_sitk, params) >>> >>> return image >>> >>> def _process_image_inverse(self, >>> image: IntensityImage, >>> transform_info: TransformInfo >>> ) -> IntensityImage: >>> # return the original image because the clipping >>> # is not invertible >>> return image >>> >>> def execute(self, >>> subject: Subject, >>> params: ClipFilterParams >>> ) -> Subject: >>> # implement exclusively due to type adaptation for params >>> return super().execute(subject, params)
- execute(subject, params)[source]#
Execute the intensity modifying procedure.
- Parameters:
params (IntensityFilterParams) – The filter parameters.
- Returns:
The
Subjectinstance with processedIntensityImageinstances.- Return type:
- execute_inverse(subject, transform_info, target_image=None)[source]#
Execute the inverse intensity modifying procedure.
- Parameters:
transform_info (TransformInfo) – The transform information.
target_image (Optional[Union[SegmentationImage, IntensityImage]]) – The target image to which the inverse transformation should be applied. If None, the inverse transformation is applied to all images (default: None).
- Returns:
The
Subjectinstance with processedIntensityImageinstances.- Return type:
- class IntensityLoopFilterParams(loop_axis, modalities=None)[source]#
Bases:
LoopEntryFilterParamsA filter parameter class for the
IntensityLoopFilterbase class. In addition to theLoopEntryFilterParamsclass, this class also provides amodalitiesparameter to specify the images to be processed by the filters.- Parameters:
loop_axis (Optional[int]) – The axis along which the data transformation is performed. If
None, the transformation is performed on the whole image at once. If a value is given, the transformation is performed by looping over the corresponding image dimension.modalities (Optional[Tuple[Union[Modality, str], ...]]) – The modalities associated with the corresponding
IntensityImageinstances that should be processed. IfNoneis provided, allIntensityImageinstances will be processed (default: None).
- class IntensityLoopFilter[source]#
Bases:
LoopEntryFilterAn abstract base class for intensity modifying filters that can process the provided image content by looping over a specific axis or by using the whole image extent at once. This base class is intended to be used for implementing flexible intensity modifying filters that can iteratively process subsets of the image content such as for example normalization filters which may be applied slice-wise to the image content.
For the implementation of a new
IntensityLoopFiltersubclass implement the provided_modify_array()and_modify_array_inverse()methods. Both methods are called iteratively for each loop axis position. The_modify_array()method is called for the forward processing and the_modify_array_inverse()method is called for the inverse processing.Note
The selection of the
IntensityImageinstances to be processed is specified by theIntensityLoopFilterParamsinstance. If themodalitiesparameter is set toNone, allIntensityImageinstances will be processed. Otherwise, only theIntensityImageinstances with the specified modalities will be processed. If the user wants to implement its own intensity modifying filter, the user do not need to implement the selection of the images to be processed. The selection mechanism is already provided in the implementedexecute()andexecute_inverse()methods.- execute(subject, params)[source]#
Execute the intensity modifying procedure.
- Parameters:
params (IntensityLoopFilterParams) – The filter parameters.
- Returns:
The
Subjectinstance with processedIntensityImageinstances.- Return type:
- execute_inverse(subject, transform_info, target_image=None)[source]#
Execute the inverse intensity modifying procedure.
- Parameters:
transform_info (TransformInfo) – The transform information.
target_image (Optional[Union[SegmentationImage, IntensityImage]]) – The target image to which the inverse transformation should be applied. If None, the inverse transformation is applied to all images (default: None).
- Returns:
The
Subjectinstance with processedIntensityImageinstances.- Return type:
- class ZScoreNormFilterParams(loop_axis=None, modalities=None)[source]#
Bases:
IntensityLoopFilterParamsA filter parameter class for the
ZScoreNormFilterclass.- Parameters:
loop_axis (Optional[int]) – The axis along which the intensity normalization is performed. If None, the intensity normalization is performed on the whole image extent at once. If a value is given, the intensity normalization is performed by looping over the corresponding image dimension (default: None).
modalities (Optional[Tuple[Union[Modality, str], ...]]) – The modalities of the images to be rescaled. If
Noneis provided all images of the provided subject are rescaled (default: None).
- class ZScoreNormFilter[source]#
Bases:
IntensityLoopFilterA normalization filter class performing an invertible z-score normalization on all
IntensityImageinstances of the providedSubjectinstance.For the normalization the following formula is applied to the image extent or its subsets:

For the inverse normalization the following formula is applied to the image extent or its subsets:

During the normalization procedure, the intensity mean and standard deviation of the original image or its subsets are tracked such that these values are available for the inverse normalization.
Warning
The inverse normalization procedure may not yield the expected results if successive
Filters are applied to the sameImageinstances. Thus, it’s recommended to use the invertibility feature with appropriate caution.Note
Due to the limited precision of floating point numbers, the inverse normalization may not be exact.
- static is_invertible()[source]#
Check if the filter is invertible.
- Returns:
True because the z-score normalization procedure is invertible.
- Return type:
bool
- execute(subject, params)[source]#
Execute the z-score normalization procedure.
- Parameters:
params (ZScoreNormFilterParams) – The filter parameters.
- Returns:
The
Subjectinstance with z-score normalizedIntensityImageinstances.- Return type:
- execute_inverse(subject, transform_info, target_image=None)[source]#
Execute the inverse z-score normalization procedure.
- Parameters:
transform_info (TransformInfo) – The transform information.
target_image (Optional[Union[SegmentationImage, IntensityImage]]) – The target image to which the inverse transformation should be applied. If None, the inverse transformation is applied to all images (default: None).
- Returns:
The
Subjectinstance with denormalizedIntensityImageinstances.- Return type:
- class ZeroOneNormFilterParams(loop_axis=None, modalities=None)[source]#
Bases:
IntensityLoopFilterParamsA filter parameter class for the
ZeroOneNormFilterclass.- Parameters:
loop_axis (Optional[int]) – The axis along which the intensity normalization is performed. If None, the intensity normalization is performed on the whole image extent at once. If a value is given, the intensity normalization is performed by looping over the corresponding image dimension (default: None).
modalities (Optional[Tuple[Union[Modality, str], ...]]) – The modalities of the images to be rescaled. If
Noneis provided all images of the provided subject are rescaled (default: None).
- class ZeroOneNormFilter[source]#
Bases:
IntensityLoopFilterA normalization filter class performing an invertible zero-one (1-0) normalization on all
IntensityImageinstances of the providedSubjectinstance.For the normalization the following formula is applied to the image extent or its subsets:

For the inverse normalization the following formula is applied to the image extent or its subsets:

During the normalization procedure, the min and max intensity values of the image or its subsets are tracked to be available for inverse normalization.
Warning
The inverse normalization procedure may not yield the expected results if successive
Filters are applied to the sameImageinstances. Thus, it’s recommended to use the invertibility feature with appropriate caution.Note
Due to the limited precision of floating point numbers, the inverse normalization may not be exact.
- static is_invertible()[source]#
Check if the filter is invertible.
- Returns:
True because the zero-one normalization procedure is invertible.
- Return type:
bool
- execute(subject, params)[source]#
Execute the zero-one normalization procedure.
- Parameters:
params (ZeroOneNormFilterParams) – The filter parameters.
- Returns:
The
Subjectinstance with zero-one normalizedIntensityImageinstances.- Return type:
- execute_inverse(subject, transform_info, target_image=None)[source]#
Execute the inverse zero-one normalization procedure.
- Parameters:
transform_info (TransformInfo) – The transform information.
target_image (Optional[Union[SegmentationImage, IntensityImage]]) – The target image to which the inverse transformation should be applied. If None, the inverse transformation is applied to all images (default: None).
- Returns:
The
Subjectinstance with denormalizedIntensityImageinstances.- Return type:
- class RescaleIntensityFilterParams(min_out, max_out, modalities=None)[source]#
Bases:
IntensityFilterParamsA filter parameter class for the
RescaleIntensityFilterclass.- Parameters:
min_out (Optional[float]) – The minimum value of the rescaled image. If
Noneis provided the filter takes the minimum intensity value of the image.max_out (Optional[float]) – The maximum value of the rescaled image. If
Noneis provided the filter takes the maximum intensity value of the image.modalities (Optional[Tuple[Union[Modality, str], ...]]) – The modalities of the images to be rescaled. If
Noneis provided all images of the provided subject are rescaled (default: None).
- class RescaleIntensityFilter(warning_on_non_invertible=False)[source]#
Bases:
IntensityFilterA filter class performing an invertible intensity rescaling on all selected
IntensityImageinstances of the providedSubjectinstance.For the rescaling the following formula is applied to the image extent or its subsets:

For the inverse rescaling the following formula is applied to the image extent or its subsets:

During the rescaling procedure, the min and max intensity of the original image or its subsets are tracked to be available for inverse rescaling.
Warning
The inverse rescaling procedure may not yield the expected results if successive
Filters are applied to the sameImageinstances. Thus, it’s recommended to use the invertibility feature with appropriate caution.Note
Due to the limited precision of floating point numbers, the inverse normalization may not be exact.
- static is_invertible()[source]#
Check if the filter is invertible.
- Returns:
True because the rescaling procedure is invertible.
- Return type:
bool
- execute(subject, params)[source]#
Execute the rescaling procedure.
- Parameters:
params (RescaleIntensityFilterParams) – The filter parameters.
- Returns:
The
Subjectinstance with rescaledIntensityImageentries.- Return type:
- execute_inverse(subject, transform_info, target_image=None)[source]#
Execute the inverse rescaling procedure.
- Parameters:
subject (Subject) – The
Subjectinstance to be inversely rescaled.transform_info (TransformInfo) – The transform information.
target_image (Optional[Union[SegmentationImage, IntensityImage]]) – The target image to which the inverse transformation should be applied. If None, the inverse transformation is applied to all images (default: None).
- Returns:
The
Subjectinstance with inversely rescaledIntensityImageentries.- Return type:
- class ClipIntensityFilterParams(min_out, max_out, modalities=None)[source]#
Bases:
IntensityFilterParamsA filter parameter class for the
ClipIntensityFilterclass.- Parameters:
min_out (float) – The minimum intensity value of the processed image.
max_out (float) – The maximum intensity value of the processed image.
modalities (Optional[Tuple[Union[Modality, str], ...]]) – The modalities of the images to be clipped. If
Noneis provided all images of the provided subject are clipped (default: None).
- class ClipIntensityFilter(warning_on_non_invertible=False)[source]#
Bases:
IntensityFilterA filter class performing a clipping of intensity values on all selected
IntensityImageinstances of the providedSubjectinstance. The clipping procedure sets the intensity values outside the specified range to the specified minimum and maximum values.For the clipping procedure the following formula is applied to the image data:

Note
The clipping procedure causes a loss of information which can not be recovered. Thus, the clipping procedure is not invertible.
- static is_invertible()[source]#
Check if the filter is invertible.
- Returns:
False because the clipping procedure is not invertible.
- Return type:
bool
- execute(subject, params)[source]#
Execute the clipping procedure.
- Parameters:
params (ClipIntensityFilterParams) – The filter parameters.
- Returns:
The
Subjectinstance with clippedIntensityImageinstances.- Return type:
- execute_inverse(subject, transform_info, target_image=None)[source]#
Return the provided subject without any processing because the clipping procedure is not invertible.
- Parameters:
transform_info (TransformInfo) – The transform information.
target_image (Optional[Union[SegmentationImage, IntensityImage]]) – The target image to which the inverse transformation should be applied. If None, the inverse transformation is applied to all images (default: None).
- Returns:
The provided
Subjectinstance.- Return type:
- class GaussianFilterParams(variance, kernel_size, modalities=None)[source]#
Bases:
IntensityFilterParamsA filter parameter class for the
GaussianFilterclass.- Parameters:
variance (float) – The variance of the Gaussian kernel.
kernel_size (int) – The kernel size of the Gaussian kernel.
modalities (Optional[Tuple[Union[Modality, str], ...]]) – The modalities of the images to be filtered. If
Noneis provided all images of the provided subject are filtered (default: None).
- class GaussianFilter(warning_on_non_invertible=False)[source]#
Bases:
IntensityFilterA filter class performing a Gaussian smoothing on all
IntensityImageinstances of the providedSubjectinstance.- Reference:
The implementation is based on the SimpleITK implementation of the SimpleITK DiscreteGaussianImageFilter.
Note
The Gaussian smoothing procedure is not invertible.
- is_invertible()[source]#
Check if the filter is invertible.
- Returns:
False because the Gaussian filter is not invertible.
- Return type:
bool
- execute(subject, params)[source]#
Execute the Gaussian filter.
- Parameters:
params (GaussianFilterParams) – The filter parameters.
- Returns:
The
Subjectinstance with Gaussian filteredIntensityImageinstances.- Return type:
- execute_inverse(subject, transform_info, target_image=None)[source]#
Return the provided subject without any processing because the Gaussian filtering procedure is not invertible.
- Parameters:
transform_info (TransformInfo) – The transform information.
target_image (Optional[Union[SegmentationImage, IntensityImage]]) – The target image to which the inverse transformation should be applied. If None, the inverse transformation is applied to all images (default: None).
- Returns:
The provided
Subjectinstance.- Return type:
- class MedianFilterParams(radius, modalities=None)[source]#
Bases:
IntensityFilterParamsA filter parameter class for the
MedianFilterclass.- Parameters:
radius (int) – The radius of the median filter.
modalities (Optional[Tuple[Union[Modality, str], ...]]) – The modalities of the images to be filtered. If
Noneis provided all images of the provided subject are filtered (default: None).
- class MedianFilter(warning_on_non_invertible=False)[source]#
Bases:
IntensityFilterA filter class performing a median filtering on all
IntensityImageinstances of the providedSubjectinstance.- Reference:
The implementation is based on the SimpleITK implementation of the SimpleITK MedianImageFilter.
Note
The median filter is not invertible.
- static is_invertible()[source]#
Check if the filter is invertible.
- Returns:
False because the median filter is not invertible.
- Return type:
bool
- execute(subject, params)[source]#
Execute the median filter.
- Parameters:
params (MedianFilterParams) – The filter parameters.
- Returns:
The
Subjectinstance with filteredIntensityImageinstances.- Return type:
- execute_inverse(subject, transform_info, target_image=None)[source]#
Return the provided subject without any processing because the median filtering procedure is not invertible.
- Parameters:
transform_info (TransformInfo) – The transform information.
target_image (Optional[Union[SegmentationImage, IntensityImage]]) – The target image to which the inverse transformation should be applied. If None, the inverse transformation is applied to all images (default: None).
- Returns:
The provided
Subjectinstance.- Return type:
- class LaplacianFilterParams(modalities=None)[source]#
Bases:
IntensityFilterParamsA filter parameter class for the
LaplacianFilterclass.- Parameters:
modalities (Optional[Tuple[Union[Modality, str], ...]]) – The modalities of the images to be filtered. If
Noneis provided all images of the provided subject are filtered (default: None).
- class LaplacianFilter(warning_on_non_invertible=False)[source]#
Bases:
IntensityFilterA filter class performing a Laplacian sharpening on all
IntensityImageinstances of the providedSubjectinstance.- Reference:
The implementation is based on the SimpleITK implementation of the SimpleITK LaplacianSharpeningImageFilter.
Note
The Laplacian filter is not invertible.
- static is_invertible()[source]#
Check if the filter is invertible.
- Returns:
False because the Laplacian filter is not invertible.
- Return type:
bool
- execute(subject, params=None)[source]#
Execute the Laplacian sharpening filter.
- Parameters:
params (Optional[LaplacianFilterParams]) – The unused filter parameters.
- Returns:
The
Subjectinstance with Laplace filteredIntensityImageinstances.- Return type:
Note
The Laplacian filter does not need any parameters.
- execute_inverse(subject, transform_info, target_image=None)[source]#
Return the provided subject without any processing because the Laplace filtering procedure is not invertible.
- Parameters:
transform_info (TransformInfo) – The transform information.
target_image (Optional[Union[SegmentationImage, IntensityImage]]) – The target image to which the inverse transformation should be applied. If None, the inverse transformation is applied to all images (default: None).
- Returns:
The provided
Subjectinstance.- Return type: