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

5 Ansichten (letzte 30 Tage)
ava
ava am 11 Jan. 2012
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!

Akzeptierte Antwort

Anton Semechko
Anton Semechko am 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: http://www.mathworks.com/matlabcentral/fileexchange/32506-marching-cubes
3) Export the mesh to a .stl file using the 'stlwrite' function that can be download from here: http://www.mathworks.com/matlabcentral/fileexchange/20922-stlwrite-write-binary-or-ascii-stl-file
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
x=linspace(-1.1,1.1,50);
[x,y,z]=meshgrid(x);
F=(x.^4 + y.^4 + z.^4) - 10*(0.13)^2*(x.^2 + y.^2 + z.^2); % pill-box
F(F<=0)=-1;
F(F>0)=1;
figure('color','w'), isosurface(x,y,z,F,0), axis equal
% Smooth
F=smooth3(F);
figure('color','w'), isosurface(x,y,z,F,0)
% Extract the surface mesh
M=isosurface(x,y,z,F,0);
tr=TriRep(M.faces,M.vertices);
figure('color','w'), h=trimesh(tr); axis equal
set(h,'FaceColor','w','EdgeClor','b')
% Write to .stl
stlwrite('PillBoxExample.stl',tr.Triangulation,tr.X)
Good luck!
  5 Kommentare
Walter Roberson
Walter Roberson am 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
ava am 13 Jan. 2012
Thank you very much ! that was a great solution

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 11 Jan. 2012
Perhaps using a .obj object would do? http://www.mathworks.com/matlabcentral/fileexchange/27982 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 http://www.martinreddy.net/gfx/3d/OBJ.spec

Community Treasure Hunt

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

Start Hunting!

Translated by