AlbumentationsExplore
DocumentationExploreAdoptionPricingBlog
GitHub

AdditiveNoise

Targets:
image
volume
Image Types:uint8, float32

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.

Arguments
noise_type
uniform | gaussian | laplace | beta
uniform

Noise distribution. Default: "uniform".

spatial_mode
constant | per_pixel | shared | patch
constant

Spatial 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_params
dict[str, Any] | None

Parameters 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]

p
float
0.5

Probability of applying the transform. Default: 0.5.

patch_count_range
tuple[int, int]
[1, 1]

Inclusive range for the number of patches when spatial_mode="patch". Default: (1, 1).

patch_height_range
tuple[float, float]
[0.1, 1]

Patch height as a fraction of image height. Values must be in (0, 1]. Default: (0.1, 1.0).

patch_width_range
tuple[float, float]
[0.1, 1]

Patch width as a fraction of image width. Values must be in (0, 1]. Default: (0.1, 1.0).

per_channel
bool
false

When spatial_mode="patch", whether to sample independent noise for every channel. If False, the same noise is shared across channels. Default: False.

Examples
>>> 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"]
Notes
  • Patch positions and sizes are shared across channels. per_channel controls only the sampled noise values.
  • Overlapping patches are processed in order, and later patch noise replaces earlier noise in the overlap.
  • Image batches and volume slices receive the same sampled patch program, matching the existing batch behavior.
  • All noise is generated in normalized units and scaled by the image dtype maximum.
References
  • Patch GaussianImproving Generalization of Convolutional Neural Networks without Encouraging Invariance: https://openreview.net/forum?id=HkxWXkStDB