How to create a wireframe 3D model from the MNI brain template with Matlab
Posted on 16. Feb, 2010 by admin in How To
PROBLEM: How can we obtain a 3D wireframe model of the standard brain in Matlab?
Sometimes we need to project significant results (statistical maps, correlation maps, functional connectivity, etc…) in a three dimensional space. While there are good tools for doing this, when we build a prototype we want to access the 3D image at a very low level.
This simple method utilises the standard MNI 152 2mm T1 brain mask template to build the wireframe.
The steps go as follows:
- Make sure you have FSL, in the folder /usr/local/fsl/data/standard/ you find the volume MNI152lin_T1_2mm_brain_mask.nii.gz
- Gunzip the volume (from the terminal: gunzip filename.gz) and load it in Matlab. You need the Matlab NIFTI toolbox.
img=load('brain.nii'); - As you can see by inspecting
img.imgthe loaded volume is made of 0 when we are outside the brain and 1 when we are inside the brain - To plot the wireframe we are using a function developed by Luigi Giaccari. See how it works here. As you see, we need to provide the point of our surface as a list of 3D coordinates (Nx3 matrix).
- With the next snippet of code, we extract the surface out of the Nifti standard volume:
img=load_nii('brain.nii'); brain=double(img.img); prev=0; p=[]; for x=1:91; for y=1:109 for z=1:91; v=brain(x,y,z); if(prev~=v) p=[p; x y z]; end prev=v; end end end - the variable p now stores Nx3 points in space that identify our surface
- to plot the surface as a 3D wireframe with Matlab you can then use:
[t,tnorm]=MyRobustCrust(p); figure(1) hold on axis equal h=trisurf(t,p(:,1),p(:,2),p(:,3),'facealpha',0.4,... ...'facecolor',[1 1 1],'edgecolor',[0.8 0.8 0.8]); view(3); axis vis3d
- Using all N values of p can result in a very dense surface. We can then downsample the p matrix and still obtain a decent plot (plot in the image above):
p=p(1:5:end,:);





