Stay updated

News & Insights
utils

albumentations.augmentations.pixel.noise


Random noise to channels: uniform, gaussian, laplace, or beta. spatial_mode: constant, per_pixel, or shared. Params depend on noise_type.

AdditiveNoiseclass

AdditiveNoise(
    noise_type: 'uniform' | 'gaussian' | 'laplace' | 'beta' = uniform,
    spatial_mode: 'constant' | 'per_pixel' | 'shared' = constant,
    noise_params: dict[str, Any] | None,
    approximation: float = 1.0,
    p: float = 0.5
)

Random noise to channels: uniform, gaussian, laplace, or beta. spatial_mode: constant, per_pixel, or shared. Params depend on noise_type. This transform generates noise using different probability distributions and applies it to image channels. The noise can be generated in three spatial modes and supports multiple noise distributions, each with configurable parameters.

Parameters

NameTypeDefaultDescription
noise_type
One of:
  • 'uniform'
  • 'gaussian'
  • 'laplace'
  • 'beta'
uniformType of noise distribution to use. Options: - "uniform": Uniform distribution, good for simple random perturbations - "gaussian": Normal distribution, models natural random processes - "laplace": Similar to Gaussian but with heavier tails, good for outliers - "beta": Flexible bounded distribution, can be symmetric or skewed
spatial_mode
One of:
  • 'constant'
  • 'per_pixel'
  • 'shared'
constantHow to generate and apply the noise. Options: - "constant": One noise value per channel, fastest - "per_pixel": Independent noise value for each pixel and channel, slowest - "shared": One noise map shared across all channels, medium speed
noise_params
One of:
  • 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]
approximationfloat1.0float in [0, 1], default=1.0 Controls noise generation speed vs quality tradeoff. - 1.0: Generate full resolution noise (slowest, highest quality) - 0.5: Generate noise at half resolution and upsample - 0.25: Generate noise at quarter resolution and upsample Only affects 'per_pixel' and 'shared' spatial modes.
pfloat0.5-

Examples

>>> # Constant RGB shift with different ranges per channel:
>>> transform = AdditiveNoise(
...     noise_type="uniform",
...     spatial_mode="constant",
...     noise_params={"ranges": [(-0.2, 0.2), (-0.1, 0.1), (-0.1, 0.1)]}
... )

FilmGrainclass

FilmGrain(
    intensity_range: tuple[float, float] = (0.1, 0.3),
    grain_size_range: tuple[int, int] = (1, 3),
    p: float = 0.5
)

Analog film grain: luminance-dependent, spatially correlated noise. Distinct from i.i.d. GaussNoise or ShotNoise. Use for vintage or film-like augmentation. Unlike GaussNoise or ShotNoise, film grain is: - Luminance-dependent: darker areas show more visible grain - Spatially correlated: grain is clumped, not i.i.d. per-pixel - Optionally chromatic: separate grain patterns per channel

Parameters

NameTypeDefaultDescription
intensity_rangetuple[float, float](0.1, 0.3)Range for grain intensity. Higher values give more prominent grain. Default: (0.1, 0.3).
grain_size_rangetuple[int, int](1, 3)Grain resolution as divisor of image size. 1 = full resolution (fine); larger = coarser, more clumped. Default: (1, 3).
pfloat0.5Probability of applying the transform. Default: 0.5.

Examples

>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>>
>>> transform = A.FilmGrain(intensity_range=(0.1, 0.3), grain_size_range=(1, 3), p=1.0)
>>> result = transform(image=image)["image"]

Notes

- Grain is generated at lower resolution and upscaled → spatial correlation (clumping) like real film. - Visibility modulated by inverse luminance; darker regions show more grain (silver halide-like behavior).

GaussNoiseclass

GaussNoise(
    std_range: tuple[float, float] = (0.2, 0.44),
    mean_range: tuple[float, float] = (0.0, 0.0),
    per_channel: bool = False,
    noise_scale_factor: float = 1,
    p: float = 0.5
)

Add Gaussian (normal) noise to the image. i.i.d. per pixel (or per block if scaled). Use for robustness to sensor or transmission noise. Noise standard deviation and mean are sampled from configurable ranges and scaled to image dtype (255 for uint8, 1.0 for float32). Optional per-channel sampling and lower-resolution noise for speed.

Parameters

