Skip to main content

Noise

Module: deeprai.tools.noise

This module provides a set of classes for introducing different types of noise into numpy arrays, typically used for image data augmentation or robustness testing.


1. GaussianNoise Class

Description:

The GaussianNoise class applies Gaussian noise to a list of numpy arrays (images).

Attributes:

  • mean (float, default=0): Mean of the Gaussian distribution.

  • std (float, default=1): Standard deviation of the Gaussian distribution.

Methods:

  • compute(): Internal method to get a function that introduces Gaussian noise to an image.

  • noise(arrays): Applies Gaussian noise to a list of numpy arrays. Uses multi-threading for efficiency.

Usage:

from deeprai.tools.noise import GaussianNoise

gaussian_noise = GaussianNoise(mean=0, std=25)
noisy_images = gaussian_noise.noise(list_of_images)

2. SaltPepperNoise Class

Description:

The SaltPepperNoise class introduces salt and pepper noise to a list of numpy arrays.

Attributes:

  • s_vs_p (float, default=0.5): Proportion of salt vs. pepper noise.

  • amount (float, default=0.04): Overall amount of noise to introduce.

Methods:

  • compute(): Internal method to get a function that introduces salt and pepper noise to an image.

  • noise(arrays): Applies salt and pepper noise to a list of numpy arrays. Uses multi-threading for efficiency.

Usage:

from deeprai.tools.noise import SaltPepperNoise

sp_noise = SaltPepperNoise(s_vs_p=0.5, amount=0.04)
noisy_images = sp_noise.noise(list_of_images)

3. SpeckleNoise Class

Description:

The SpeckleNoise class introduces speckle noise to a list of numpy arrays.

Methods:

  • compute(): Internal method to get a function that introduces speckle noise to an image.

  • noise(arrays): Applies speckle noise to a list of numpy arrays. Uses multi-threading for efficiency.

Usage:

from deeprai.tools.noise import SpeckleNoise

speckle_noise = SpeckleNoise()
noisy_images = speckle_noise.noise(list_of_images)

General Note:

For all the above classes, the noise method is designed for efficient computation by applying noise to multiple images using multi-threading. Each image in the input list is processed in a separate thread.

The results are then compiled and returned as a list of numpy arrays.