Converting Cortical Labels From FreeSurfer to Volumetric Masks

Note from February 2015: The methods in this guide work but do not necessarily represent current or best practice. My methods have changed over the years. I’ll try to go and update all my guides but I might never get around to it. Feel free to contact me for specific questions. For example, there is potentially¬†a better way to pull out cortical labels than what is contained in the following guide. If a label is put into an annotation file (.annot) – using the mris_label2annot Freesurfer tool – then mri_aparc2aseg could be used to create a well-filled in label segmentation. Also, I don’t generally extract labels in rawavg (scanner native) space anymore, preferring to stay in Freesurfer’s ‘native’ conformed (interpolated) space. However, the guide below is valid and can serve as a starting point for figuring out the tools and methods.

————————————

Suppose you ran recon-all (the main command in¬†FreeSurfer for automated processing) on a number of participants’ MRIs and now wanted to convert one or more of the cortical¬†parcellation areas to a volumetric mask for manual cleaning of the structure or for use as an ROI in diffusion fiber tracking, for example. Here is a picture of what the rendering of the cortical parcellation of the right hemisphere of my brain looks like. Just as an example, if you wanted to convert the entorhinal cortex to a volumetric mask in native MRI space, there are a number of commands you will need to run using Terminal.

The first command is part of FreeSurfer; it is a program called mri_annotation2label. In order to run this program, you should first create a “labels” folder within each subject’s directory (wherever your FreeSurfer subject’s directory resides. On my computer it is in /Applications/freesurfer/subjects). You can name this whatever you want to but I find it helpful to call it “labels”. Note: there is a “label” folder so do not confuse the two.

After this “labels” folder is created, you are ready to convert the (cortical) annotation file to a number of .label files (you can do only one if you want to but as they do not take up much space, I find it useful just to convert all the cortical areas to .label files).

Important note: all the following commands have a double dash before the options “- -” (without a space). However, your browser might render it as a single dash. It is a double dash!

Run the following command for each hemisphere you want (the “\” means it should be only one line in Terminal):

mri_annotation2label –subject ${blindnum} –hemi lh –outdir \ /Applications/freesurfer/subjects/${blindnum}/labels

After the –subject option you put the subject you want to load. With the –hemi option you specify which hemisphere (the left and right are done separately). With –outdir you specify in what directory you want to save the .label files (this might change depending on where you want to save your labels). In any case, the directory must already exist.

Here is a sample output from running that command:

Now you want to create a file that you can use to transform those labels into native space (or whatever imaging space you want to). To do this you run the following command (with appropriate changes made for your data: –mov is the input file, –noedit suppresses the tkregister GUI {this means the command just runs without showing a screen you do not need to see for this conversion}, –s is the input subject –regheader reads the header from the input, and –reg creates a registration matrix file):

tkregister2 –mov /Applications/freesurfer/subjects/${blindnum}/mri/rawavg.mgz –noedit –s \ ${blindnum} –regheader –reg ./register.dat

Now for each label file you want to convert you should run a command like this (this is set up to run from within a subject’s labels directory and to convert the entorhinal cortex; again, the “\” denotes no line break):

mri_label2vol –label ./lh.entorhinal.label –temp \ /Applications/freesurfer/subjects/${blindnum}/mri/rawavg.mgz –subject ${blindnum} –hemi lh –o \${blindnum}_lh_entorhinal.nii.gz –proj frac 0 1 .1 –fillthresh .3 –reg ../mri/register.dat

I won’t explain all of the options here; you can read more about the mri_label2vol command here. If that does not produce good results, play around with some of the fill thresholds or other options.

Now let’s check the result. Change back into the subject’s FreeSurfer mri directory (e.g., cd /Applications/freesurfer/{subject}/mri).

Within this directory, convert the rawavg.mgz (or original T1 or whatever you used as reference) file to a NIfTI file:

mri_convert rawavg.mgz rawavg.nii.gz

I like to load this file in ITK-SNAP, which is my preferred visualization and editing program.

There you have the left entorhinal cortex (if you believe this automatic parcellation is accurate and valid) as a volumetric mask file in native scanner space!

About Jared Tanner

I have a PhD in Clinical and Health Psychology with an emphasis in neuropsychology at the University of Florida. I previously studied at Brigham Young University. I am currently a Research Assistant Professor at the University of Florida. I spend the bulk of my research time dealing with structural magnetic resonance images of the brain. My specialty is with traditional structural MR images, such as T1-weighted and T2-weighted images, as well as diffusion weighted images. I also look at the cognitive and behavioral functioning of individuals with PD and older adults undergoing orthopedic surgery. Funding for the images came from NINDS K23NS060660 (awarded to Catherine Price, University of Florida). Brain images may not be used without my written permission (grant and software requirements).