Apply salt-and-pepper (impulse) noise: randomly set pixels to min or max with
density and ratio controlled by amount_range and salt_vs_pepper_range.
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.
amount_rangeRange for total amount of noise (both salt and pepper). Values between 0 and 1. For example:
salt_vs_pepper_rangeRange for ratio of salt (white) vs pepper (black) noise. Values between 0 and 1. For example:
pProbability of applying the transform. Default: 0.5.
>>> 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_range=(0.1, 0.2), # 10-20% of pixels will be noisy
... salt_vs_pepper_range=(0.7, 0.9), # 70-90% of noise will be salt
... p=1.0
... )
>>> noisy_image = transform(image=image)["image"]