MATLAB:pdist,发现在二值图像
问题描述:
我有一个二进制图像,并发现连接利息/连接部件的附近的两个区域使用MATLAB:pdist,发现在二值图像
min(min(pdist2(CCstats(1).PixelList,CCstats(2).PixelList)))
我还需要获得最小距离最小成对距离的像素位置这个距离的这些末端的坐标/这两个感兴趣区域之间最相邻的像素
我打算沿着这个距离画一条线。我打算使用类似于:
x=linspace(coord1(1), coord2(1),1000);
y=linspace(coord1(2), coord2(2),1000);
index=sub2ind(size(image),round(y),round(x));
image(index)=1;
有关如何找到这些坐标的任何建议?
由于
答
您将要的min
第二输出(带有ind2sub
组合)来确定对应于最小距离的pdist2
矩阵的行/列。
distances = pdist2(CCstats(1).PixelList, CCstats(2).PixelList);
[mindist, minind] = min(distances(:));
%// Now convert this linear index into index1/index2 into your pixel lists
[index1, index2] = ind2sub(size(distances), minind);
%// Now grab the coordinates using these index values
coord1 = CCstats(1).PixelList(index1,:);
coord2 = CCstats(2).PixelList(index2,:);