Introduction

Recently, I have been investigating different methodologies for creating anatomical masks for fMRI data analysis. Several techniques exist within the neuroimaging literature for segmenting the brain. Techniques for segmenting my region of interest (namely, the nuclei of the thalamus) shall be described briefly in this post, and I will also explain in more detail how I have created my anatomical masks using Freesurfer. However, before you turn away for lack of interest in thalamic nuclei, I would like to reassure you that Freesurfer can segment much more than the nuclei of the thalamus1Freesurfer can create anatomical segmentations for cortical and subcortical brain regions. Freesurfer also can segment hippocampal subfields, amygdala nuclei, and brainstem structures. Therefore, I encourage you to read on to discover the superpowers that Freesurfer possesses.

Thalamic segmentation

Located in the forebrain, the thalamus is a grey matter structure that has several functions. This includes being a relay for information between cortical and subcortical brain regions. The nuclei of the thalamus receive projections from and can project to distinct regions and neuronal subtypes within the cortex and subcortex. Therefore, neuroscientists need to understand how the afferent and efferent connectivity of the thalamus makes distinct contributions to neuronal activity. Nevertheless, it is not uncommon that the activity of the thalamus as a whole is reported in human neuroimaging literature, rather than the activation specific nuclei. This indifference towards specificity may be due, in part, to the fact that the nuclei of the thalamus are often small in size and cannot be delineated easily. Therefore, drawing meaningful conclusions regarding thalamic activity can be difficult if one does not have a clear a priori hypothesis. For those with a specific interest in nuclei of the thalamus, there are multiple methods for segmenting the nuclei of the thalamus. These methods include using machine learning, clustering of diffusion-weighted images, independent component analysis, applying a 7T atlas to 3T, and creating probabilistic atlases using Bayesian inference. This last method, developed by Iglesias and colleagues2Iglesias, J. E., Insausti, R., Lerma-Usabiaga, G., Bocchetta, M., Van Leemput, K., Greve, D. N., van der Kouwe, A., Alzheimer’s Disease Neuroimaging Initiative, Fischl, B., Caballero-Gaudes, C., & Paz-Alonso, P. M. (2018). A probabilistic atlas of the human thalamic nuclei combining ex vivo MRI and histology. NeuroImage183, 314–326. https://doi.org/10.1016/j.neuroimage.2018.08.012 shall be the focus of the remainder of this post3This guide is easily adaptable to other anatomical segmentations in Freesurfer, as the general principles are the same.

Creating anatomical masks using Freesurfer

DISCLAIMER: Within this section, I shall include links to my GitHub repository containing the scripts that I have used for my analysis. I include this in the hope that it will be a useful starting point/supplementary material for those wish to run a similar analysis, however, I do not plan to respond to specific requests concerning debugging code.

Before you can start to create your anatomical masks, the first step you need to run is the recon-all function within Freesurfer. Recon-all will execute several processing steps on your structural data, and more information can be found within the recon-all documentation. To create anatomical masks, we are most interested in the cortical parcellation, and subcortical segmentation steps (which will be used later to segment the thalamic nuclei). For example, to run recon-all for a participant with the ID “ppt1”, you would use the following command:

 

recon-all -subject ppt1 -i ppt1_struct.nii.gz -all -cm

 

The -subject flag will tell Freesurfer the ID that you would like the participant directory to have within the default Freesurfer subject directory (or $SUBJECTS_DIR if you define a specific directory); the -i flag tells Freesurfer where the anatomical file for ppt1 can be found; the -all flag tells Freesurfer to run all steps of recon-all; the -cm flag is useful to include if your structural voxel resolution is sub 1mm isotropic. The recon-all command will take a while to run, it took around 6 hours for me but this will depend on your hardware and if you chose to run all the steps. Once recon-all is complete, you can then use the thalamic nuclei tool to segment the thalamus4This is available in Freesurfer 6 and 7. To run the thalamic nuclei tool, you will need to tell Freesurfer which subject directory you would like to run segmentation on. For example, to segment the thalamus for ppt1, you would use the following command5The reliability of the segmentation algorithm can be improved by including an additional scan, such as a Fast Gray Matter Acquisition T1 Inversion Recovery scan, which has greater thalamic contrast than T1-w MP-RAGE or T2-w FLAIR scans (Sudhyadhom et al., 2009) :

 

segmentThalamicNuclei.sh ppt1

 

After the thalamic segmentation tool is complete, you can inspect your anatomical segmentations for the cortex, thalamic nuclei, and other subcortical brain regions. Within each subject’s subdirectory of the Freesurfer subject directory, there is a directory called mri. Within the mri directory, you will find several files including those containing your segmentations. Freesurfer contains two atlases for cortical segmentation that are created as part of recon-all, namely the Desikan-Killiany atlas and the Destrieux atlas. More information regarding these atlases can be found in the Freesurfer documentation and the regions they include in the Freesurfer Color Lookup Table. You will also get three files from the thalamic segmentation tool. More information can be found within the documentation. To create functional space masks from your anatomical segmentation, you will need to use the output file “ThalamicNuclei.v10.T1.FSvoxelSpace.mgz” as this will contain the segmentations in voxel space. This will be 1mm isotropic unless you include the -cm flag, then the segmentation voxel size will be the same as your anatomical image if it is sub 1mm isotropic.

 

