Gaussian filter vs median filter vs wiener filter??Noise tackling performance with image corrupted with salt and pepper noise

70 views (last 30 days)
I am trying to remove noise in an image usig three different filters,but i am bit confused in output performance of each filter. I think gaussian filter has best performance in this case(please guide me if my observation is wrong)
or median filter also has apparently best performance(but one major drawback that its output appear like binary(black and white image) while originally we had grayscale image,not a binary image)
My matlab code is as follow
clc,clear all close all
im=imread('cameraman.tif');
[r c]=size(im);
t1=randi([0 255],r,c); % Random integers of size r,c in the range 0-255
t2=randi([0 255],r,c);
f=im;
for i=1 : r
for j=1: c
if im(i,j) > t1(i,j)
f(i,j)=255;
else
if im(i,j) < t2(i,j)
f(i,j)=0;
end
end
end
end
%Figure 1 showing f(x,y) and the caption
figure(1), imshow(f); title('Noisy Image Created');
% Gaussian Filter of Variance 1
w=fspecial('gaussian',3,1);
wf=imfilter(f,w);
%Figure 2 showing g(x,y) as the result of Gaussian filtering and the caption
figure(2), imshow(wf); title('Result of 3x3 Gaussian Filter');
mf=medfilt2(f);
%Figure 3 showing g(x,y) as the result of Median filtering and the caption
figure(3), imshow(mf); title('Result of Median Filter');
wf = wiener2(f,[3 3]);
%Figure 4 showing g(x,y) as the result of Wiener filtering and the caption
figure(4), imshow(wf); title('Result of 3x3 Wiener Filter');

Accepted Answer

Subhadeep Koley
Subhadeep Koley on 25 May 2020
Hi,
The code (by which you are adding Salt & Pepper noise into the image) is modifying almost all the pixels in the input image to either 0 or 255 (Refer the histogram below).
Therefore, your filtered image is also looking like binary image. Is there any particular reason you're not using the inbuilt imnoise() function? If not then you can you the below code.
clc;
close all;
img = imread('cameraman.tif');
% Add noise using imnoise
f = imnoise(img, 'salt & pepper', 0.1);
%Figure 1 showing f(x,y) and the caption
figure(1), imshow(f); title('Noisy Image Created');
% Gaussian Filter of Variance 1
w = fspecial('gaussian', 3, 1);
wf = imfilter(f, w);
%Figure 2 showing g(x,y) as the result of Gaussian filtering and the caption
figure(2), imshow(wf); title('Result of 3x3 Gaussian Filter');
mf = medfilt2(f);
%Figure 3 showing g(x,y) as the result of Median filtering and the caption
figure(3), imshow(mf); title('Result of Median Filter');
wf = wiener2(f, [3 3]);
%Figure 4 showing g(x,y) as the result of Wiener filtering and the caption
figure(4), imshow(wf); title('Result of 3x3 Wiener Filter');

More Answers (1)

Image Analyst
Image Analyst on 25 May 2020
A guassian filter blurs edges and is affected by the noise value itself.
A median filter preserves edges and is not affected by the noise value.
A wiener filter is a stochastic filter that requires that you know the spectrum of the noise.
There are other even more sophisticated denoising routines, like BM3D, non-local means, etc.
  2 Comments
Image Analyst
Image Analyst on 26 May 2020
I gave generalities, which is much more useful and informative than telling you which is best for this particular amount of noise and this particular image. You can always compute the MSE with immse() to see which performed best with that particular image - that's trivial so why don't you do it?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!