将凸包转换为二元掩模

发布于 2024-08-31 16:12:31 字数 288 浏览 15 评论 0原文

我想生成一个二进制掩码,其中 1 表示内部的所有体素,0 表示体积外部的所有体素。体积由一组 3D 坐标周围的凸包定义(<100;一些坐标位于体积内部)。

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

疯狂的代价 2024-09-07 16:12:31

您可以使用 DelaunayTri 解决此问题类pointLocation方法。下面是一个示例:

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 点集。

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.

韬韬不绝 2024-09-07 16:12:31

现在已经很晚了,所以只有一个非常粗略的建议:

  1. 用凸包中的点构建 Delaunay 曲面细分。
  2. 使用 DelaunayTri 类的 pointLocation 方法测试像素数组中的每个点。

我预计这会非常慢,并且有更好的解决方案,如果有一个出现在我的梦想中,我明天会再次发布。

It's late here, so only a very sketchy suggestion:

  1. With the points from your convex hull construct a Delaunay tessellation.
  2. Using the pointLocation method of the DelaunayTri class test every point in your array of pixels.

I expect that this will be very slow, and that there are better solutions, if one comes in my dreams I'll post again tomorrow.

半枫 2024-09-07 16:12:31

这是扫描转换问题。查看 3D 的第 8 节基于体素的图形的扫描转换算法

您想要的算法是可靠的算法,并且稍微简单一些,因为您正在对一个面为三角形的凸多面体进行体素化 - 每个“体素”运行都以两个三角形为界。

This is a scan conversion problem. Check out section 8 of 3D Scan-Conversion Algorithms for Voxel-Based Graphics.

The algorithm you want is the solid one, and is slightly simpler since you are voxelizing a convex polyhedron whose faces are triangles - each "voxel" run is bounded by two triangles.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文