Voxelise STL files using mesh voxelisation

22 views (last 30 days)
Zehra Ese
Zehra Ese on 17 Jun 2020
Answered: TED MOSBY on 18 Mar 2025
Hi, I would like to voxelise a 3d mesh constuction (STL file), which works very well with the mesh voxelisation from the file exchange (https://de.mathworks.com/matlabcentral/fileexchange/27390-mesh-voxelisation). This program is able to voxelise the imported STL file in a given grid, which is definable by the user in three dimensions [gridX,gridY,gridZ]. The voxelsize in this way is defined by the STL model size and the given number of voxels. I would like to define the voxelsize by myself, fo example 1mm and the number if voxels for each dimension should be adjust to the model size. For example the model is a cube with the dimension of 3x4x5 mm. With a cubic voxelsize of 1 mm, we would get 3 voxels in X direction, 4 voxels in Y direction and 5 voxels in Z directeion, respectively. Is there a way to do like this?
  2 Comments
Jan Marxen
Jan Marxen on 11 Apr 2021
If you found something like that please tell me. Thank you
Zhihao Wei
Zhihao Wei on 5 Jul 2023
I am also looking for stl2voxel matlab code, pls let me know.

Sign in to comment.

Answers (1)

TED MOSBY
TED MOSBY on 18 Mar 2025
Hi Zehra,
You can voxelize an STL mesh at a fixed voxel size (e.g., 1 mm) using the “VOXELISE” function from the File Exchange. The key idea is to:
  • Define a 1 mm grid based on the model's dimensions (3×4×5 mm) so you get exactly 3 voxels in X, 4 in Y, and 5 in Z (total 60).
  • Call "VOXELISE" with those grid coordinates (e.g., voxel centers at 0.5, 1.5, … in each dimension) plus the mesh to find which cells are inside the model.
  • Draw each true cell as a 1×1×1 cube (red faces, black edges) so you see the full 3×4×5 array of voxels.
I have attached an example script as reference. As I dont have your STL file I simulated it by creating a cuboid mesh. Feel free to adjust according to your use case.
Hope this helps!

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!