Skip to content

Normalization

Source

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.

__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)

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.

denormalize(patch)

Reverse the normalization operation for a batch of patches.

Parameters:

  • patch (Tensor) –

    Patch, 2D or 3D, shape BC(Z)YX.

Returns:

  • Tensor

    Transformed 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.

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.

__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)

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.

denormalize(patch)

Reverse the normalization operation for a batch of patches.

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, patching_strategy, input_extractor, target_extractor=None, channels=None)

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).

  • patching_strategy (PatchingStrategy) –

    Strategy for iterating over patches.

  • input_extractor (PatchExtractor) –

    Extractor for input data.

  • target_extractor (PatchExtractor, default: None ) –

    Extractor for target data.

  • channels (sequence of int or None, default: None ) –

    Channels to compute statistics for; None for all.

Returns:

  • NormalizationConfig

    A resolved configuration with all statistics populated.