我百度的代码,可是运行就报错,我贴出来大家帮我一下,毕业设计求助!
function [r, zhongxindian]=ff %输出各切片最大内切圆半径及圆心坐标
a=zeros(512,512);
b=zeros(512,512);
for i=1:512
for j=1:512
a(i,j)=i-257; %横坐标的对应
b(i,j)=j-257; %纵坐标的对应
end
end %图像在xyz面上的x轴、y轴坐标
zhongxindian=zeros(100,2);
r=zeros(100,1);
for k=0:99
t=strcat('F:\毕设\材料\RE1\',int2str(k),'.png');
b=imread(t);
b=zhuanhua(b);%将01互换
blunkuo=edge(b,'sobel');%提取轮廓
bgujia=bwmorph(b,'skel',inf);%提取骨架
%寻找内切圆
[x0,y0,v0]=find(blunkuo);
[a0,b0,c0]=find(bgujia);
m=length(a0);
n=length(x0);
juli=zeros(m,n);
cunfang=zeros(m,2);
for i=1:m
for j=1:n
p1=a0(i);q1=b0(i);
p2=x0(j);q2=y0(j);
juli(i,j)=sqrt((a(p1,q1)-a(p2,q2))^2+(b(p1,q1)-b(p2,q2))^2);%骨架上的各个点到轮廓的距离
end
[zx,zxxh]=min(juli(i,:));%骨架上一点到轮廓的最短距离即以骨架上各个点为圆心的内切园的半径
cunfang(i,1)=zx;
cunfang(i,2)=zxxh;
end
[zd,zdxh]=max(cunfang(:,1));%寻找半径中最大的半径和其对应的圆心坐标
g=a0(zdxh);h=b0(zdxh);
zhongxindian(k+1,1)=a(g,h);
zhongxindian(k+1,2)=b(g,h);
r(k+1)=zd;
end
运行结果报错
??? Attempted to access a(513,1); index out of bounds because size(a)=[512,512].
Error in ==> ff at 29
juli(i,j)=sqrt((a(p1,q1)-a(p2,q2))^2+(b(p1,q1)-b(p2,q2))^2);%骨架上的各个点到轮廓的距离
function [r, zhongxindian]=ff %输出各切片最大内切圆半径及圆心坐标
a=zeros(512,512);
b=zeros(512,512);
for i=1:512
for j=1:512
a(i,j)=i-257; %横坐标的对应
b(i,j)=j-257; %纵坐标的对应
end
end %图像在xyz面上的x轴、y轴坐标
zhongxindian=zeros(100,2);
r=zeros(100,1);
for k=0:99
t=strcat('F:\毕设\材料\RE1\',int2str(k),'.png');
b=imread(t);
b=zhuanhua(b);%将01互换
blunkuo=edge(b,'sobel');%提取轮廓
bgujia=bwmorph(b,'skel',inf);%提取骨架
%寻找内切圆
[x0,y0,v0]=find(blunkuo);
[a0,b0,c0]=find(bgujia);
m=length(a0);
n=length(x0);
juli=zeros(m,n);
cunfang=zeros(m,2);
for i=1:m
for j=1:n
p1=a0(i);q1=b0(i);
p2=x0(j);q2=y0(j);
juli(i,j)=sqrt((a(p1,q1)-a(p2,q2))^2+(b(p1,q1)-b(p2,q2))^2);%骨架上的各个点到轮廓的距离
end
[zx,zxxh]=min(juli(i,:));%骨架上一点到轮廓的最短距离即以骨架上各个点为圆心的内切园的半径
cunfang(i,1)=zx;
cunfang(i,2)=zxxh;
end
[zd,zdxh]=max(cunfang(:,1));%寻找半径中最大的半径和其对应的圆心坐标
g=a0(zdxh);h=b0(zdxh);
zhongxindian(k+1,1)=a(g,h);
zhongxindian(k+1,2)=b(g,h);
r(k+1)=zd;
end
运行结果报错
??? Attempted to access a(513,1); index out of bounds because size(a)=[512,512].
Error in ==> ff at 29
juli(i,j)=sqrt((a(p1,q1)-a(p2,q2))^2+(b(p1,q1)-b(p2,q2))^2);%骨架上的各个点到轮廓的距离