获得属于凸包的点

use*_*748 8 matlab convex-hull

我在Matlab中有一个颗粒的二进制图像.我可以通过以下功能找到颗粒的凸包:

[K, V] = convhull(granule);
Run Code Online (Sandbox Code Playgroud)

如何找到属于凸包的所有像素,但不属于原始图像中的颗粒?我的意思是我想做那样的事情:

granule2 = zeros(size(granule));
granule2(K == 1 & granule == 0) = 2;
Run Code Online (Sandbox Code Playgroud)

它不起作用,因为K的大小为x乘3,其中x是凸包中的三角形数.

编辑:根据文档,凸包应该是一个数组,其中每个行的凸包构成点.那么如何找到由这些点确定的体积内的所有点.

编辑2:让我换句话说:我有一个3D点阵列的图像.它不是一个球体,它有一些凹痕(因此凸面船体不会放在我的图像表面).

我想找到凸包,然后找到凸包内部的所有点,但是在颗粒之外.这是它在2D中的样子(我想找到红色像素在此输入图像描述):

编辑3:NicolaSysnet,你的算法应该返回我图片中红色的所有像素(它们的索引)(图片是2D,因为它更容易绘制). 在此输入图像描述

Adr*_*aan 3

[K, V] = convhull(granule);
granule2 = zeros(size(granule));
tmp = granule(K,:)==0; %// all points on the convex hull but not in the granule
tmp2 = tmp(:,1)==tmp(:,2); %// both indices of your granule are zero
granule2(tmp(tmp2)) = 2;
Run Code Online (Sandbox Code Playgroud)

K是与凸包上的点相对应的点的行号,V就是该凸包所跨越的体积。因此,您可以使用此行索引来查找颗粒中的零索引。

使用下面的例子:

granule = rand(1e3,2);
[K, V] = convhull(granule);
granule2 = zeros(size(granule));
tmp = granule(K,:)<0.1; %// all points on the convex hull but not in the granule
tmp2 = tmp(:,1)==tmp(:,2); %// both indices of your granule are below 0.1
granule2(tmp(tmp2)) = 2;
Run Code Online (Sandbox Code Playgroud)

结果为sum(tmp2)=11,因此在这种情况下有 11 个点位于凸包上,并且两个索引都低于 0.1(我无法使用,==0因为我的数组中没有零)。

tmp2您可能需要根据实际需要更改条件。

毫不奇怪,更多的人为此苦苦挣扎,并为此编写了代码,请参阅MathWorks Central,由 John D'Errico 编写。