function gm= GeomtricMean (X)
epsilon = 0.001 ;
% x = max (x , epsilon ) ;
x = ( 1- epsilon ) * x + epsilon ;
gm= exp (mean (Log ( X ) ) ) ;
end
function hm = HarmonicMean (X)
epsilon = 0.001 ;
% x = max (x , epsilon ) ;
x = ( 1- epsilon ) * x + epsilon ;
hm= 1./mean (1./X) ;
end
Clc ;
Clear ;
Close all ;
f = imread ( ‘Coins . png ‘ ) ;
f = im2double ( f ) ;
%g = imnoise ( f , ‘ Gaussian ‘ , 0 , 0.01 ) ;
g = imnoise ( f , ‘ salt & pepper ‘ ) ;
fhat1= spatialFilter ( g , ‘median‘ , [5 5] ) ;
fhat2= spatialFilter ( g , ‘ average ‘ , [5 5] ) ;
fhat3= spatialFilter ( g , ‘geomtric‘ , [5 5] ) ;
fhat4= spatialFilter ( g , ‘harmonic‘ , [5 5] ) ;
fhat5= spatialFilter ( g , ‘ charmonic ‘ , [5 5] , 2 ) ;
fhat6= spatialFilter ( g , ‘max ‘ , [5 5] ) ;
fhat7= spatialFilter ( g , ‘min ‘ , [5 5] ) ;
fhat8= spatialFilter ( g , ‘ midpoint ‘ , [5 5] ) ;
fhat9= spatialFilter ( g , ‘ alphatrim ‘ , [5 5] , 0.1 ) ;
figure ;
subplot (3, 4, 1 ) ;
imshow ( f ) ;
title ( ‘ Original Image ‘ ) ;
subplot (3, 4, 2) ;
imshow (g) ;
title ( ‘ Noisy Image ‘ ) ;
subplot (3, 4, 3) ;
imshow ( fhat 1 ) ;
title ( ‘Meadin Filter ‘ ) ;
subplot (3, 4, 4) ;
imshow (fhat 2 ) ;
title ( ‘Average Filter ‘ ) ;
subplot (3, 4, 5) ;
imshow (fhat 3 ) ;
title ( ‘Geometric Mean Filter ‘ ) ;
subplot (3, 4, 6 ) ;
imshow (fhat 4 ) ;
title ( ‘Harmonic Mean Filter ‘ ) ;
subplot (3, 4, 7 ) ;
imshow (fhat 5 ) ;
title ( ‘Contra - Harmonic Filter ‘ ) ;
subplot (3, 4, 8 ) ;
imshow (fhat 6 ) ;
title ( ‘Max Filter ‘ ) ;
subplot (3, 4, 9 ) ;
imshow (fhat 7 ) ;
title ( ‘ Min Filter ‘ ) ;
subplot (3, 4, 10 ) ;
imshow (fhat 8 ) ;
title ( ‘ Mid – point Filter ‘ ) ;
subplot (3, 4, 11 ) ;
imshow (fhat 9 ) ;
title ( ‘ \alpha – trim Filter ‘ ) ;