区分简单连接的数字? [英] Distinguish a simply connected figures?

查看:256
本文介绍了区分简单连接的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So I have a binary matrix in Matlab. It is basically a blob (pixels of value 1) surrounded by a neutral background (value 0).

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

I want to figure out whether this blob is simply connected or not. Figure below is a straightforward example.

如何实现这一目标?
值得注意的是我理解像素化图像中的每条路径都可以通过选择4个相邻元素(上,下,左,右)或8个相邻元素等来创建 - 在这种情况下无关紧要。

How can this be achieved? Notably I understand that every path in a pixelated image can be created by choosing from 4 adjacent elements (up, down, left, right) or 8 adjacent elements etc - it doesn't matter in this case.

推荐答案

代码

%// 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

这篇关于区分简单连接的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