Example Box: Brain Masks


The aim of this example is to see how to create and use binary brain masks.

This example is based on tools available in FSL, and the file names and instructions are specific to FSL. However, similar analyses can be performed using other neuroimaging software packages.

Please download the dataset for this example here:

Data download

The dataset you downloaded contains three images:

Viewing the Data

To start with load the original image into a viewer (e.g. fsleyes) and inspect the image. Then load the brain extracted image (T1_brain.nii.gz) and the brain mask (T1_brain_mask.nii.gz). Note that the brain extracted image shows contrast in the intensities between tissues whereas the brain mask shows no features inside the mask (as it only contains values of one).

Using the Brain Mask

The brain mask is useful as it can be used to regenerate the brain extracted image from the original. This can be done with FSL using the following command (executed from a terminal, after changing into the appropriate directory):

fslmaths T1 -mul T1_brain_mask T1_new_brain

This creates a new version of the brain extracted image (T1_new_brain) by multiplying the original image (T1) and the brain mask (T1_brain_mask). Load this into a viewer and check that it worked.

Such a process is useful as an alternative method of brain extraction since brain masks can be generated from other images (e.g., a T2-weighted image) and transformed between spaces, which is especially useful when edges of some brain tissues are clearer in one image modality.

Generating the Brain Mask

It is also possible to do the opposite and generate the brain mask from the brain extracted image. This takes all the non-zero voxels in the brain extracted image and sets then to a value of one, which is known as binarization. The command to do this with FSL is:

fslmaths T1_brain -bin T1_new_brain_mask

This creates a new version of the brain mask (T1_new_brain_mask) by binarization. Load the result into a viewer and check that it worked.

The above demonstrates how the brain extracted image and the brain mask image contain the same information, since either can be generated using the other (and the original image). Hence you may only see one of these images in the results from a pipeline, but at some point the vast majority of pipelines will generate a brain mask in order to restrict the analysis to just the brain voxels.