NameTypeDefaultDescription
std_rangetuple[float, float](0.2, 0.44)Range for noise standard deviation as a fraction of the max value (255 for uint8, 1.0 for float32). In [0, 1]. Default: (0.2, 0.44).
mean_rangetuple[float, float](0.0, 0.0)Range for noise mean as a fraction of max. In [-1, 1]. Default: (0.0, 0.0).
per_channelboolFalseIf True, sample noise per channel; else same noise for all. Default: False.
noise_scale_factorfloat1If < 1, noise is generated at lower resolution and resized (faster, coarser). 1 = per-pixel. In (0, 1]. Default: 1.0.
pfloat0.5Probability of applying the transform. Default: 0.5.

Examples

>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>>
>>> transform = A.GaussNoise(std_range=(0.1, 0.2), p=1.0)
>>> noisy_image = transform(image=image)["image"]

Notes

- std_range and mean_range are in [0, 1] / [-1, 1]; scaled by 255 (uint8) or used directly (float32). - per_channel=False: faster, same noise on all channels (grayscale-like on RGB). - per_channel=True: different noise per channel (colored noise). - noise_scale_factor < 1 trades speed for noise granularity.

ISONoiseclass

ISONoise(
    color_shift: tuple[float, float] = (0.01, 0.05),
    intensity: tuple[float, float] = (0.1, 0.5),
    p: float = 0.5
)

Add camera-sensor-like noise scaling with intensity (high ISO). color_shift and intensity range control strength. Good for low-light or camera noise simulation. This transform adds random noise to an image, mimicking the effect of using high ISO settings in digital photography. It simulates two main components of ISO noise: 1. Color noise: random shifts in color hue 2. Luminance noise: random variations in pixel intensity

Parameters

NameTypeDefaultDescription
color_shifttuple[float, float](0.01, 0.05)Range for changing color hue. Values should be in the range [0, 1], where 1 represents a full 360° hue rotation. Default: (0.01, 0.05)
intensitytuple[float, float](0.1, 0.5)Range for the noise intensity. Higher values increase the strength of both color and luminance noise. Default: (0.1, 0.5)
pfloat0.5Probability of applying the transform. Default: 0.5

Examples

>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> transform = A.ISONoise(color_shift=(0.01, 0.05), intensity=(0.1, 0.5), p=0.5)
>>> result = transform(image=image)
>>> noisy_image = result["image"]

Notes

- This transform only works with RGB images. It will raise a TypeError if applied to non-RGB images. - The color shift is applied in the HSV color space, affecting the hue channel. - Luminance noise is added to all channels independently. - This transform can be useful for data augmentation in low-light scenarios or when training models to be robust against noisy inputs.

References

  • [{'description': 'ISO noise in digital photography', 'source': 'https://en.wikipedia.org/wiki/Image_noise#In_digital_cameras'}]

MultiplicativeNoiseclass

MultiplicativeNoise(
    multiplier: tuple[float, float] = (0.9, 1.1),
    per_channel: bool = False,
    elementwise: bool = False,
    p: float = 0.5
)

Multiply image by random per-pixel or per-channel factor. multiplier_range controls strength. Simulates illumination or gain variation; preserves zeros. This transform multiplies each pixel in the image by a random value or array of values, effectively creating a noise pattern that scales with the image intensity.

Parameters

NameTypeDefaultDescription
multipliertuple[float, float](0.9, 1.1)The range for the random multiplier. Defines the range from which the multiplier is sampled. Default: (0.9, 1.1)
per_channelboolFalseIf True, use a different random multiplier for each channel. If False, use the same multiplier for all channels. Setting this to False is slightly faster. Default: False
elementwiseboolFalseIf True, generates a unique multiplier for each pixel. If False, generates a single multiplier (or one per channel if per_channel=True). Default: False
pfloat0.5Probability of applying the transform. Default: 0.5

Examples

>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> transform = A.MultiplicativeNoise(multiplier=(0.9, 1.1), per_channel=True, p=1.0)
>>> result = transform(image=image)
>>> noisy_image = result["image"]

Notes

- When elementwise=False and per_channel=False, a single multiplier is applied to the entire image. - When elementwise=False and per_channel=True, each channel gets a different multiplier. - When elementwise=True and per_channel=False, each pixel gets the same multiplier across all channels. - When elementwise=True and per_channel=True, each pixel in each channel gets a unique multiplier. - Setting per_channel=False is slightly faster, especially for larger images. - This transform can be used to simulate various lighting conditions or to create noise that scales with image intensity.

References

  • [{'description': 'Multiplicative noise', 'source': 'https://en.wikipedia.org/wiki/Multiplicative_noise'}]

