Surface models types and voxelization

Hi all!

I have to convert a surface model stl into a voxelized mask, with 1s inside and 0s outside. It is important that the mask has the same dimensions and voxel size as another volume I want to register with. In Matlab the available functions don’t allow to specify voxel size and this is very important for me. Getting inspired by this post: Voxelization of mesh, I follow these steps:

  1. Import stl and convert into segmentation node by right clicking on the model entry in the data module.
  2. Import the other volume, and in the volume section specify the voxel size and center it.
  3. Go to the transform model, and create a new transformation which moves the segmentation so that the crucial parts of it overlap the other volume. This step may not be needed.
  4. Go to the Segmentation Module, and select export the segmentation as a labelmap, indicating as reference volume the other one, so that the output voxelized mask has the same dimensions and voxel size.
  5. Then, go to the volume section, select the just created volume, and convert to scalar volume.

I’d like to know if these steps are well or if there is another way to do it better. The stl model sometimes appears to be bigger than the object in the other volume, when it shouldn’t be. And other thing: should the stl model have some basis features (i.g. closed surface, filled inside etc.)?

The steps are correct.

You can write a script that performs all the steps without the need to use the GUI (see

We test all the conversions very thoroughly and we are not aware any shift or scale issues. If you have doubts then send a data set (upload somewhere and post the link here) and explanation of what you expect and what you find instead.

Surface to labelmap conversion is guaranteed to work if the surface is closed (watertight). STL is a surface mesh, so it cannot be filled inside. If the surface is not closed then it will be made a solid, watertight object “randomly”: the surface is sliced along the z axis and filled in line by line, so what parts and how will be filled depend on the object shape and orientation.