Thursday, March 12, 2009

Alpha trimed mean filter

% read a gray scale image and remove the salt & pepper noise using alpha
% trimed mean filter. prove that for D=0 it becomes arithmetic mean filter
% and for d=(mn-1)/2 it becomes median filter. show that this filter
% removes combination of gaussian and salt & pepper noise.
clear all; close all; clc;
f = imread('cameraman.tif');
f = im2double(f);
f = imnoise(f,'salt & pepper',0.1);
f = imnoise(f,'gaussian',0,0.01);
[m n]=size(f);
f1=zeros(m,n);
D = 4;
d = D/2;
for i=3:m-2
for j=3:n-2
con=0;
for k=i-2:i+2
for p=j-2:j+2
con=con+1;
s(con)=f(k,p);
end
end
s = sort(s);
r = (size(s,2)-d);
s1= s(d+1:r);
f1(i,j)= sum(s1)/(con-D);
end
end
figure,imshow(f);
figure,imshow(f1);

No comments: