Home > vbmeg > external > iso2mesh > sample > demo_vol2mesh_ex3.m

demo_vol2mesh_ex3

PURPOSE ^

sample script to create volumetric mesh from

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 sample script to create volumetric mesh from 
 multiple levelsets of a binary segmented head image.

 Author: Qianqian Fang <fangq at nmr.mgh.harvard.edu>

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % sample script to create volumetric mesh from
0002 % multiple levelsets of a binary segmented head image.
0003 %
0004 % Author: Qianqian Fang <fangq at nmr.mgh.harvard.edu>
0005 
0006 % load full head image (T1 MRI scan)
0007 
0008 fprintf(1,'loading binary head image...\n');
0009 for i=1:256 
0010   head(:,:,i)=imread('head.tif',i);
0011 end
0012 
0013 % load segmented brain images (by freesurfer recon_all)
0014 fprintf(1,'loading binary brain image...\n');
0015 for i=1:256
0016   brain(:,:,i)=imread('brain.tif',i);
0017 end
0018 
0019 % fill holes in the head image and create the canonical binary volume
0020 % this may take a few minutes for a 256x256x256 volume
0021 fprintf(1,'filling holes in the volumetric images...\n');
0022 tic
0023 cleanimg=fillholes3d(logical(head>0),10);
0024 cleanbrain=fillholes3d(logical(brain>0),10);
0025 toc
0026 
0027 % add brain image as additional segment
0028 cleanimgfull=cleanimg+(cleanbrain>0);
0029 
0030 % create volumetric tetrahedral mesh from the two-layer 3D images
0031 % this may take another few minutes for a 256x256x256 volume
0032 clear opt;
0033 
0034 % set method for vol2mesh to 'simplify' to use these option
0035 opt(1).keepratio=0.05; % resample levelset 1 to 5%
0036 opt(2).keepratio=0.1;  % resample levelset 2 to 10%
0037 
0038 % by default, vol2mesh uses 'cgalsurf' method, which requires the following
0039 opt(1).radbound=4; % head surface element size bound
0040 opt(2).radbound=2; % brain surface element size bound
0041 opt(1).side='lower'; %
0042 opt(2).side='lower'; %
0043 
0044 tic
0045 [node,elem,face]=vol2mesh(cleanimgfull,1:size(cleanimg,1),1:size(cleanimg,2),1:size(cleanimg,3),opt,100,1);
0046 toc
0047 
0048 % plot the boundary surface of the generated mesh
0049 h=slice(cleanimgfull,[],[120],[120 180]);
0050 set(h,'linestyle','none')
0051 hold on
0052 
0053 plotmesh(node(:,[2 1 3]),face,'facealpha',0.7);

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005