实验的目的:连接图像中存在断点的二值区域
原始图像如下所示:
实验原理:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
实验程序:
clear;close all; im = imread('C:Documents and Settingsluokh桌面line1.jpg'); imshow(im) BW=im2bw(im,0.5); s = regionprops(BW, 'ConvexHull'); figure,imshow(BW); % hold on; % plot(s(1).ConvexHull(:,1) ,s(1).ConvexHull(:,2) , 'r*'); % % hold on; % plot(s(2).ConvexHull(:,1) ,s(2).ConvexHull(:,2) , 'g*'); % % hold on; % plot(s(3).ConvexHull(:,1) ,s(3).ConvexHull(:,2) , 'b*'); [m1 ,~]=size(s(1).ConvexHull); [m2 ,~]=size(s(2).ConvexHull); len=length(s); for i=1:len-1 for j=i+1:len [m1 ,~]=size(s(i).ConvexHull); [m2 ,~]=size(s(j).ConvexHull); for h=1:m1 for k=1:m2 if pdist([s(i).ConvexHull(h,:) ;s(j).ConvexHull(k,:)],'euclidean')<100 hold on; plot([s(i).ConvexHull(h,1) ,s(j).ConvexHull(k,1)] ,[s(i).ConvexHull(h,2) ,s(j).ConvexHull(k,2)],'r'); end end end end end
实验结果: