Normalize
Applies various normalization techniques to an image. The specific normalization technique can be selected
with the normalization parameter.
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.
meanMean values for standard normalization. For "standard" normalization, the default values are ImageNet mean values: (0.485, 0.456, 0.406).
stdStandard deviation values for standard normalization. For "standard" normalization, the default values are ImageNet standard deviation :(0.229, 0.224, 0.225).
max_pixel_valueMaximum possible pixel value, used for scaling in standard normalization. Defaults to 255.0.
normalizationSpecifies 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.
pProbability of applying the transform. Defaults to 1.0.
>>> 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"]
>>>
>>> # Min-max normalization
>>> transform_minmax = A.Normalize(normalization="min_max", p=1.0)
>>> normalized_image_minmax = transform_minmax(image=image)["image"]- For "standard" normalization,
mean,std, andmax_pixel_valuemust be provided. - For other normalization types, these parameters are ignored.
- 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.
- ImageNet mean and stdhttps://pytorch.org/vision/stable/models.html
- Inception preprocessinghttps://keras.io/api/applications/inceptionv3/