【问题标题】:Distinguish a simply connected figures?区分一个简单连通的数字?
【发布时间】:2014-06-30 01:52:05
【问题描述】:

所以我在 Matlab 中有一个二进制矩阵。 它基本上是一个被中性背景(值 0)包围的斑点(值 1 的像素)。

我想弄清楚这个 blob 是否是简单连接的。 下图是一个简单的例子。

如何做到这一点? 值得注意的是,我知道像素化图像中的每条路径都可以通过从 4 个相邻元素(上、下、左、右)或 8 个相邻元素等中进行选择来创建 - 在这种情况下并不重要。

【问题讨论】:

    标签: image matlab image-processing blob


    【解决方案1】:

    代码

    %// Assuming bw1 is the input binary matrix
    
    [L,num] = bwlabel( ~bw1 );
    counts = sum(bsxfun(@eq,L(:),1:num));
    [~,ind] = max(counts);
    bw2 = ~(L==ind);
    
    %// Output decision
    [L,num] = bwlabel( bw1 );
    if ~nnz(bw1~=bw2) && num==1
        disp('Yes it is a simply connected blob.')
    else
        disp('Nope, not a simply connected blob.')
    end
    

    【讨论】:

    • 毫无疑问,代码很短,而且看起来很有魅力。我已准备好接受您的回答,但您能否就 countsind 背后的原因发表一点评论?
    • @Pranasas 要点:前四行未注释的代码基本上给出了填充的斑点。 1. counts = sum(bsxfun(@eq,L(:),1:num)); 为您提供倒置图像中每个斑点的像素数。 2. 从中找出最大的 blob,由 [~,ind] = max(counts);L==ind 完成。 3. 反转将在原始矩阵中产生填充斑点的最大斑点。决策部分:将填充的 blob 与原始 blob 进行比较,从而帮助我们确定它是否是简单连接的。希望这是有道理的。
    • 谢谢!这很聪明!
    猜你喜欢
    • 2018-11-04
    • 2017-08-19
    • 1970-01-01
    • 1970-01-01
    • 2011-07-27
    • 1970-01-01
    • 1970-01-01
    • 2014-04-08
    • 1970-01-01
    相关资源
    最近更新 更多