% Harmonic mean filter

% Read a gray scale image and add a noise to it and filter it using

% Harmonic mean filter.

clear all; close all; clc;

f = imread('cameraman.tif');

f = imnoise(f,'gaussian',0,0.02);

f = im2double(f);

subplot(1,2,1),imshow(f),title('Original Image');

[m n]=size(f);

si=1;

for i = 1:m

for j = 1:n

con=0; s1=0;

for k1 = i-si:i+si

for p1 = j-si:j+si

if ((k1 > 0 && p1 > 0) && (k1 < m && p1 < n))

con = con+1;

if f(k1,p1)==0

s1 = s1+0;

else

s1=s1+(1/f(k1,p1));

end

end

end

end

b1(i,j)=con/s1;

end

end

subplot(1,2,2),imshow(b1),title('Harmonic mean filtered');

## No comments:

Post a Comment