Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#2 |
普通会员
注册日期: 2008-08-17
年龄: 36
帖子: 70
声望力: 20 ![]() ![]() |
![]()
不知道这段代码的最终目的是什么?
程序调好了 运行结果中3个孤立点被消除了 但如果只是为了消除孤立点完全没必要写得这么复杂的 代码:
clc clear all bw1=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 255 255 255 255 255 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 255 255 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 255 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 255 0 0 0 0 0 0 0 0 0 0 255 0 0 0 255 255 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; figure,imshow(bw1); title('数据图象'); [m,n]=size(bw1); % EDIT BY PSL 2008 08 20 bianjie_length=0; first_point=zeros(1,2); %起始点 temp1_im=zeros(m,n); %临时存放检测到的点 end_im=zeros(m,n); %最终检测到的点 biaoji=zeros(1,2,2*(m+n)); %用于避免循环的出现 figure; title('temp1_image'); for i=1:m for j=1:n if bw1(i,j)==255 first_point=[i,j]; bianjie_length=bianjie_length+1; biaoji(:,:,bianjie_length)=first_point(:,:); %以i,j为起始点开始计算边缘长度 disp(first_point); while ((first_point(1,1))~=0&(first_point(1,2)~=0)) %first_point %biaoji(:,:,bianjie_length) first_point=fun_find(bw1,biaoji,first_point(1,1),first_point(1,2),bianjie_length,0,0); if(first_point(1,1))~=0&(first_point(1,2)~=0) tempPos=biaoji(:,:,bianjie_length); temp1_im(tempPos(1),tempPos(2))=255; bianjie_length=bianjie_length+1; biaoji(:,:,bianjie_length)=first_point(:,:); pause(0.01); imshow(temp1_im); disp(first_point); end end disp(bianjie_length) bianjie_length=0; end end end end_im=temp1_im; figure,imshow(end_im); title('检测结果'); 代码:
function re_point=fun_find(bw,bji,a,b,len,c,d) %////////////////////////////////////// % bw为图象数据 % m,n为图象数据的维数 % bji为已搜索点记录 % a,b为搜索的起始点坐标 % len为已扫描的点数 % EDIT BY PSL 2008 08 20 %////////////////////////////////////// re_point=[c,d]; [m,n]=size(bw); bool=0; if(a==m) a1=m; else a1=a+1; end if(a==0) a2=0; else a2=a-1; end if(b==n) b1=n; else b1=b+1; end if(b==0) b2=0; else b2=b-1; end for k=a1:-1:a2 for l=b1:-1:b2 if (bw(k,l)==255&(k~=a|l~=b)) for bj=1:len if (bji(:,:,bj)==[k,l]) bool=1; end end if (bool==0); re_point(:,:)=[k,l]; break; end end end end end |
![]() |
![]() |