## Thursday, September 24, 2009

### iso2mesh: a Matlab/Octave-based mesh generator: Examples Segmented images

iso2mesh: a Matlab/Octave-based mesh generator: Doc/Examples: "Example Scripts for Using iso2mesh

1. Demonstration for surf2mesh
2. Demonstration 1 for vol2mesh
3. Demonstration 2 for vol2mesh
4. Demonstration 3 for vol2mesh

We provided a couple of example scripts to demonstrate the basic utilities of this toolbox. They can be found at sample/ subdirectory from iso2mesh's installation directory. In this page, we will briefly describe the input/output for each of the example and show you the process of the mesh creation using iso2mesh. Most the examples come from author's realistic research problems. For example, the surf2mesh example came from vessel network modeling; demo1 for vol2mesh came from small animal florescences imaging, and demo3 of vol2mesh originated from a combined image reconstruction of brain functional imaging using MRI, MEG and diffuse optical tomography.

1. Demonstration for surf2mesh
The sample script 'demo_surf2mesh_ex1.m' is to demonstrate how to use surf2mesh for meshing a simple open-ended surface. The surface is saved in 'surfmesh_demo.mat'. Loading this mat file, you will find two variables, f, and v, they record a tube surface mesh. One can view this surface by

trisurf(f,v(:,1),v(:,2),v(:,3)); axis equal;

then, we call surf2mesh to produce volumetric mesh from this surface. This includes 3 sub steps

1. in the first step, the fine surface, f and v, are re-sampled to only keep 10% of the original elements
2. because the surface has openings, in the second step, iso2mesh added a cubic frame outside the tube, and punch openings on the bounding box and merge with the tube surface to create a closed surface
3. in the third step, a volumetric mesh is generated within the enclosed volume bounded by the bounding box and the tube.

After step 1, the surface mesh look like upload:tube_surf_sampled.png
After step 2, the surface mesh look like upload:tube_mesh.png
After step 3, the volume mesh look like upload:tube_mesh2.png

I want to mention that at this point, iso2mesh can only mesh surfaces with their edges (borders of the open regions) strictly located within a bounding box surface. It can even handle the complex cases where a opening edge contour located on multiple sides of the bounding box.

2. Demonstration 1 for vol2mesh
The first vol2mesh demonstration is to create an FEM mesh from a CT scan of a rat-head. In this example, the volumetric data is a thresholded CT image of a rat. In a vol2mesh session, we first wrap the volume with a layer of zeros, in order to make the non-zero region close. Then we extract the boundary of the non-zero regions by calling Matlab's isosurface(). The created iso-surface, in the resolution of voxel sizes, will be re-sampled to specified mesh density. Before and after the simplification, we perform a mesh validation and repair process to avoid the appearance of 'non-manifold' nodes. Once the surface mesh is completed, we produce volumetric mesh within the region bounded by the re-sampled surface mesh.

The re-sampled rat surface mesh is shown below upload:mouse_mesh.png
3. Demonstration 2 for vol2mesh
In this example, we try to make a little bit fun using iso2mesh while showing off the extreme flexibility and simplicity of making a complex mesh using this toolbox. We will make a mesh on a slab-shaped object with 'ISO2Mesh' etched on one of the surface, just like the header image of this document showing.

To make this 'object', we first create a black-white image, 'iso2mesh_bar.tif', with an image editor. This image is then read as a 2D array into matlab, we then invert the 0-1 values, and stack it to 30 layers to make a etched patten, then, append another 30 layers of pure 1 image at the end of the stack as the base. Now we have this binary array with etched letter patterns.

The original 2D binary pattern is upload:iso2mesh_bar_2d.png
and the 3D object surface look like upload:iso2mesh_bar_3d_vox_small.png

We pass this array to vol2mesh, and set the surface simplification ratio to 10%, and maximum volume of 100 (in voxel unit), after going through similar processes as in demo1, we will get a volumetric mesh just like what you see from the header bar image.

The generated surface mesh is upload:iso2mesh_bar_1.png

4. Demonstration 3 for vol2mesh
Demonstration 3 is another challenging example showing you how to apply iso2mesh in complex geometries such as head and brain imaging. The 3D head and brain images were extracted from a real head scan from MRI. To save space, we convert them into a binary format as head.tif and brain.tif, respectively, where the brain is simple a segmented subregions from the head scan.

Reading the head binary image into matlab and plot a slice, you will find there are lots of gaps and openings in the volume. As the dimensions of these gaps are close to the sale of a few voxel, it will give iso2mesh a really bad time trying to mesh with these gaps and holes. Therefore, we first perform a binary volume repairing process: deisland3d, to fill the holes and remove the isolated regions form the image. The cleaned up version of the head image can be found at here. The brain volume is clean by itself, so, we do not need to do hole-filling and island-removing.