将凸包转换为二进制掩码 [英] Converting convex hull to binary mask
问题描述
我想生成一个二进制掩码,它对于所有体素来说都是一样的,对于体积之外的所有体素来说都是零。体积由一组三维坐标(<100;一些坐标位于体积内)的凸壳限定。
我可以得到凸包使用 CONVHULLN ,但是如何将其转换为一个二进制掩码?
如果没有好的方法可以通过凸包,您是否有其他想法可以创建二进制掩码?
您可以使用 DelaunayTri class 和 pointLocation 方法。下面是一个例子:
pointMatrix = rand(20,3); %#一组20个随机三维点
dt = DelaunayTri(pointMatrix); %#创建Delaunay三角剖分
[X,Y,Z] = meshgrid(0:0.01:1); %#为你的卷创建一个坐标网格
simplexIndex = pointLocation(dt,X(:),Y(:),Z(:)); %#查找单纯形索引
%#每个点在
掩码内=〜isnan(simplexIndex); %#在凸包外的点有一个
%#单纯形索引NaN
mask = reshape(mask,size(X)); %#将面具重新塑造成101×101×101
上面的例子创建了一个逻辑对于101×101×101的网格,单位体积(每个维度0到1)的掩模,对于三维点集的凸包内的网格点,具有1(真) p>
I want to generate a binary mask that has ones for all voxels inside and zeros for all voxels outside a volume. The volume is defined by the convex hull around a set of 3D coordinates (<100; some of the coordinates are inside the volume).
I can get the convex hull using CONVHULLN, but how do I convert that into a binary mask?
In case there is no good way to go via the convex hull, do you have any other idea how I could create the binary mask?
You can solve this problem using the DelaunayTri class and the pointLocation method. Here's an example:
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
The above example creates a logical mask for a 101-by-101-by-101 mesh spanning the unit volume (0 to 1 in each dimension), with a 1 (true) for the mesh points inside the convex hull of the 3-D point set.
这篇关于将凸包转换为二进制掩码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!