【问题标题】:Finding shortest length between to regions of interest寻找感兴趣区域之间的最短长度
【发布时间】:2016-04-27 06:19:42
【问题描述】:

我有一个包含多个感兴趣区域的二进制图像,我通过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

【问题讨论】:

标签: matlab image-processing binary distance


【解决方案1】:

使用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 是更好的方法。

【讨论】:

  • 一次更正:最后一行应该是distMat(:,iLabel) = accumarray(labeledImage(labeledImage>0), dist(labeledImage>0),[],@min);
  • 一个问题:是否有可能得到最短距离线的方程?
猜你喜欢
  • 2011-08-10
  • 2021-09-25
  • 2016-08-31
  • 2017-09-28
  • 2012-02-22
  • 2013-03-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多