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.
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".
(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.clip_rangeLower 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.
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"]
>>>
>>> # 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"]mean, std, and max_pixel_value must be provided.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.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).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).