将凸包转换为二进制掩码

Jon*_*nas 4 matlab geometry convex-hull

我想生成一个二进制掩码,其中包含内部所有体素的二进制掩码,以及体积外所有体素的零.体积由围绕一组3D坐标(<100;一些坐标在体积内)的凸包定义.

我可以使用CONVHULLN获取凸包,但是如何将其转换为二进制掩码?

如果没有通过凸包的好方法,你还有其他想法如何创建二进制掩码?

gno*_*ice 8

您可以使用DelaunayTripointLocation方法解决此问题.这是一个例子:

pointMatrix = rand(20,3);       %# A set of 20 random 3-D points
dt = DelaunayTri(pointMatrix);  %# Create a Delaunay triangulation
[X,Y,Z] = meshgrid(0:0.01:1);   %# Create a mesh of coordinates for your volume
simplexIndex = pointLocation(dt,X(:),Y(:),Z(:));  %# Find index of simplex that
                                                  %#   each point is inside
mask = ~isnan(simplexIndex);    %# Points outside the convex hull have a
                                %#   simplex index of NaN
mask = reshape(mask,size(X));   %# Reshape the mask to 101-by-101-by-101
Run Code Online (Sandbox Code Playgroud)

上面的例子为跨越单位体积的101×101×101网格创建了一个逻辑掩模(每个维度为0到1),对于3的凸包内的网格点有一个1(真) D点集.