binsurface: fast (triangular/rectangular) isosurface extraction for 3D binary images

1. Detailed help info:
2. parameters:
3. outputs
4. example:
4.1.1. example output
5. notes

1. Detailed help info:

[node,elem]=binsurface(img,nface)

fast (triangular/rectangular) isosurface extraction for 3D binary images, by Qianqian Fang, <fangq at nmr.mgh.harvard.edu>

2. parameters:

img
a 3D binary image
nface
nface=3 or ignored - for triangular faces, nface=4 - square faces

3. outputs

elem
integer array with dimensions of NE x nface, each row represents a surface mesh face element
node
node coordinates, 3 columns for x, y and z respectively

the outputs of this subroutine can be easily plotted using

    patch('Vertices',node,'faces',elem,'FaceVertexCData',node(:,3),'FaceColor','interp');
if the surface mesh has triangular faces, one can plot it with
    trisurf(elem,node(:,1),node(:,2),node(:,3))

4. example:

the following sample code shows how to use binsurface to create iso-surfaces of a spherical object.
 dim=64;
 [xi,yi,zi]=meshgrid(1:dim,1:dim,1:dim);
 dist=(xi-32).^2+(yi-32).^2+(zi-32).^2;
 v=zeros(size(xi));
 v(dist<256)=1;
 % triangular surface
 [node,elem]=binsurface(v);
 subplot(121);
 trisurf(elem,node(:,1),node(:,2),node(:,3));
 axis equal;
 % cubical surface
 [node,elem]=binsurface(v,4);
 subplot(122);
 trisurf(elem,node(:,1),node(:,2),node(:,3));
 axis equal;

4.1.1. example output

upload:binsurface_sample.png

5. notes

This function is not included in iso2mesh 0.5.1. You can get it at our CVS. It will be included in the next release of this toolbox. One can download this function alone from Matlab File Exchange.

This function is Octave compatible.

Powered by Habitat