SaltPepperNoise#

class deepinv.physics.SaltPepperNoise(p=0.025, s=0.025, rng=None)[source]#

Bases: NoiseModel

SaltPepper noise \(y = \begin{cases} 0 & \text{if } z < p\\ x & \text{if } z \in [p, 1-s]\\ 1 & \text{if } z > 1 - s\end{cases}\) with \(z\sim\mathcal{U}(0,1)\)

This noise model is also known as impulse noise, is a form of noise sometimes seen on digital images. For black-and-white or grayscale images, it presents as sparsely occurring white and black pixels, giving the appearance of an image sprinkled with salt and pepper.

The parameters s and p control the amount of salt (pixel to 1) and pepper (pixel to 0) noise.


Examples:

Adding LogPoisson noise to a physics operator by setting the noise_model attribute of the physics operator:

>>> from deepinv.physics import Denoising, SaltPepperNoise
>>> import torch
>>> physics = Denoising()
>>> physics.noise_model = SaltPepperNoise()
>>> x = torch.rand(1, 1, 2, 2)
>>> y = physics(x)
Parameters:
  • s (float) – amount of salt noise.

  • p (float) – amount of pepper noise.

  • rng (torch.Generator) – (optional) a pseudorandom random number generator for the parameter generation.

forward(x, p=None, s=None, seed=None, **kwargs)[source]#

Adds the noise to measurements x

Parameters:
  • x (torch.Tensor) – measurements

  • s (None, float, torch.Tensor) – amount of salt noise. If not None, it will overwrite the current salt noise.

  • p (None, float, torch.Tensor) – amount of pepper noise. If not None, it will overwrite the current pepper noise.

  • seed (int) – the seed for the random number generator, if rng is provided.

Returns:

noisy measurements

update_parameters(s=None, p=None, **kwargs)[source]#

Updates the number of photons and normalization constant.

Parameters: