Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
初级会员
注册日期: 2011-04-27
年龄: 37
帖子: 1
声望力: 0 ![]() |
![]()
程序有错误,第一次做,希望高手帮指导一下
% 名称:基于pcnn自动波特征的血细胞图像分割和计数程序 %*************************************** function y=PCNN() %主程序 global alpha beta w h c threshold Y X=double(imread('cameraman.tif')); [w,h]=size(X); figure,imshow(X/255) title('原始噪声图像') %******************************** %求取最小交叉熵 %******************************* H=zeros(1,256); %计算灰度直方图 for i=1:w for j=1:h a=X(i,j); H(a+1)=H(a+1)+1/256; end end D=zeros(1,15); threshold0=255; for n0=1:15; threshold0=exp(-alpha)*threshold0; t=round(threshold0); h1=sum(H(1:t+1)); h2=sum(H(t+2:256)); f1=1:t; g1=sum(sum(f1.*H(2:t+1))); f2=t+1:255; g2=sum(sum(f2.*H(t+2:256))); u1=1/h1*g1; u2=1/h2*g2; D1=sum(sum(f1.*H(2:t+1).*log10(f1/u1)+u1*H(2:t+1).*log10(u1./f1)));%背景交叉 D2=sum(sum(f2.*H(t+2:256).*log10(f2/u2)+u2*H(t+2:256).*log10(u2./f2)));%目标交叉 D(n0)=(D1+D2)/255 %整幅图像交叉 end MIN_D=min(D) for n0=1:15; if D(n0)==MIN_D; n=n0; end end %交叉熵最小时所取最佳迭代次数 %******************* %下面为二值分割 %********************* threshold=zeros(w,h); threshold( ![]() Y=zeros(w+1,h+1); Weight=[0.707 1 0.707;1 0 1;0.707 1 0.707]; while(n>0) for i=2:w for j=2:h F=X(i,j); V=[Y(i-1,j-1) Y(i-1,j) Y(i-1,j+1); Y(i,j-1) Y(i,j) Y(i,j+1); Y(i+1,j-1) Y(i+1,j) Y(i+1,j+1)]; L=sum(sum(V.*Weight)); U=double(F)*(1+beta*L); if U>threshold(i,j) Y(i,j)=1; else Y(i,j)=0; end threshold(i,j)=exp(-alpha)*threshold(i,j); end end n=n-1; end figure,imshow(Y) title('输出二值分割图像') |
![]() |
![]() |