Mean Filter

  • It is also called as Box Averaging filtering technique. 
  • It uses a kernel and is based on convolution.
  • It calculates the average of all a pixel and its surrounding pixels and the result is assigned to the central pixel.
  • It is a very effective technique for the removal of Poisson noise.

Syntax:

 k=rgb2gray(k); // To convert into grayscale: 

 gaussian_noise = imnoise(k, ‘gaussian’, 0, 0.01);

// To create the image corrupted with gaussian noise:

denoised=conv2(noisy_image, mean_filter, ‘same’); 

// To perform the convolution between gaussian_noisy image and mean filter:

To display the image: imtool( image_variable, [ ]);

To create the image corrupted with poisson noise: poisson_noise = imnoise(k, ‘poisson’);

 salt_noise = imnoise(k, ‘salt & pepper’, 0.05);

// To create the image corrupted with salt and pepper noise:

 speckle_noise = imnoise(k, ‘speckle’, 0.05);

// To corrupt the image with speckle noise:

Example:

Matlab




% MATLAB code for Mean filter 
% read the image.
k=imread("einstein_colored.png");
  
% convert into grayscale.
k=rgb2gray(k);
  
% create image corrupted with gaussian noise.
gaussian_noise=imnoise(k,'gaussian',0,0.01);
  
% denoise the image with gaussian noise
gaussian_denoised=conv2(gaussian_noise,h,'same');
  
% display the org image.
imtool(k,[]);
  
% display the noised and denoised image.
imtool(gaussian_noise,[]);
imtool(gaussian_denoised,[]);
  
% create image corrupted with poisson noise.
poisson_noise=imnoise(k,'poisson');
  
% denoise the image with poisson noise
poisson_denoised=conv2(poisson_noise,h,'same');
  
% display the org image.
imtool(k,[]);
  
% display the noised and denoised image.
imtool(poisson_noise,[]);
imtool(poisson_denoised,[]);
  
% create image corrupted with salt & pepper noise.
salt_noise=imnoise(k,'salt & pepper', 0.05);
  
% denoise the image with salt & pepper noise
salt_denoised=conv2(salt_noise,h,'same');
  
% display the org image.
imtool(k,[]);
  
% display the noised and denoised image.
imtool(salt_noise,[]);
imtool(salt_denoised,[]);
  
% create image corrupted with speckle noise.
speckle_noise=imnoise(k,'speckle', 0.05);
  
% denoise the image with speckle noise
speckle_denoised=conv2(speckle_noise,h,'same');
  
%display the org image.
imtool(k,[]);
  
% display the noised and denoised image.
imtool(speckle_noise,[]);
imtool(speckle_denoised,[]);


Output:

Figure: Gaussian noise

 

Figure: Poisson noise

 

 Figure: Salt and pepper noise

Figure: Speckle noise

Mean filter does not remove any particular noise effectively. 

Code Explanation: 

  • k=imread(“einstein_colored); This line reads the image.
  • k=rgb2gray(k); this line converts into grayscale.
  • gaussian_noise = imnoise(k, ‘gaussian’, 0, 0.01); this line creates the image corrupted with gaussian noise.
  • gaussian_denoised=conv2(gaussian_noise, h, ‘same’); this line performs the convolution between gaussian_noisy image and mean filter.
  • poisson_noise = imnoise(k, ‘poisson’); this line creates the image corrupted with poisson noise.
  • poisson_denoised=conv2(poisson_noise, h, ‘same’); this line performs the convolution between poisson_noise image and mean filter.
  • salt_noise = imnoise(k, ‘salt & pepper’, 0.05); this line creates the image corrupted with salt and pepper noise with 5 % of total pixels.
  • salt_denoised=conv2(salt_noise, h, ‘same’); this line performs the convolution between salt_noise image and mean filter.
  • speckle_noise = imnoise(k, ‘speckle’, 0.05); this line corrupts the image with speckle noise of 0.05 variance.
  • speckle_denoised=conv2(speckle_noise, h, ‘same’); this line performs the convolution between speckle_noise image and mean filter.
  • imtool(k, []); this line displays the original image.
  • imtool(noised_image, []); this line displays the noisy_image.
  • imtool(denoised_image, []); this line displays the denoised image.

What are different types of denoising filters in MATLAB?

Digital images are prone to various types of noise that make the quality of the images worst. Image noise is a random variation of brightness or color information in the captured image. Noise is basically the degradation in image signal caused by external sources such as cameras. Images containing multiplicative noise have the characteristic that the brighter the area the noisier it. We shall discuss various denoising filters in order to remove these noises from the digital images. 

Types of filters discussed in this article are listed as:

  • Mean filter
  • Median filter
  • Gaussian filter  
  • Wiener filter

Similar Reads

Mean Filter

It is also called as Box Averaging filtering technique.  It uses a kernel and is based on convolution. It calculates the average of all a pixel and its surrounding pixels and the result is assigned to the central pixel. It is a very effective technique for the removal of Poisson noise....

Median Filter

...

Gaussian Filter

A Median filter is a non-linear filter. It sorts the pixels covered by the window and sorts them in ascending order then returns the median of them....

Wiener Filter

...