极值中值滤波编码
function =jzzz(array);%文件名为jzzz的极值中值滤波程序array=imread('flowers.tif');
array=imnoise(array,’gaussian’,0,0.005)
=size(array);
hb(1:256)=0;
for x=1:X
for y=1:Y
g=double(array(x,y))+1;
hb(g)=hb(g)+1;
end
end %对矩阵中间元素进行处理
for x=2:(X-1)
for y=2:(Y-1)
%定义一个数组存放3*3数值
a(1:9)=0;
i=1;
for m=(x-1):(x+1)
for n=(y-1):(y+1)
a(i)=double(array(m,n));
i=i+1;
end
end
s=a; %对数组a进行按从大到小排列
for i=1:8
for j=1:9-i
if s(j)>s(j+1)
t=s(j);
s(j)=s(j+1);
s(j+1)=t;
end
end
end
if a(5)==s(9)|a(5)==s(1)
outimage(x,y)=uint8(s(5));
else outimage(x,y)=uint8(a(5));
end
end
end
=size(outimage);
he(1:256)=0;
for x=1:X1
for y=1:Y1
g=double(outimage(x,y))+1;
he(g)=he(g)+1;
end
end
figure,imshow(array);title;
figure,imshow(outimage);title;
页:
[1]