matlab - 找到感兴趣区域之间的最短长度

标签 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

最佳答案

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

关于matlab - 找到感兴趣区域之间的最短长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34916387/

相关文章:

MATLAB parfor 广播变量值错误

一行中的 Matlab 向量到逗号分隔列表的转换

image-processing - 为 Windows Phone 开发 Polyframe 图像编辑应用程序

actionscript-3 - 上传前给图片添加水印? AS3 + 柔性

c# - 为什么是 -1L * -9223372036854775808L == -9223372036854775808L

python - 将二进制转换为十进制整数输出

MATLAB:如何在没有循环的情况下计算子矩阵

matlab - 在matlab中从结构创建表 - 对齐

opencv - OpenCV从二进制图像中消除鸿沟

mysql - 将十六进制值插入 MySql