Before you can extract your anatomical mask, you will first need to convert your segmentation from Freesurfer space to native anatomical space6An mgz volume typically has the dimensions 1mm isotropic, 256,256,256, even if the nifti file that is used as input has different dimensions. For example, to convert the thalamic segmentation, you would use the following command:

 

mri_label2vol –seg ThalamicNuclei.v10.T1.FSvoxelSpace.mgz –temp rawavg.mgz –regheader ThalamicNuclei.v10.T1.FSvoxelSpace.mgz –o ThalamicNuclei.v10.T1-anat.mgz

 

The –seg flag tells Freesurfer the segmentation to convert to native anatomical space; the –temp flag tells Freesurfer which image to use as a template for the geometry of the output; the –regheader flag tells Freesurfer which segmentation to use as the header for the output segmentation, and the –o flag defines the output file. To extract the anatomical binary mask for your region of interest, you will need to use the mri_binarize function in Freesurfer. For example, to extract the segmentation of the left centromedian nucleus of the thalamus, you would use the following command:

 

mri_binarize –i ThalamicNuclei.v10.T1.FSvoxelSpace-anat.mgz –o Left-CM.mgz –match 8106

 

The –i flag tells Freesurfer the input file; the –o flag tells Freesurfer the output filename; the –match flag tells Freesurfer the code in the Freesurfer Color Lookup Table for your anatomical segmentation of choice that will be used to create a binary mask from the input image. After you have created your mask, you may want to convert it from the .mgz file type to .nii(.gz) if you wish to use your segmentation in other software, such as FSL or SPM. To do this, you can use the Freesurfer function mri_convert. For example, to convert the Left-CM mask from the above example, you would use the following command:

 

mri_convert –in_type mgz –out_type nii Left-CM.mgz Left-CM.nii.gz

 

The –in_type –out_type flags let Freesurfer know the file type for the input and output image, respectively. Then the input and output file for mri_convert are defined.

Using your masks in FSL

You should now have a binarised mask for your region of interest in anatomical space with the correct dimensions and orientation. To convert your mask from anatomical space to functional space7Or another space, for example, diffusion space or standard space in FSL, you can use the affine transformations that are included in the FLIRT preprocessing directory8Alternatively, if you would like a non-linear transformation, you can apply a warp field (ending _warp.nii.gz) using the function applywarp. For example, to transform the Left-CM mask from anatomical space to functional space using an affine transformation, you would use the following command:

 

flirt -in Left-CM.nii.gz -ref example_func.nii.gz -out Left-CM_func.nii.gz -init highres2example_func.mat -applyxfm

 

The -in flag tells FSL the input file; the -ref flag tells FSL the template image of the space that you want to transform your mask into; the -out flag tells FSL the output file; -init file flag tells FSL which affine transformation should be applied to the input image; the -applyxfm flag tells FSL that you would like to apply a saved transformation. Now you should have your anatomical masks in functional space. However, you will need to binarise your masks again before you can use them. To do this you can use the FSL function fslmaths.

 

fslmaths Left-CM_func.nii.gz -thr 0.5 -bin Left-CM_func_binary.nii.gz

 

First, you need to tell FSL your input file; the -thr flag defines the minimum threshold value for voxels that will be included in the binarised mask; the -bin flag defines the binary file that FSL will create. Now you should have a binarised mask for your region of interest in functional space that you can now use for further analysis. You could use your mask to extract the average time series for your region of interest9For example, this can be used as a seed for PPI, restrict your analysis to a region of interest, combine your region of interest with other masks, or anything else you can think of!

 

Thank you for taking the time to read this post, I hope you have found it useful. If you have, why not share it with a friend or colleague? Also, if you create your own anatomical segmentations in Freesurfer, let me know in the comments below!

Footnotes:

  1. Freesurfer can create anatomical segmentations for cortical and subcortical brain regions. Freesurfer also can segment hippocampal subfields, amygdala nuclei, and brainstem structures
  2. Iglesias, J. E., Insausti, R., Lerma-Usabiaga, G., Bocchetta, M., Van Leemput, K., Greve, D. N., van der Kouwe, A., Alzheimer’s Disease Neuroimaging Initiative, Fischl, B., Caballero-Gaudes, C., & Paz-Alonso, P. M. (2018). A probabilistic atlas of the human thalamic nuclei combining ex vivo MRI and histology. NeuroImage183, 314–326. https://doi.org/10.1016/j.neuroimage.2018.08.012
  3. This guide is easily adaptable to other anatomical segmentations in Freesurfer, as the general principles are the same
  4. This is available in Freesurfer 6 and 7
  5. The reliability of the segmentation algorithm can be improved by including an additional scan, such as a Fast Gray Matter Acquisition T1 Inversion Recovery scan, which has greater thalamic contrast than T1-w MP-RAGE or T2-w FLAIR scans (Sudhyadhom et al., 2009)
  6. An mgz volume typically has the dimensions 1mm isotropic, 256,256,256, even if the nifti file that is used as input has different dimensions
  7. Or another space, for example, diffusion space or standard space
  8. Alternatively, if you would like a non-linear transformation, you can apply a warp field (ending _warp.nii.gz) using the function applywarp
  9. For example, this can be used as a seed for PPI

Leave a Reply

Your email address will not be published. Required fields are marked *

Post comment