www.pudn.com > PCNN.rar > pcnn.asv, change:2011-05-17,size:2183b


function[Edge,Numberofaera]=pcnn(X)  
%X:输入的灰度图像。Edge:检测到的一些边界点.Numberofaear:在各次迭代时激活的块区域.  
X=double(imread('lena.jpg'));  
Weight=[0.5 1 0.5;1 0 1;0.5 1 0.5];  
Beta=0.4;  
Yuzhi=2;  
Decay=0.3;  
[a,b]=size(X);  
Threshold=zeros(a,b);  
S=zeros(a+2,b+2);  
B=zeros(a,b);%标记样板,表明该pixel是否被激活过.  
Y=zeros(a,b);  
Edge=zeros(a,b);  
Numberofaera=zeros(a,b);  
Numberofaera_1=zeros(a,b);  
Num_1=0;  
Num=0;  
n=1;  
while(sum(sum(B))~=256*256)%若采用128*128的图像,须注意  
    for i0=2:a+1  
        for i1=2:b+1  
            V=[S(i0-1,i1-1) S(i0-1,i1) S(i0-1,i1+1);  
                S(i0,i1-1) S(i0,i1) S(i0,i1+1);  
                S(i0+1,i1-1) S(i0+1,i1) S(i0+1,i1+1)];  
            L=sum(sum(V.*Weight));  
            F=X(i0-1,i1-1);  
            U=double(F)*(1+Beta*double(L));  
            if U>=Threshold(i0-1,i1-1)|Threshold(i0-1,i1-1)<60  
                T(i0-1,i1-1)=1;  
                Threshold(i0-1,i1-1)=Yuzhi;  
                Y(i0-1,i1-1)=1;  
                if n==1  
                    B(i0-1,i1-1)=0;%避免第一次全部激发造成的影响   
                else  
                    B(i0-1,i1-1)=1;%已发射过的标记  
                    Threshold(i0-1,i1-1)=10000000;%相当于不会第二次激活   
                end  
            else  
                T(i0-1,i1-1)=0;  %no use?      
                Y(i0-1,i1-1)=0;  
            end  
        end  
    end  
    Threshold(find(B~=1))=exp(- Decay)*Threshold(find(B~=1));  
    %被激活过的像素不再参与迭代过程  
    if n~=1  
        Edge=Edge+judge_edge(Y,n);  
        Y(find(Edge<0))=0;%边界点被置0,Y本来是激发的像素,现在边界被置0,也不能说白激发了,B矩阵有记录!当然下次就休想再被激发了   
        [Numberofaera_1,Num_1]=bwlabel(Y,4);  
        for i=1:a  
            for j=1:b  
                if Numberofaera_1(i,j)~=0  
                    Numberofaera_1(i,j)=Numberofaera_1(i,j)+Num;  
                end  
            end  
        end  
        Numberofaera=Numberofaera+Numberofaera_1;  
        Num=Num_1;  
    end  
    if n==1  
        S=zeros(a+2,b+2);  
    else  
        S=Bianhuan(T);  
    end  
    n=n+1;  
    Numberofaera_1=zeros(a,b);  
end