Add uniform, Gaussian, Laplace, or beta-distributed noise in constant, per-pixel, channel-shared, or randomly localized rectangular patch modes.
Noise can be constant per channel, independent per pixel and channel, shared across channels, or localized inside one or more randomly sampled rectangular patches. Patch-localized noise is useful when spatially restricted corruption should improve robustness without perturbing the complete image.
noise_typeNoise distribution. Default: "uniform".
spatial_modeSpatial sampling mode. Default: "constant".
"constant" samples one value per channel."per_pixel" samples each pixel and channel independently."shared" samples one spatial map and shares it across channels."patch" samples noise only inside random rectangular patches.noise_paramsParameters for the chosen noise distribution. Must match the noise_type:
uniform: ranges: list[tuple[float, float]] List of (min, max) ranges for each channel. Each range must be in [-1, 1]. If only one range is provided, it will be used for all channels.
[(-0.2, 0.2)] # Same range for all channels
[(-0.2, 0.2), (-0.1, 0.1), (-0.1, 0.1)] # Different ranges for RGB
gaussian: mean_range: tuple[float, float], default (0.0, 0.0) Range for sampling mean value, in [-1, 1] std_range: tuple[float, float], default (0.1, 0.1) Range for sampling standard deviation, in [0, 1]
laplace: mean_range: tuple[float, float], default (0.0, 0.0) Range for sampling location parameter, in [-1, 1] scale_range: tuple[float, float], default (0.1, 0.1) Range for sampling scale parameter, in [0, 1]
beta: alpha_range: tuple[float, float], default (0.5, 1.5) Value < 1 = U-shaped, Value > 1 = Bell-shaped Range for sampling first shape parameter, in (0, inf) beta_range: tuple[float, float], default (0.5, 1.5) Value < 1 = U-shaped, Value > 1 = Bell-shaped Range for sampling second shape parameter, in (0, inf) scale_range: tuple[float, float], default (0.1, 0.3) Smaller scale for subtler noise Range for sampling output scale, in [0, 1]
pProbability of applying the transform. Default: 0.5.
patch_count_rangeInclusive range for the number of patches when
spatial_mode="patch". Default: (1, 1).
patch_height_rangePatch height as a fraction of image height. Values must be in
(0, 1]. Default: (0.1, 1.0).
patch_width_rangePatch width as a fraction of image width. Values must be in
(0, 1]. Default: (0.1, 1.0).
per_channelWhen spatial_mode="patch", whether to sample independent noise for every channel.
If False, the same noise is shared across channels. Default: False.
>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> transform = A.Compose(
... [
... A.AdditiveNoise(
... noise_type="gaussian",
... spatial_mode="patch",
... noise_params={"mean_range": (0.0, 0.0), "std_range": (0.05, 0.15)},
... patch_count_range=(1, 3),
... patch_height_range=(0.1, 0.4),
... patch_width_range=(0.1, 0.4),
... p=1.0,
... ),
... ],
... seed=137,
... )
>>> noisy_image = transform(image=image)["image"]per_channel controls only the sampled noise values.