MATLAB中图形轮廓提取的C均值聚类算法FCM出错,用其他图片就可以出结果,换成医学图片就不行了
function[IX2]=fcm(IM);IM=imread('001.jpg');IM=IM(:,:,1);figure(1)imshow(uint8(IM))[ma...
function [IX2]=fcm(IM);
IM=imread('001.jpg');
IM=IM(:,:,1);
figure(1)
imshow(uint8(IM))
[maxX,maxY]=size(IM);
IM=double(IM);
IMM=cat(4,IM,IM,IM,IM);
cc1=7;
cc2=70;
cc3=180;
cc4=240;
ttFcm=0;
while(ttFcm<15)
ttFcm=ttFcm+1;
c1=repmat(cc1,maxX,maxY);
c2=repmat(cc2,maxX,maxY);
c3=repmat(cc3,maxX,maxY);
c4=repmat(cc4,maxX,maxY);
c=cat(4,c1,c2,c3,c4);
ree=repmat(0.000001,maxX,maxY);
ree1=cat(4,ree,ree,ree,ree);
distance=IMM-c;
distance=distance.*distance+ree1;
daoshu=1./distance;
daoshu2=daoshu(:,:,1)+daoshu(:,:,2)+daoshu(:,:,3)+daoshu(:,:,4);
distance1=distance(:,:,1).*daoshu2;
u1=1./distance1;
distance2=distance(:,:,2).*daoshu2;
u2=1./distance2;
distance3=distance(:,:,3).*daoshu2;
u3=1./distance3;
distance4=distance(:,:,4).*daoshu2;
u4=1./distance4;
ccc1=sum(sum(u1.*u1.*IM))/sum(sum(u1.*u1));
ccc2=sum(sum(u2.*u2.*IM))/sum(sum(u2.*u2));
ccc3=sum(sum(u3.*u3.*IM))/sum(sum(u3.*u3));
ccc4=sum(sum(u4.*u4.*IM))/sum(sum(u4.*u4));
tmpMatrix=[abs(cc1-ccc1)/cc1,abs(cc2-ccc2)/cc2,abs(cc3-ccc3)/cc3,abs(cc4-ccc4)/cc4];
pp=cat(3,u1,u2,u3,u4);
for i=1:maxX
for j=1:maxY
if max(pp(i,j,:))==u1(i,j)
IX(i,j)=1;
elseif max(pp(i,j,:))==u2(i,j)
IX2(i,j)=2;
elseif max(pp(i,j,:))==u3(i,j)
IX2(i,j)=3;
else
IX2(i,j)=4;
end
end
end
if max(tmpMatrix)<0.0001
break;
else
cc1=ccc1;
cc2=ccc2;
cc3=ccc3;
cc4=ccc4;
end
for i=1:maxX
for j=1:maxY
if IX2(i,j)==1;
IMMM(i,j)=240;
elseif IX2(i,j)==3
IMMM(i,j)=180;
elseif IX2(i,j)==2
IMMM(i,j)=70;
else
IMMM(i,j)=7;
end
end
end
figure(2);
imshow(uint8(IMMM));
end
for i=1:maxX
for j=1:maxY
if IX2(i,j)==4
IMMM(i,j)=240;
elseif IX2(i,j)==3
IMMM(i,j)=180;
elseif IX2(i,j)==2
IMMM(i,j)=70;
else
IMMM(i,j)=7;
end
end
end
IMMM=uint8(IMMM);
figure(3);
imshow(IMMM);
end 展开
IM=imread('001.jpg');
IM=IM(:,:,1);
figure(1)
imshow(uint8(IM))
[maxX,maxY]=size(IM);
IM=double(IM);
IMM=cat(4,IM,IM,IM,IM);
cc1=7;
cc2=70;
cc3=180;
cc4=240;
ttFcm=0;
while(ttFcm<15)
ttFcm=ttFcm+1;
c1=repmat(cc1,maxX,maxY);
c2=repmat(cc2,maxX,maxY);
c3=repmat(cc3,maxX,maxY);
c4=repmat(cc4,maxX,maxY);
c=cat(4,c1,c2,c3,c4);
ree=repmat(0.000001,maxX,maxY);
ree1=cat(4,ree,ree,ree,ree);
distance=IMM-c;
distance=distance.*distance+ree1;
daoshu=1./distance;
daoshu2=daoshu(:,:,1)+daoshu(:,:,2)+daoshu(:,:,3)+daoshu(:,:,4);
distance1=distance(:,:,1).*daoshu2;
u1=1./distance1;
distance2=distance(:,:,2).*daoshu2;
u2=1./distance2;
distance3=distance(:,:,3).*daoshu2;
u3=1./distance3;
distance4=distance(:,:,4).*daoshu2;
u4=1./distance4;
ccc1=sum(sum(u1.*u1.*IM))/sum(sum(u1.*u1));
ccc2=sum(sum(u2.*u2.*IM))/sum(sum(u2.*u2));
ccc3=sum(sum(u3.*u3.*IM))/sum(sum(u3.*u3));
ccc4=sum(sum(u4.*u4.*IM))/sum(sum(u4.*u4));
tmpMatrix=[abs(cc1-ccc1)/cc1,abs(cc2-ccc2)/cc2,abs(cc3-ccc3)/cc3,abs(cc4-ccc4)/cc4];
pp=cat(3,u1,u2,u3,u4);
for i=1:maxX
for j=1:maxY
if max(pp(i,j,:))==u1(i,j)
IX(i,j)=1;
elseif max(pp(i,j,:))==u2(i,j)
IX2(i,j)=2;
elseif max(pp(i,j,:))==u3(i,j)
IX2(i,j)=3;
else
IX2(i,j)=4;
end
end
end
if max(tmpMatrix)<0.0001
break;
else
cc1=ccc1;
cc2=ccc2;
cc3=ccc3;
cc4=ccc4;
end
for i=1:maxX
for j=1:maxY
if IX2(i,j)==1;
IMMM(i,j)=240;
elseif IX2(i,j)==3
IMMM(i,j)=180;
elseif IX2(i,j)==2
IMMM(i,j)=70;
else
IMMM(i,j)=7;
end
end
end
figure(2);
imshow(uint8(IMMM));
end
for i=1:maxX
for j=1:maxY
if IX2(i,j)==4
IMMM(i,j)=240;
elseif IX2(i,j)==3
IMMM(i,j)=180;
elseif IX2(i,j)==2
IMMM(i,j)=70;
else
IMMM(i,j)=7;
end
end
end
IMMM=uint8(IMMM);
figure(3);
imshow(IMMM);
end 展开
1个回答
光点科技
2023-08-15 广告
2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件...
点击进入详情页
本回答由光点科技提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询