Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 人工智能 > 计算机视觉/图像处理
计算机视觉/图像处理 A discussion board for Computer Vision & Digital image processing.
回复
 
主题工具 显示模式
旧 2011-04-27, 23:32   #1
gysc
初级会员
 
注册日期: 2011-04-27
年龄: 37
帖子: 1
声望力: 0
gysc 正向着好的方向发展
默认 关于PCNN图像分割程序求教

程序有错误,第一次做,希望高手帮指导一下


% 名称:基于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(=255;
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('输出二值分割图像')
gysc 当前离线   回复时引用此帖
回复

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码



所有时间均为北京时间。现在的时间是 23:33


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.