图像滞后阈值算法:
滞后阈值算法可以实现一个迭代或递归,采取Sb(和Sh)约为0.001(resp.0,1)的值。然后,测试一下改变阈值所发生的现象:
算法如下:
Sb=0.001 ;
Sh=0.1 ;
H(1 :n(1),1 :n(2))=zeros(1 :n(1),1 :n(2));
for i=1: (n(1)-1)
for j=1: (n(2)-1)
if(E(i,j)>sb)
H(i,j)=H(i,j)+ E(i,j);
else
H(i,j)=250;
end
if(E(i,j)>sh)
H(i,j)=H(i,j)+ E(i,j);
end
<span lang="EN-US">if(E(i,j)>sb&&E(i,j)figure
subplot 211
I=imread('bateau.gif');
imshow(I);
title('Image original');
% Sobel 滤波
Sx=[-1 0 1;-2 0 2;-1 0 1];
Sy=[-1 -2 -1;0 0 0; 1 2 1];
subplot 223
Hx=filter2(Sx,I);
imshow(Hx);
subplot 224
Hy=filter2(Sy,I) ;
imshow(Hy);
title('image convoluer avec sobel en y');
figure
G=(sqrt(Hx.*Hx+Hy.*Hy));
n=size(G) ;
G(1 : n(1),1)=0 ;
G(1 : n(1),n(2))=0 ;
G(1,1 : n(2))=0 ;
G(n(1) , 1 :n(2))=0 ;
imshow(G,[]);
figure
teta=atan2(Hy,Hx) ;
imshow(teta);
figure
for i=2 : (n(1)-1)
for j=2 : (n(2)-1)
e1=0 ;
e2=0 ;
if(teta(i,j)>1& teta(i,j)-180 & teta(i,j)45& teta(i,j)-135& teta(i,j)90 & teta(i,j)-90& teta(i,j)135& teta(i,j)-45& teta(i,j)e1&&G(i,j)>e2)
E(i,j)= G(i,j);
else
E(i,j)=0;
end
end
end
imshow(E,[]);
Sb=0.001 ;
Sh=0.1 ;
H(1 :n(1),1 :n(2))=zeros(1 :n(1),1 :n(2));
for i=1: (n(1)-1)
for j=1: (n(2)-1)
if(E(i,j)>sb)
H(i,j)=H(i,j)+ E(i,j);
else
H(i,j)=250;
end
if(E(i,j)>sh)
H(i,j)=H(i,j)+ E(i,j);
end
<span lang="FR" style="">if(E(i,j)>sb&&E(i,j) |