寻找感兴趣区域之间的最短长度

时间:2016-01-21 05:58:36

标签: matlab image-processing binary distance

我有一个二元图像,其中包含几个感兴趣的区域,我已通过bwconncomp识别出来。我试图找到连接这些区域的最短点。我正在考虑在代码类似于下面的循环中使用具有越来越大的内核大小的扩张,当连接的组件的数量下降时暂停循环,然后可以识别通过质心中的相当大的变化并使用迭代次数连接的那些两个给出近似距离?我觉得应该有更好的方法吗?

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

1 个答案:

答案 0 :(得分:0)

使用bwdistbwlabel,您可以找到任何功能与所有其他功能的最短距离。您所要做的就是遍历这些功能。

%// 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是更好的方法。