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

조회 수: 5 (최근 30일)
ava
ava 2012년 1월 11일
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!

채택된 답변

Anton Semechko
Anton Semechko 2012년 1월 11일
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
Walter Roberson
Walter Roberson 2012년 1월 12일
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 2012년 1월 13일
Thank you very much ! that was a great solution

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 1월 11일
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

카테고리

Help CenterFile Exchange에서 Risk Management Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by