我想生成一个二进制掩码,其中所有内部体素都为 1,体积外所有体素为 0。体积由围绕一组 3D 坐标的凸包定义(<100;一些坐标在体积内)。
我可以使用 CONVHULLN 得到凸包,但如何将其转换为二进制掩码?
如果没有通过凸包的好方法,您是否有任何其他想法可以创建二进制掩码?
最佳答案
您可以使用 DelaunayTri class 解决此问题和 pointLocation method .这是一个例子:
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
上面的示例为跨越单位体积(每个维度为 0 到 1)的 101×101×101 网格创建了一个逻辑掩码,凸包内的网格点为 1(真) 3-D 点集。
关于matlab - 将凸包转换为二进制掩码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2769138/