SaltAndPepperclass

SaltAndPepper(
    amount: tuple[float, float] = (0.01, 0.06),
    salt_vs_pepper: tuple[float, float] = (0.4, 0.6),
    p: float = 0.5
)

Apply salt-and-pepper (impulse) noise: randomly set pixels to min or max. amount and salt_vs_pepper control density and ratio. Same mask for all channels. Salt and pepper noise is a form of impulse noise that randomly sets pixels to either maximum value (salt) or minimum value (pepper). The amount and proportion of salt vs pepper can be controlled. The same noise mask is applied to all channels of the image to preserve color consistency.

Parameters

NameTypeDefaultDescription
amounttuple[float, float](0.01, 0.06)Range for total amount of noise (both salt and pepper). Values between 0 and 1. For example: - 0.05 means 5% of all pixels will be replaced with noise - (0.01, 0.06) will sample amount uniformly from 1% to 6% Default: (0.01, 0.06)
salt_vs_peppertuple[float, float](0.4, 0.6)Range for ratio of salt (white) vs pepper (black) noise. Values between 0 and 1. For example: - 0.5 means equal amounts of salt and pepper - 0.7 means 70% of noisy pixels will be salt, 30% pepper - (0.4, 0.6) will sample ratio uniformly from 40% to 60% Default: (0.4, 0.6)
pfloat0.5Probability of applying the transform. Default: 0.5.

Examples

>>> import albumentations as A
>>> import numpy as np

# Apply salt and pepper noise with default parameters
>>> transform = A.SaltAndPepper(p=1.0)
>>> noisy_image = transform(image=image)["image"]

# Heavy noise with more salt than pepper
>>> transform = A.SaltAndPepper(
...     amount=(0.1, 0.2),       # 10-20% of pixels will be noisy
...     salt_vs_pepper=(0.7, 0.9),  # 70-90% of noise will be salt
...     p=1.0
... )
>>> noisy_image = transform(image=image)["image"]

Notes

- Salt noise sets pixels to maximum value (255 for uint8, 1.0 for float32) - Pepper noise sets pixels to 0 - The noise mask is generated once and applied to all channels to maintain color consistency (i.e., if a pixel is set to salt, all its color channels will be set to maximum value) - The exact number of affected pixels matches the specified amount as masks are generated without overlap

References

  • [{'description': 'Digital Image Processing', 'source': 'Rafael C. Gonzalez and Richard E. Woods, 4th Edition, Chapter 5: Image Restoration and Reconstruction.'}, {'description': 'Fundamentals of Digital Image Processing', 'source': 'A. K. Jain, Chapter 7: Image Degradation and Restoration.'}, {'description': 'Salt and pepper noise', 'source': 'https://en.wikipedia.org/wiki/Salt-and-pepper_noise'}]

ShotNoiseclass

ShotNoise(
    scale_range: tuple[float, float] = (0.1, 0.3),
    p: float = 0.5
)

Shot noise (Poisson) in linear light space. Sensor-realistic; use for low-light or photon-limited imaging and camera simulation. Simulates photon-counting: convert to linear space (gamma removed), treat pixel values as expected photon counts, sample from Poisson, convert back. Variance equals mean in linear space; brighter regions have more absolute noise, less relative.

Parameters

NameTypeDefaultDescription
scale_rangetuple[float, float](0.1, 0.3)Reciprocal of photons per unit intensity. Higher = more noise. e.g. 0.1 ≈ low, 1.0 ≈ moderate, 10.0 ≈ high. Default: (0.1, 0.3).
pfloat0.5Probability of applying the transform. Default: 0.5.

Examples

>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>>
>>> transform = A.ShotNoise(scale_range=(0.1, 1.0), p=1.0)
>>> noisy_image = transform(image=image)["image"]

Notes

- Pipeline: linear space (gamma = 2.2), Poisson sample, back to display space. - Preserves mean intensity. Per-pixel, per-channel independent.

References

  • [{'description': 'Shot noise', 'source': 'https://en.wikipedia.org/wiki/Shot_noise'}, {'description': 'Original paper', 'source': 'https://doi.org/10.1002/andp.19183622304 (Schottky, 1918)'}, {'description': 'Poisson process', 'source': 'https://en.wikipedia.org/wiki/Poisson_point_process'}, {'description': 'Gamma correction', 'source': 'https://en.wikipedia.org/wiki/Gamma_correction'}]