Adaptive median filter
clc;
clear all;
close all;
a=imread('cameraman.tif');
figure(1),imshow(a),title('origanal image');
b=imnoise(a,'salt & pepper',.02)
figure(2),imshow(b),title('noisy image');
Smax=9;for i=1:254
for j=1:254
n=b(i:i+2,j:j+2)
Zmin=min(n(:));
Zmax=max(n(:));
Zmed=median(n(:));
sx=3;
sy=3; A1=Zmed-Zmin;
A2=Zmed-Zmax;
if (A1>0) && (A2<0)
B1 = Zxy-Zmin; B2 = Zxy-Zmax;
if (B1>0) && (B2<0)
b(i:i+2,j:j+2) = n(i, j);
break;
else
b(i:i+2,j:j+2) = Zmed;
break;
end
else
sx=sx+2;
sy=sy+2;
if (sx > Smax) && (sy > Smax)
b(i:i+2,j:j+2) = n(i, j);
end
end
end
end figure(3),imshow(b),title('denoised image');
i am trying to implement the following algorithm but where the above pro. is wrong i am unable to find ..
please help me…….
Adaptive median filter changes size of Sxy (the size of the neighborhood) during operation.
? Notation
Zmin = minimum gray level value in Sxy
Zmax = maximum gray level value in Sxy
Zmed = median of gray levels in Sxy
Zxy = gray level at coordinates (x, y)
Smax = maximum allowed size of Sxy? Algorithm
Level A: A1 = Zmed - Zmin
A2 = Zmed - Zmax
if A1 > 0 AND A2 < 0, go to level B
else increase the window size
if window size < Smax, repeat level A
else output Zxy
Level B: B1 = Zxy - Zmin
B2 = Zxy - Zmax
if B1 > 0 AND B2 < 0, output Zxy
else output Zmed
NOTE:-
Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.
You need to take the contents of the “if” block and make it a function that takes the center location and the window size as input arguments. Then in the “else” block you need to increase the window size and call the function. Something like
% Determine window size.
if (A1>0) && (A2<0)
windowSize = standardSize; % 3 or whatever
SEE COMPLETE ANSWER CLICK THE LINK