Apply salt-and-pepper (impulse) noise: randomly set pixels to min or max. amount and salt_vs_pepper control density and ratio. Same mask for all channels.
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.
amountRange for total amount of noise (both salt and pepper). Values between 0 and 1. For example:
salt_vs_pepperRange 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=(0.1, 0.2), # 10-20% of pixels will be noisy
... salt_vs_pepper=(0.7, 0.9), # 70-90% of noise will be salt
... p=1.0
... )
>>> noisy_image = transform(image=image)["image"]