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

조회 수: 64 (최근 30일)
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');

채택된 답변

Subhadeep Koley
Subhadeep Koley 2020년 5월 25일
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');
  댓글 수: 2
ABTJ
ABTJ 2020년 5월 26일
Ok, but is your conclusion after using above code. Which filter has best performance?
Subhadeep Koley
Subhadeep Koley 2020년 5월 26일
편집: Subhadeep Koley 2020년 5월 26일
For Salt & Pepper noise I would say median filter has the best performance.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 5월 25일
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
ABTJ
ABTJ 2020년 5월 26일
You haven't explicitly indicated or concluded
which filter will perform best here?
Image Analyst
Image Analyst 2020년 5월 26일
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?

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by