5
$\begingroup$

My goal is to produce a 3D dataset, from a scene of simple transformed shapes. The idea is that this data serves as a ground truth for some tomographic reconstruction problems. (For this, it is especially nice that with Mathematica, Ellipsoid, Cuboid and other 3D primitives remain algebraic up to the point of discretization.)

Ideally, I would like to partition the 3D space into voxels (small cuboids), and compute per voxel how much of it is filled by a shape. This does not have to be very precise, I'm happy already if the value is $1$ if it contains something and $0$ otherwise.

However, I do not manage to get the shapes into a discrete dataset of values. So far, I tried something simple:

B = Ball[{10,10,10}, 2];
reg = TransformedRegion[B, ShearingTransform[Pi/5, {1, 0, 0}, {0, 0, 1}]]
DiscretizeGraphics[Graphics3D[reg]];

which produces a triangular mesh (instead of a uniform) for an ellipsoid (sheared ball).

For 2D problems I managed to get grid data from converting the Graphics to grayscale, and subsequently to ImageData. In 3D that doesn't work.

It seems like a relatively simple thing to do, but after a few hours of bugging the documentation, I still did not find a solution. All suggestions are much appreciated.

$\endgroup$
8
  • $\begingroup$ Do you mean that you want to have a full-dimensional discretization of reg? Then try BoundaryDiscretizeRegion[reg] or DiscretizeRegion[reg]. Graphics3D objects represent only the surfaces of the regions (for performance reasons). $\endgroup$ Commented Oct 19, 2018 at 15:09
  • 2
    $\begingroup$ Have you seen RegionImage[]? $\endgroup$ Commented Oct 19, 2018 at 15:10
  • $\begingroup$ @HenrikSchumacher Thanks, that is good to know! $\endgroup$ Commented Oct 19, 2018 at 15:13
  • $\begingroup$ @J.M. Wow! That looks very promising, how could I have missed that! Thanks! $\endgroup$ Commented Oct 19, 2018 at 15:14
  • 1
    $\begingroup$ You could combine it with ImageMesh[] if you want to see a voxelization. $\endgroup$ Commented Oct 19, 2018 at 15:17

1 Answer 1

5
$\begingroup$

As I noted in the comments, a judicious combination of RegionImage[] and ImageMesh[] will yield suitable voxelizations of regions. Applied to the OP's example:

reg = TransformedRegion[Ball[{10, 10, 10}, 2], 
                        ShearingTransform[π/5, {1, 0, 0}, {0, 0, 1}]];

ImageMesh[RegionImage[DiscretizeRegion[reg]]]

voxelized ellipsoid

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.