Salt & pepper noise is a noise type in which the noise pixels are either black or white. This type of noise non-Gaussian i.e. the probability distribution of the noise is not normal. As we’ll see later, this has an effect on the type of filter we can use to get rid of it.
Where does salt & pepper noise show up in real life? Examples of it can be seen in video and images from deteriorated image sensors. In the video linked below you can see examples of it:
As Tim Peake shows us the effect of low-gravity on dizziness you can see a few examples of white pixels. This is due to radiation damage to the CCD recording the image. Admittedly, this noise is more of the salt variety but it is an interesting real-world example nonetheless.
So how do we get rid of salt & pepper noise? Salt & pepper noise is non-Gaussian and as mentioned before this affects the way that we filter it. Gaussian noise has a zero average (or is zero-mean). What this means is that when we apply averaging filters to removing it we can come close to averaging away the effect of the noise to zero.
Salt & pepper noise does not have this zero-mean property. When an averaging filter is applied to an image containing salt & pepper noise the effect of the noise largely remains in the image albeit with lower intensity and blurred with the rest of the image.
In order to effectively remove salt & pepper noise we need to use a median filter. A median filter works by evaluating a region of pixels around a pixel of interest. The median value of the region of pixels is calculated (the value of the pixel of interest is included). The value of the pixel of interest is then replaced with the calculated median which will be the value of a pixel in the region being filtered. This filter operates on the assumption that values of neighbouring pixels are not likely to differ dramatically. The operation of a median filter is illustrated in the diagram below:
The value produce by the median filter effectively cancels out the effect of the salt & pepper noise while the averaging filter cannot average the non-gaussian noise’s effect to zero. Examples of the operations discussed above when applied to an actual image can be found below:
The median filter is, as expected, very effective at removing this particular type of noise. In the next post we will dig into the code that generated the images above.
2 thoughts on “Salt & Pepper Noise and Median Filters, Part I – The Theory”
Interesting filter! Is this operation applied to all image pixels, or can you use the fact that the noise is all white or all black to selectively identify pixels of noise to apply the filter?
This operation works across the entire image and the side effect of that is that the image is blurred. Interesting idea on being selective! I suppose you could look for white or black pixels that are markedly different from surrounding pixels (to avoid swathes of black or white) and then apply the median filter only at that location.