Code covered by the BSD License  

Highlights from
Export Voxel Data

5.0 | 3 ratings Rate this file 29 Downloads (last 30 days) File Size: 2.05 MB File ID: #43640 Version: 1.0
image thumbnail

Export Voxel Data



Export objects described in a logical matrix, label matrix or voxel list to STL and PovRay mesh2.

| Watch this File

File Information

Export Voxel Data

This submission allows to export multiple objects described in logical matrix, label matrix or voxel list data to STL and PovRay mesh2 format.

Mesh can be determined from the data using convhull, isosurface or geometric method.

Extracted mesh can be smoothed, resampled and translated as required.

Package provides a script, which allows to generate a simple PovRay scene, where exported objects are included with a given colour, transparency and texture. Objects can be coloured using some array of scalars as a key.

Similar script is written to export a Blender "configuration" file, which can be opened with a Blender add-on (also attached) that imports STL files and assigns each object a colour specified in the "configuration" file.

A manual describing every option is provided. Further examples that use real data are available to download (links are included in the manual).

External scripts used/included within the upload (that are not present on MathWorks):
- resampling script from "iso2mesh" package by Qianqian Fang (Available at:
- a stereoscopic camera add-on to Blender by Sebastian Schneider (Available at:

License crash difficulties

The resampling part of the package could not be included in the submission itself, but on first required use of the resampling part it will be downloaded from my Google Drive and added to the package. This is because it uses some functions from iso2mesh package, which is distributed under GNU license and does not support it.

Similar situation applies to Blender Addons. Both are distributed under GPL license, hence are not included in the package, but there is a hotlink present in the package to download them.

I am sorry for additional problems, but this was the easiest way I could think of to overcome the problem of licensing.


This package is a by-product of my main internship project, which was analysis of random rod packing. Further examples mentioned above use some of the data collected.

I did my best to make the package up to MathWorks standard, but it is my first submission, so I would appreciate all comments and suggestions on what to change.


Stlwrite(Filename, Varargin), Smooth Triangulated Mesh, Check Whether Mex File Is Compiled For System, and Converting A 3 D Logical Array Into An Stl Surface Mesh inspired this file.

Required Products MATLAB
MATLAB release MATLAB 8.1 (R2013a)
Other requirements Optional PovRay and Blender.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
25 Jul 2015 Francesco Sciortino

Very nice and thorough work!

13 Jul 2015 Cyprian Lewandowski

Thai V. Hoang,

Thank you. I will look into incorporating anisotropic voxels into the package.

Comment only
08 Jul 2015 Thai V. Hoang

A very nice package although anisotropic voxel is not yet handled. Could you add this feature to the export function?

12 Mar 2015 Cyprian Lewandowski


My first guess, as I don't know how it failed, would be that the matrix size is too large for your computer to handle. That has happened to me on few occasions and usually decreasing resolution solves it.

Could you try rescaling your matrix? I would go for the imresize function.

As to what size should you rescale: that depends on the memory you have available :)

Comment only
11 Mar 2015 Erez

Erez (view profile)

I tried this on a matrix that is 2500 x 2500 x 2400, and it failed. any ideas?

Comment only
29 Sep 2013 Max Neudecker

Overall, this is a very useful package, which an exceptionally good documentation (See PDF file!) Its main advantage are generic, well accessible interface and the modular, integrated workflow (see the Fig.2 in the manual).

For me (MATLAB 2012b, ubuntu64bit), it works out of the box, and automatically compiled the missing mex files for your platform.

However, I encountered a few Out-Of-Memory issues with the "smoothing" option. If you set the default value,
p.smoothing.smooth = false; (ExportVoxelData.m, line 137) then it works. The "geometric" option took very long, I suppose it got stuck in CONVERT_meshformat.

I think, if you have 3D-data e.g. from X-Ray-Tomography or confocal microscopy, and are looking for nice visualization -even with stereoscopic images- of segmented objects in Povray or with your favourite STL program, this might be the right tool.

Keep up the good work!

Contact us