How to export 3D image from matlab and import it into maya
5 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
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
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.
更多回答(1 个)
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 Center 和 File Exchange 中查找有关 Basic Display 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!