Normalization
Normalization types.
MeanStdNormalization
Bases: Normalization
Zero-mean and unit-variance normalization.
The normalization expects arrays of dimensions C(Z)YX.
Parameters:
-
input_means(list[float]) –Mean values (length 1 for global, multiple values for per channel).
-
input_stds(list[float]) –Standard deviation values (length 1 for global, multiple values for per channel).
-
target_means(list[float] | None, default:None) –Target mean values (length 1 for global, multiple values for per channel), by default None.
-
target_stds(list[float] | None, default:None) –Target standard deviation values (length 1 for global, multiple values for per channel), by default None.
-
skip_target(bool, defaut=False, default:False) –When True, target normalization is skipped and the target is returned unchanged.
__call__(patch, target=None)
Apply the transform to the source patch and the target (optional).
Parameters:
-
patch(ndarray) –Patch, 2D or 3D, shape C(Z)YX.
-
target(ndarray, default:None) –Target for the patch, by default None.
Returns:
-
tuple of numpy.ndarray–Transformed patch and target, the target can be returned as
None.
__init__(input_means, input_stds, target_means=None, target_stds=None, skip_target=False)
Constructor.
Parameters:
-
input_means(list[float]) –Mean values (length 1 for global, multiple values for per channel).
-
input_stds(list[float]) –Standard deviation values (length 1 for global, multiple values for per channel).
-
target_means(list[float] | None, default:None) –Target mean values (length 1 for global, multiple values for per channel), by default None.
-
target_stds(list[float] | None, default:None) –Target standard deviation values (length 1 for global, multiple values for per channel), by default None.
-
skip_target(bool, defaut=False, default:False) –When True, target normalization is skipped and the target is returned unchanged.
denormalize(patch)
Reverse the normalization operation for a batch of patches.
The data is denormalized using the target statistics, when available. When no target statistics are available, which is the case for self-supervised algorithms such as N2V, the data is denormalized using the input statistics.
If self.skip_target is True, then this method returns patch.
Parameters:
-
patch(Tensor) –Patch, 2D or 3D, shape BC(Z)YX.
Returns:
-
Tensor–Denormalized array.
NoNormalization
Bases: Normalization
No-op normalization transform returning patches unchanged.
Parameters:
-
**kwargs(Any, default:{}) –Additional keyword arguments.
__call__(patch, target=None)
Apply no normalization to the patch and target.
Parameters:
-
patch(NDArray) –Patch, 2D or 3D, shape C(Z)YX.
-
target(NDArray, default:None) –Target for the patch, by default None.
Returns:
-
tuple of NDArray–Transformed patch and target, the target can be returned as
None.
__init__(**kwargs)
Initialize the no normalization transform.
Parameters:
-
**kwargs(Any, default:{}) –Additional keyword arguments.
denormalize(patch)
Reverse the normalization operation for a batch of patches.
Parameters:
-
patch(Tensor) –Patch, 2D or 3D, shape BC(Z)YX.
Returns:
-
Tensor–Denormalized patch.
RangeNormalization
Bases: Normalization
Normalize an image or image patch to [0, 1] range.
This transform expects C(Z)YX dimensions for normalization and BC(Z)YX for denormalization. Returns float32 arrays.
Parameters:
-
input_mins(list of float) –Minimum value per channel.
-
input_maxes(list of float) –Maximum value per channel.
-
target_mins(list of float, default:None) –Target minimum value per channel.
-
target_maxes(list of float, default:None) –Target maximum value per channel.
-
skip_target(bool, default:False) –When True, target normalization is skipped and the target is returned unchanged.
Attributes:
-
input_mins(list of float) –Minimum value per channel.
-
input_maxes(list of float) –Maximum value per channel.
-
target_mins(list of float, optional) –Target minimum value per channel.
-
target_maxes(list of float, optional) –Target maximum value per channel.
-
skip_target(bool) –When True, target normalization is skipped and the target is returned unchanged.
__call__(patch, target=None)
Apply range normalization to patch and optional target.
Parameters:
-
patch(NDArray) –Patch with shape C(Z)YX.
-
target(NDArray, default:None) –Target patch with shape C(Z)YX.
Returns:
-
tuple of NDArray–Normalized patch and target (target can be None).
__init__(input_mins, input_maxes, target_mins=None, target_maxes=None, skip_target=False)
Initialize range normalization.
Parameters:
-
input_mins(list of float) –Minimum value per channel.
-
input_maxes(list of float) –Maximum value per channel.
-
target_mins(list of float or None, default:None) –Target minimum per channel.
-
target_maxes(list of float or None, default:None) –Target maximum per channel.
-
skip_target(bool, default:False) –When True, target normalization is skipped and the target is returned unchanged (as float32). Default is False.
denormalize(patch)
Reverse the normalization operation for a batch of patches.
The data is denormalized using the target range, when available. When no target range is available, which is the case for self-supervised algorithms such as N2V, the data is denormalized using the input range.
If self.skip_target is True, then this method returns patch.
Parameters:
-
patch(Tensor) –Normalized patch with shape BC(Z)YX.
Returns:
-
Tensor–Denormalized patch.
create_normalization(norm_model)
Build a normalization transform from a normalization model.
Parameters:
-
norm_model(NormalizationConfig) –The normalization configuration.
Returns:
-
NormalizationProtocol–The normalization transform.
resolve_normalization_config(norm_config, patch_constructor)
Resolve a normalization config by computing any missing statistics.
If statistics are already provided in the config, they are preserved. If statistics are missing (None), they are computed from the data.
Parameters:
-
norm_config(NormalizationConfig) –The normalization configuration (may have missing statistics).
-
patch_constructor(PatchConstructor) –Constructor for paired input and target patches.
Returns:
-
NormalizationConfig–A resolved configuration with all statistics populated.