寻找兴趣区域之间的最短距离

3

我有一张二进制图像,其中有几个感兴趣的区域,我通过 bwconncomp 进行了识别。我正在尝试找到连接每个区域的最短路径。我考虑使用膨胀算法,在一个循环中使用不断增大的核大小进行计算,当连接组件的数量下降时暂停循环,然后可能通过中心的可观变化来确定已连接的区域,并使用迭代次数乘以2来得到大致距离?我觉得应该有更好的方法来实现这个目标吧?

distancebetweenROIS=[];
M11=tempBimage;

for c=1:50          
    TT=bwconncomp(M11);
    seDil=strel('disk',c);
    M11=imdilate(tempBimage,seDil);
    YY=bwconncomp(M11);
    if length(TT.PixelIdxList)>length(YY.PixelIdxList)
        distancebetweenROIS(end+1)=c*2;
    end

end

enter image description here

enter image description here

enter image description here


如果您只是传递每个区域的每一对(指定为(x,y)坐标列表)给pdist2,我认为您可以使用它来完成此操作。如果您没有统计工具箱,则可以尝试http://www.mathworks.com/matlabcentral/fileexchange/29004-feature-points-in-image--keypoint-extraction/content/FPS_in_image/FPS%20in%20image/Help%20Functions/SearchingMatches/pdist2.m - Dan
1个回答

2
使用和,您可以找到任何特征到所有其他特征的最短距离。然后,您只需通过特征循环即可。
%// labeledImage is 1 on feature #1, 2 on feature #2, etc

labeledImage = bwlabel(yourBinaryImage);

nLabels = max(labeledImage(:));

%// find the distance between each label and all other labels

distMat = zeros(nLabels, nLabels);

for iLabel = 1:nLabels

%// distance transform - every pixel is the distance to the nearest 
%//   non-zero pixel, i.e. the location of label iLabel

dist = bwdist(labeledImage==iLabel);

%// use accumarray b/c we can
%// get rid of the zeros in labeledImage, though, as there is no index 0

distMat(:,iLabel) = accumarray(dist(labeledImage>0),labeledImage(labeledImage>0),[],@min);

end

请注意,距离等同于“如果我从特征X开始,在像素之间跳到特征Y,最少需要多少跳”。如果您需要计算质心之间的距离,则regionprops(yourBinaryImage,'Centroids')后跟pdist2是更好的方法。

一个更正:最后一行应该是这样的 distMat(:,iLabel) = accumarray(labeledImage(labeledImage>0), dist(labeledImage>0),[],@min); - Our
不过有一个问题:是否可能获得最短距离线的方程? - Our

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接