Monday, March 1, 2021

Mean filter/ average filter (Filtre Moyenneur) - salt and pepper noise- implementation using python

Mean filter/ average filter  (Filtre Moyenneur) - salt and pepper noise- implementation using python

This filter reduces image noise and improves image smoothness. However, this allows for the fine details to not be visible or not very clear. Image noise can arise for a variety of causes, including physical factors such as camera temperature and brightness, and digital factors. There are many different kinds of image noise. Salt and pepper noise is one of the most well-known noises.

How to calculate the new pixel values?

The averaging filter is a type of image processing. It is calculated using a weighted average of the pixels around each pixel. The new pixel is calculated from the old pixel and its neighbors, as illustrated in the figure below. For each pixel, this process will be repeated.

54 = (12+18+37+64+57+98+54+64+82)/9

How to calculate the new pixel values? convolution process

Implementation Using Python 

In this section, we give an easy demonstration using Python. 



Steps

  • The first step is to import the libraries to use;

from PIL import Image from PIL import ImageFilter 

  • The next step is to import the images;

img1=Image.open("lena_original.png") img2=Image.open("lena_poivre_et_sel.png")
img1.show()
img2.show()

  • The last step is to apply the mean filter on the images using different threshold.

img2.filter(ImageFilter.BoxBlur(1)).show() img2.filter(ImageFilter.BoxBlur(3)).show() img2.filter(ImageFilter.BoxBlur(7)).show()


As a result, we can see that the Mean filter was successful in decreasing the salt and pepper noise, although the picture remained a bit unclear in comparison to the original image.
Previous Post
Next Post

0 Comments: