pysdic.add_salt_and_pepper_noise#

add_salt_and_pepper_noise(image, *, fraction, values=(0.0, 255.0), seed=None)[source]#

Add a salt and pepper noise to an image (dead and hot pixels of a sensor).

Each value of the image (each pixel and channel) is replaced, with the probability fraction, by the low value (pepper) or the high value (salt), with the same probability.

See also

add_gaussian_noise() for the usual order of the simulation of an acquisition.

Parameters:
  • image (ArrayLike) – The image, an array of any shape with finite values.

  • fraction (Real) – The probability \(p \in [0, 1]\) that a value is replaced.

  • values (Tuple[Real, Real], optional (default: (0.0, 255.0))) – The values (pepper, salt), finite. For example (0, 2**b - 1) for an image of \(b\) bits.

  • seed (Optional[Integral], optional (default: None)) – The seed of the random generator (numpy.random.default_rng), non-negative. If None, the noise is different at each call.

Returns:

The noisy image, a float64 array with the shape of image.

Return type:

numpy.ndarray

Raises:

ValueError – If the image has non-finite values or an input has a wrong value.