AlbumentationsExplore
DocumentationExploreAdoptionPricingBlog
GitHub

Normalize

Targets:
image
volume
Image Types:uint8, float32

Normalize image intensities with fixed statistics or values computed from each image, with optional clipping for bounded model inputs.

Standard normalization is applied using the formula: img = (img - mean * max_pixel_value) / (std * max_pixel_value). Other normalization techniques adjust the image based on global or per-channel statistics, or scale pixel values to a specified range. If clip_range is provided, the transform clips the normalized float32 output to those bounds.

Arguments
mean
tuple[float, ...] | float | None
[0.485, 0.456, 0.406]

Mean values for standard normalization. For "standard" normalization, the default values are ImageNet mean values: (0.485, 0.456, 0.406).

std
tuple[float, ...] | float | None
[0.229, 0.224, 0.225]

Standard deviation values for standard normalization. For "standard" normalization, the default values are ImageNet standard deviation :(0.229, 0.224, 0.225).

max_pixel_value
float | None
255

Maximum possible pixel value, used for scaling in standard normalization. Defaults to 255.0.

normalization
standard | image | image_per_channel | min_max | min_max_per_channel
standard

Specifies the normalization technique to apply. Defaults to "standard".

  • "standard": Applies the formula (img - mean * max_pixel_value) / (std * max_pixel_value). The default mean and std are based on ImageNet. You can use mean and std values of (0.5, 0.5, 0.5) for inception normalization. And mean values of (0, 0, 0) and std values of (1, 1, 1) for YOLO.
  • "image": Normalizes the whole image based on its global mean and standard deviation.
  • "image_per_channel": Normalizes the image per channel based on each channel's mean and standard deviation.
  • "min_max": Scales the image pixel values to a [0, 1] range based on the global minimum and maximum pixel values.
  • "min_max_per_channel": Scales each channel of the image pixel values to a [0, 1] range based on the per-channel minimum and maximum pixel values.
clip_range
tuple[float, float] | None

Lower and upper bounds for the normalized output. The transform clips after applying the selected normalization method. None leaves the normalized values unchanged. Defaults to None.

p
float
1

Probability of applying the transform. Defaults to 1.0.

Examples
>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> # Standard ImageNet normalization
>>> transform = A.Normalize(
...     mean=(0.485, 0.456, 0.406),
...     std=(0.229, 0.224, 0.225),
...     max_pixel_value=255.0,
...     p=1.0
... )
>>> normalized_image = transform(image=image)["image"]
>>>
>>> # Fixed dataset-level min-max normalization with clipping
>>> dataset_min = (0.1, 0.2, 0.3)
>>> dataset_max = (0.8, 0.9, 1.0)
>>> dataset_range = tuple(maximum - minimum for minimum, maximum in zip(dataset_min, dataset_max))
>>> transform_fixed_minmax = A.Normalize(
...     mean=dataset_min,
...     std=dataset_range,
...     max_pixel_value=1.0,
...     clip_range=(0.0, 1.0),
...     p=1.0,
... )
>>> normalized_image_fixed = transform_fixed_minmax(image=image.astype(np.float32) / 255.0)["image"]
>>>
>>> # Per-image min-max normalization derives new extrema from this image
>>> transform_minmax = A.Normalize(normalization="min_max", p=1.0)
>>> normalized_image_minmax = transform_minmax(image=image)["image"]
Notes
  • For "standard" normalization, mean, std, and max_pixel_value must be provided.
  • For other normalization types, these parameters are ignored.
  • normalization="min_max" and normalization="min_max_per_channel" calculate bounds from the current input. Keep normalization="standard" when using fixed bounds calculated from the whole dataset.
  • For [0, 1] output, set mean to each channel's dataset minimum and std to that channel's range (dataset maximum minus minimum). Set max_pixel_value=1.0 and clip_range=(0.0, 1.0).
  • For [-1, 1] output, set mean to the midpoint between each channel's dataset minimum and maximum and std to half of that range. Set max_pixel_value=1.0 and clip_range=(-1.0, 1.0).
  • For inception normalization, use mean values of (0.5, 0.5, 0.5).
  • For YOLO normalization, use mean values of (0, 0, 0) and std values of (1, 1, 1).
  • This transform is often used as a final step in image preprocessing pipelines to prepare images for neural network input.
References
  • ImageNet mean and stdhttps://pytorch.org/vision/stable/models.html
  • Inception preprocessinghttps://keras.io/api/applications/inceptionv3/