How to export 3D image from matlab and import it into maya

4 views (last 30 days)
I have a 3D image in Matlab and I want to deform it using Maya,But I have no idea how I can 1)export it from Matlab and 2) how to import it into Maya.
Thanks alot!

Accepted Answer

Anton Semechko
Anton Semechko on 11 Jan 2012
Hi Ava,
I am assuming the image you are working with has already been segmented (or labelled) into distinct components. If so, here is what you can try:
Suppose the object of interest contained in your image is represented by voxels with values equal to 1, while the background is represented by values equal to -1.
1) First you may want to remove the voxelization (aka staircase) artefacts. You can do this by applying a low-pass filter to your image using the built-in MATLAB function titled ' smooth3'. Alternatively, you can implement your own pre-processing routine.
2) Extract the isosurface using marching cubes algorithm. For example, you can use the built-in function 'isosurface' or you can use the routine submitted by Peter Hammer:
3) Export the mesh to a .stl file using the 'stlwrite' function that can be download from here:
Note that while using the above function, you may encounter the following error:
??? Undefined function or method 'narginchk' for input arguments of type 'double'.
Error in ==> stlwrite at 55
narginchk(2, inf)
To get rid of it you will have to edit out 'narginchk(2, inf)' on line 55
4) Finally, you can now import the .stl file into Maya and do what you have to ...
Here is an example:
% Simulate a segmented image
F=(x.^4 + y.^4 + z.^4) - 10*(0.13)^2*(x.^2 + y.^2 + z.^2); % pill-box
figure('color','w'), isosurface(x,y,z,F,0), axis equal
% Smooth
figure('color','w'), isosurface(x,y,z,F,0)
% Extract the surface mesh
figure('color','w'), h=trimesh(tr); axis equal
% Write to .stl
Good luck!
Walter Roberson
Walter Roberson on 12 Jan 2012
At the MATLAB command prompt, command
edit stlwrite.m
In the editor session, find line 55, the one with the narginchk. Add a % at the beginning of the line to comment it out. Save the file.
ava on 13 Jan 2012
Thank you very much ! that was a great solution

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 11 Jan 2012
Perhaps using a .obj object would do? My notes say that Maya can read and write those files; they also say: A description of Lightwave's .obj format can be found at

Community Treasure Hunt

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

Start Hunting!