## Friday, July 11, 2008

### VRML of a segmented image

I have an image segmented in matlab (in the form of 3d matrix with
elements 0 and 1) and from that matrix I want to create a vrml model,
do you know the best way to do it (with or without matlab, even if
with matlab I have the virtual reality toolbox installed)!

f,v]=isosurface (3Dmatrix,0);
translated to vrml with a simple script:

...
[fid,errmsg] = fopen('mymodel.wrl','w+');
...

----

fprintf(fid,' coord Coordinate {\n');
fprintf(fid,' point [\n');

for i=1:size (v,1)
fprintf(fid,'%f ',v(i,1)/500);
fprintf(fid,'%f ',v(i,2)/500);
fprintf(fid,'%f ',v(i,3)/500);
fprintf(fid,'\n');
end

fprintf(fid,' ]#Point\n');
fprintf(fid,' }#Coordinate\n');
fprintf(fid,' index[\n');

for i=1:size (f,1)
fprintf(fid,'%d ',f(i,1)-1);
fprintf(fid,'%d ',f(i,2)-1);
fprintf(fid,'%d ',f(i,3)-1);
fprintf(fid,'\n');
end

fprintf(fid,' ]#index\n');

...

fclose (fid);

Will you please show some (first ten lines - max .1kB) of the result?

unfortunately 30 megabytes for a 218x218x128 image!

The wrl file is not an image, it is the geometry and lighting.
You are sending the browser (the program that runs the .wrl file

(sets of x,y,z vertex values along with the info to make them
into triangles and lights that become pixels.

http://www.web3d.org/x3d/specifications/ISO-IEC-19776-X3DEncodings-XML-ClassicVRML/
that's too much (for both speed and memory), even because i want to
deal with much bigger matrix!

Great, we all want that.

ref: http://newsgroups.derkeiler.com/Archive/Comp/comp.lang.vrml/2007-08/msg00007.html