In a previous post I wrote about converting FreeSurfer aseg (sub-cortical segmentation) labels to volumetric masks. I demonstrated a graphical way of pulling out individual labels; however, it can be fairly tedious. There are around 50 different labels in the aseg file so sorting through them can take a while. There is a much faster – and scriptable – method for pulling out individual labels as ROIs.
Let’s assume that you know the numbers of the labels you want, for this example I’ll pull out the left caudate, which is label 11 in aseg. The commands assume you have FSL installed (as well as FreeSurfer).
We’ll use the program fslmaths, which is a very general image calculator.
First you will need an aseg file as a NIfTI.
Navigate to your FreeSurfer subjects directory:
cd $FREESURFER_HOME/subjects/
Then navigate to the participant’s mri directory you want
cd s001/mri
Then run: mri_convert aseg.mgz aseg.nii.gz
Alternatively, you can simply create the aseg NIfTI file by typing in the full paths to the input and output files when running mri_convert
For example: mri_convert $FREESURFER_HOME/subjects/s001/mri/aseg.mgz /[path to working directory]/aseg.nii.gz
However, that aseg file is in FreeSurfer space. If you want it in T1 native space (or some other space, diffusion for example) you could run something like this:
mri_convert -rl $FREESURFER_HOME/subjects/s001/mri/rawavg.mgz -rt nearest $FREESURFER_HOME/subjects/s001/mri/aseg.mgz /[path to working directory/s001_aseg2raw.nii.gz
Now you are ready to pull out the appropriate ROI(s) - this example gives you the left caudate (in native T1 space).
fslmaths /[path to aseg file]/s001_aseg2raw.nii.gz -uthr 11 -thr 11 /[path to working directory]/ROIS/l_caudate_freesurfer_rawavg.nii.gz
This runs this command with an upper (-uthr) and lower (-thr) threshold of 11 to zero out everything except the 11th label (the left caudate).
Then you can run fslmaths to turn the mask file into 0s and 1s (from its 0s and 11s in the case of the left caudate – modify this command as appropriate). The -div 11 option tells the program to divide the mask file (which is currently all 11s and 0s) by 11, which will result in a mask with just 0s and 1s. Some imaging programs do not like ROIs (binary masks) with values other than 0s and 1s:
fslmaths l_caudate_freesurfer_rawavg.nii.gz –div 11 l_caudate_freesurfer_rawavg.nii.gz
You don’t have to write over the mask file if you do not want to; feel free to create a new file just in case something goes wrong. You can delete any temp files later.
Here are screenshots of the whole process.
Related posts:



Pingback: Converting FreeSufer aseg Labels to Individual Volume Masks
Hi
I was wondering whether it’s possible to get the talairach coordinates associated with each label in the segmentation. I use BV, not FSL, and I would like to use Freesurfer’s segmentation for analysis (in Matlab). If I could somehow create a text file with the talairach coordinates of each label (or of a specific label, by label number), it would be great.
Thanks,
Aya
Yes, there are ways to do that. See for example: https://mail.nmr.mgh.harvard.edu/pipermail//freesurfer/2009-August/011672.html
You’d have to check through the FreeSurfer wikis or mailing list archives for more information but I know it’s possible, it’s just not something I’ve done before so I can’t give any specifics.
Hi,
I tried using the indices from the Freesurfer Color LUT to create a ROI not listed in aseg.stats. However, the ROI is coming up empty (no regions designated as 1s or white). If the index is listed in aseg.stats, the ROI comes out fine. Do you know how the Freesurfer LUT is used to determine which regions get segmented in aseg.mgz?
Thanks in advance,
Vy
Thanks for the question Vy. Are you creating a new ROI from scratch or did you combine aseg ROIs to make a new one?
Hi Jared,
This is a great tutorial and saved me a lot of work. Now that I have a mask for my ROI, I am trying to get a ascii list of coordinates for each voxel in my mask. How would you go about doing that?
Hi Jared,
I’m a little confused by the discussion of T1 native space…I’m using FS 4.5 and my T1.mgz file has the same dimensions as my aseg.mgz (256x256x256), which is different from the rawavg.mgz file (256x256x176). I’m actually a little unsure of what anyone means when they refer to the various kinds of spaces, and I haven’t been able to find a good explanation on the Freesurfer wiki. Are you aware of any resource that discusses the various spaces?