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

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!

 Réponse acceptée

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 commentaires

Hello Anton,
So basically what I have right now is a surface(mesh) of the tongue and the following is the code to generate it,I believe there might be a simple way to convert it to obj format.
clear;
close all;
% the beat selection for the activation parameter (A1 ...A7) is -0.02.
A1=.006;%jaw height
A2=.006;%tongue tip
A3=-.02;%tongue dorsum
A4=.006;%tongue body
A5=-.02;%tongue low
A6=-.02;%tongue volume
A7=-.02;%tongue advance
%-----------------Reference mesh--------------------------------
vertices=[1 14.8863 25.5558 -102.576
2 9.69095 25.1874 -101.184
3 4.50876 24.6425 -99.7957
4 -0.682123 24.1926 -98.4048
5 -5.26158 21.8553 -97.1778
6 -7.65997 17.1568 -96.5351
7 -7.78844 11.7766 -96.5007
8 -6.91814 6.4643 -96.7339
9 -6.31057 1.1322 -96.8967
10 -6.59166 -0.6358 -96.8214
11 -8.35447 -5.4924 -96.349
12 -8.92437 -10.597 -96.1963
13 -7.42332 -15.5169 -96.5985
14 -4.41349 -19.6439 -97.405
15 -0.163421 -22.2464 -98.5438
16 4.73865 -23.3486 -99.8573
17 9.61851 -24.5577 -101.165
18 14.5134 -25.6949 -102.476
19 12.0579 17.6021 -97.4571
20 7.2214 21.4326 -96.686
21 2.67482 22.6482 -95.4677
22 -1.90077 22.0726 -94.2417
23 -5.65436 19.4149 -93.2359
24 -8.15321 15.3864 -92.5663
25 -9.53351 10.7034 -92.1965
26 -9.82039 5.7998 -92.1196
27 -9.32874 1.5036 -92.2514
28 -9.83488 -1.2325 -92.1157
29 -11.5967 -5.3727 -91.6437
30 -11.9396 -10.3259 -91.5518
31 -10.4782 -15.2409 -91.9434
32 -7.85667 -19.5707 -92.6458
33 -3.80075 -22.173 -93.7326
.
.
.
1229 2.42731 -60.1466 -59.0661];
tongue=[
273 272 37
37 272 19
272 273 303
303 304 334
37 19 20
37 20 38
38 20 21
38 21 39
39 21 22
.
.
.
461 444 445
];
figure;
node_xy = vertices(:,2:3)'; % X and Y coordinates
quad_node = tongue'; % Polygon nodes
value_xy = vertices(:,4)';% Z coordinates
node_num = size ( node_xy, 2 );%number of nodes
quad_num = size ( quad_node, 2 );% number of polygons
fprintf ( 1, '\n' );
fprintf ( 1, ' Number of nodes = %d\n', node_num );
fprintf ( 1, ' Number of quadrilaterals = %d\n', quad_num );
quad_surface_display ( node_num, node_xy, quad_num, quad_node, value_xy );
title('reference tongue');
%
% Terminate.
So what's your question?
Hoe can I edit "narginchk(2, inf) " error?
Thanks
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.
Thank you very much ! that was a great solution

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 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

Catégories

En savoir plus sur Risk Management Toolbox dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by