← Back to all transforms

GaussNoise

Description

Apply Gaussian noise to the input image.

    Args:
        var_limit (tuple[float, float] | float): Variance range for noise. If var_limit is a single float value,
            the range will be (0, var_limit). Default: (10.0, 50.0).
        mean (float): Mean of the noise. Default: 0.
        per_channel (bool): If True, noise will be sampled for each channel independently.
            Otherwise, the noise will be sampled once for all channels. Default: True.
        noise_scale_factor (float): Scaling factor for noise generation. Value should be in the range (0, 1].
            When set to 1, noise is sampled for each pixel independently. If less, noise is sampled for a smaller size
            and resized to fit the shape of the image. Smaller values make the transform faster. Default: 1.0.
        p (float): Probability of applying the transform. Default: 0.5.

    Targets:
        image

    Image types:
        uint8, float32

    Number of channels:
        Any

    Returns:
        numpy.ndarray: Image with applied Gaussian noise.

    Note:
        - The noise is generated in the same range as the input image.
        - For uint8 input images, the noise is generated in the range [0, 255].
        - For float32 input images, the noise is generated in the range [0, 1].
        - The resulting image is clipped to keep its values in the input range.
        - Setting per_channel=False is faster but applies the same noise to all channels.
        - The noise_scale_factor parameter allows for a trade-off between transform speed and noise granularity.

    Examples:
        >>> import numpy as np
        >>> import albumentations as A
        >>> image = np.random.randint(0, 256, (224, 224, 3), dtype=np.uint8)
        >>>
        >>> # Apply Gaussian noise with default parameters
        >>> transform = A.GaussNoise(p=1.0)
        >>> noisy_image = transform(image=image)['image']
        >>>
        >>> # Apply Gaussian noise with custom variance range and mean
        >>> transform = A.GaussNoise(var_limit=(50.0, 100.0), mean=10, p=1.0)
        >>> noisy_image = transform(image=image)['image']
        >>>
        >>> # Apply the same noise to all channels
        >>> transform = A.GaussNoise(per_channel=False, p=1.0)
        >>> noisy_image = transform(image=image)['image']
        >>>
        >>> # Apply noise with reduced granularity for faster processing
        >>> transform = A.GaussNoise(noise_scale_factor=0.5, p=1.0)
        >>> noisy_image = transform(image=image)['image']

    

Parameters

  • var_limit: int | tuple[int, int] | float | tuple[float, float] (default: (10, 50))
  • mean: float (default: 0)
  • per_channel: bool (default: true)
  • noise_scale_factor: float (default: 1)
  • p: float (default: 0.5)

Targets

  • Image

Try it out

Original Image:

Original

Result:

Transform result will appear here