Salt & Pepper Noise and Median Filters, Part I – The Theory

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:

Values produced for the pixel of interest (center) by average and median filters. The pixel of interest is representative of a white pixel (8-bit image) produced by salt & pepper noise.

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:

Image with salt & pepper noise
Image with Gaussian filter applied to remove salt & pepper noise. Effect of noise still remains.
Image with median filter applied to remove salt & pepper noise. Note the absence of noise!

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”

  1. 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?


    1. 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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: