NIMH MEG Core Facility

National Institute of Mental Health, Bethesda, Maryland

Main

MEG Analysis

Valid XHTML 1.0!

Valid CSS!

view · edit · attach · print

« newDs2 | Software | checkSpheres »

brainhull

Brainhull is a set of tools for creating headmodels from structural MRI scans, including headshapes, brainshapes, and multisphere models for either heads or brains, as well as geometry for realistic volume conductor models. Brainhull uses AFNI to do most of the work. With the brainhull tools and AFNI, the CTF programs MRIConverter and MRIViewer are no longer necessary.

If you create a brain shape, instead of a head shape, be aware that SAMsrc, which always uses the shape to clip the .svl file, subtracts .5 cm from the radius of each sphere. You'll need to run the program inflateSpheres (included with brainhull), which adds .5 cm to each sphere.

Download and Installation

Download: brainhull-1.7.tgz

tar -xzvf brainhull-1.7.tgz
cd brainhull
make
make install

Brainhull uses the Python package numpy, so you will also need to install that (or have it installed). It can be found here: http://numpy.scipy.org/. See also Installing Python Modules.

Usage

First, the structural scan must be imported into AFNI. This is done in the usual way using to3d (often in a separate directory per subject, in which case it's OK to just use the names as given here):

to3d -prefix anat *.dcm

or similar. Next, the fiducial landmarks must be identified and marked. Note that it is very important to be as accurate as possible at this point, to get a good coregistration. If you need to change the registration later, you have to re-do all the following steps. The fiddist program is quite useful for getting this part right.

Run AFNI and open the dataset created above:

afni -dset anat+orig

Open Axial, Sagittal, and Coronal views. Next, access the Tagset Editor, via Define Datamode → Plugins → Edit Tagset. Three tags must be created; the easiest way to create them is to read in the null.tag file from the brainhull library. Do this by entering the full pathname of the null.tag file into the Tag File field (usually, this will be something like '/usr/local/lib/brainhull/null.tag') and clicking the Read button. To find the directory containing the null.tag file, use the command brainhull -p. The three tags are called "Nasion", "Left Ear", and "Right Ear". Select each tag in turn by clicking its label, then use the mouse and/or cursor keys to locate the correct voxel, and press the Set button.

Once all three tags have been set, click the "Save" button to save them in the dataset.

Next, the dataset must be reoriented, so that the three fiducials are all in the same plane, and also resampled to 256-cubed with uniform voxels. The easiest way to do this is to use the 3dTagalign program with a master dataset that is already in the correct format:

libdir=`brainhull -p`
3dTagalign -prefix ./ortho -master $libdir/master+orig anat+orig

The master+orig dataset is supplied with this distribution. The ./ is necessary to prevent AFNI from writing the result into the same directory as the master.

In order to allow the orthogonalized dataset to be Talairached, you must add the anatomical markers to the header with:

3drefit -markers ortho+orig

Note that the above step is not necessary if you are using automatic Talairaching.

The next step is to prepare a mask defining the volume conductor, used for forward modelling of the MEG signals. The mask may be either the brain shape, the headshape, or some other roughly brain-shaped region. The mask will be converted into a convex hull. There are many programs available for extracting these shapes; in particular you might want to try extracting the inner skull surface, using FreeSurfer for example. Here we only consider using AFNI to create mask datasets.

To create a mask from an extracted brain, try:

3dSkullStrip -input ortho+orig -prefix mask -mask_vol -no_avoid_eyes

3dSkullStrip has many options for controlling the extraction process, however, because the ultimate goal here is simply a rough mask, anything that covers most of the brain will do. Small gaps and holes will be filled in by the hull. If things don't look right, try adding -shrink_fac .55 and/or -ld 30. Also, read the help message for 3dSkullStrip.

Note that the default behavior of 3dSkullStrip is to create a volume containing the masked brain. If you have the mask from the step above, you can create the masked brain this way:

3dcalc -a ortho+orig -b mask+orig -prefix brain -expr 'a * step(b - 2.9)'

This volume is useful with overlays, but it is a little smaller than the full mask, which contains some extra edge voxels. It's better to use the mask to compute the hull, since it's closer to the inner skull surface. The mask can also be used to clean up SAM volumes.

Next, create the hull from the mask:

brainhull mask+orig > hull

Finally, the hull must be converted to a "shape" file, using:

hull2fid ortho+orig hull ortho

In general, the first argument must be the "orthogonalized" brik (output of 3dTagalign), since it contains the fiducial tags, while the masks don't. The second argument is the hull, and the third argument is the "shape" file prefix. The output files will be called, in this example, ortho.shape and ortho.shape_info.

The above steps can be combined into a single script, usually called orthohull. The @auto_tlrc command (see below) is included here as well:

#! /bin/sh

libdir=`brainhull -p`

3dTagalign -prefix ./ortho -master $libdir/master+orig anat+orig
3dSkullStrip -input ortho+orig -prefix mask -mask_vol -no_avoid_eyes
3dcalc -a ortho+orig -b mask+orig -prefix brain -expr 'a * step(b - 2.9)'
brainhull mask+orig > hull
hull2fid ortho+orig hull ortho
@auto_tlrc -base TT_N27+tlrc -input ortho+orig -pad_base 60 -no_avoid_eyes

To visualize the hull, you can use SUMA (this step is optional):

hull2suma hull
suma -novolreg -spec hull.spec &
afni -niml -dset ortho+orig

Note that hull2suma uses relative filenames for the vertex, triangle, and surface volume files, so the hull.spec file can only be used in the current directory. hull2suma also defaults the ortho BRIK to "ortho+orig"; if that's not true you can specify the correct name as the second argument. Refer to the documentation for SUMA.

Creating Multisphere Models

A multisphere model for a CTF dataset may now be created using:

localSpheres -d $ds -s $mri/ortho.shape -M -v

It is sometimes necessary to use the -r argument to localSpheres, see localSpheres -help for more information. As a rough guide to determining the quality of the multisphere model, the checkSpheres program prints a few statistics about the spheres.

checkSpheres $ds

If you used a brainshape mask, you'll need to inflate the multisphere model.

inflateSpheres $ds

You must create a Multisphere model using localSpheres (and inflateSpheres, if you used the brain shape) for every MEG dataset you wish to analyze using SAM.

Talairach Space

AFNI has an automatic Talairach warping procedure based on 3dSkullStrip and a template. You'll need to download the template yourself if it isn't already installed. Then try

@auto_tlrc -base TT_N27+tlrc -input ortho+orig -pad_base 60 -no_avoid_eyes

or, since you've already stripped the skull, you can start with the masked brain (see above),

@auto_tlrc -base TT_N27+tlrc -input brain+orig -no_ss

If you use this, adwarp can't currently be used to warp SAM volumes, you'll have to use @auto_tlrc (usage 2). See GroupAnalysis.

Q & A

Q Does the headshape file need to be a good fit, matching all the sulci and gyri, or just cover the brain completely and, ideally, be smooth?

A CTF has recommended that the shape be smooth, to facilitate better sphere fits. When using a brain shape, a smooth envelope will more closely approximate the inner skull surface, which Dr. Robinson says is the ideal.

Q Does inflating the spheres affect the magnetic field calculation?

A No. The radius of the sphere isn't used in the forward calculation, only the distance of the sensor to the center of the sphere.

 
view · edit · attach · print · history · recent changes
Page last modified on February 28, 2008, at 12:39 PM
 
Department of Health and Human Services image and link First Gov image and link