Using FreeSurfer

Authors: Francois Tadel

The open-source software FreeSurfer can be used to extract the cortical envelope from a T1/T2 MRI and register it to an atlas. The process is fully automatic and the results can be imported in Brainstorm with just a few mouse clicks. If you are using FreeSurfer, please register on their website (registration page) and cite the appropriate references. Note that this software is available only for Linux and MacOS.

Run FreeSurfer manually

  1. Downloading and installing FreeSurfer is easy but long (several Gb). Two options: you have a Linux system and you want to install FreeSurfer, or you don't and you want to run FreeSurfer in a Linux virtual machine. Just follow the instructions:

  2. Set up the FreeSurfer in a csh/tcsh environment: run the following lines, or add them at the end of your $HOME/.cshrc script for permanent change. If you're not sure what csh is: type "echo $SHELL" to know what is the name of the shell that you use. If it says "/bin/tcsh" or "/bin/csh", this is for you.

    setenv FREESURFER_HOME /.../local/freesurfer
    setenv SUBJECTS_DIR /.../data/freesurfer/subjects
    setenv FUNCTIONALS_DIR /.../data/freesurfer/sessions
    source /.../local/freesurfer/FreeSurferEnv.csh
  3. Set up the FreeSurfer environment in a bash environment (add these lines at the end of your $HOME/.bashrc script):

    export FREESURFER_HOME=/.../local/freesurfer
    export SUBJECTS_DIR=/.../data/ftadel/freesurfer
    export FUNCTIONALS_DIR=/.../data/ftadel/freesurfer
    source $FREESURFER_HOME/
  4. Run the reconstruction (6-12 hours):
    recon-all -i <mri_file> -subjid <subject_id>
    recon-all -all -subjid <subject_id>
  5. Contralateral registration: Computes the registration of each hemisphere to the contralateral atlas, which later allows projecting scouts between hemispheres, but adds about one hour of computation. More information

    FreeSurfer 6.x: Add the option -contrasurfreg to the recon-all command line.

    recon-all -all -contrasurfreg -subjid <subject_id>

    FreeSurfer 7.x: The option -contrasurfreg was removed for unknown reasons. Execute manually the following commands after recon-all:

    mris_register -curv -reverse $SUBJECTS_DIR/<subject_id>/surf/lh.sphere $FREESURFER_HOME/average/rh.folding.atlas.acfb40.noaparc.i12.2016-08-02.tif $SUBJECTS_DIR/<subject_id>/surf/lh.rh.sphere.reg
    mris_register -curv -reverse $SUBJECTS_DIR/<subject_id>/surf/rh.sphere $FREESURFER_HOME/average/lh.folding.atlas.acfb40.noaparc.i12.2016-08-02.tif $SUBJECTS_DIR/<subject_id>/surf/rh.lh.sphere.reg
  6. If you have an additional T2 or FLAIR image, you can improve the cortex reconstruction:

  7. Additional volume or surface parcellations can be computed at this stage. For details see section Cortical parcellations below.

  8. Done. Everything is ready to be imported in Brainstorm. Because the process may occasionally fail, always check visually the final surfaces. The FreeSurfer wiki suggests that you check all the steps with FreeSurfer. We suggest instead that you load it all in Brainstorm and go back to the manual checking/editing only if it looks bad.

  9. More instructions for setting up the environment and tuning the reconstruction here:

Run FreeSurfer from Brainstorm

Alternatively, it is possible to call the FreeSurfer recon-all pipeline from Brainstorm.

Import the results in Brainstorm

  1. Switch to the anatomy view of the database explore.
  2. Create a new subject, set the default anatomy option to "No, use individual anatomy".
  3. Right-click on the subject > Import anatomy folder.


    • Import anatomy folder: Interactive import: asks for the number of vertices expected in the final cortex surfaces and for the location of the fiducials NAS/LPA/RPA. Select this option in the case of an MEG study, when you know exactly where the fiducials were digitized during the MEG acquisition. See tutorial MRI registration.

    • Import anatomy folder (auto): Automatic import: Computes the linear MNI normalization, uses default positions from the MNI atlas for the NAS/LPA/RPA fiducials, and uses 15000 vertices for the cortex downsampled surfaces.

  4. Select one of the FreeSurfer import options and select the top folder of your subject <subject_id> (/.../data/freesurfer/subjects/subject_id)

    • FreeSurfer: Import the T1 MRI, pial and white cortex surfaces, surface parcellations, surface spherical registration, ASEG surface parcellation. Reconstruct the head surface.

    • FreeSurfer + Volume atlas: Same as above, with the following additions: Import the volume parcellations available in the mri subfolder; reconstruct the mid surfaces (intermediate between the pial and white surfaces).

    • FreeSurfer + Volume atlas + Thickness: Same as above, with the cortical thickness maps imported as source maps.

  5. Manual import: You're prompted for the number of vertices you want in the final cortex surface. This will by extension define the number of dipoles to estimate during the source estimation process. By default we set this value to 15000 for the entire brain (it means 7500 for each hemisphere).


  6. Manual import: The MRI Viewer appears for you to define the anatomical fiducials. See tutorial Import anatomy. Click on Save to keep your modifications, and the import will continue.


  7. A figure is automatically shown at the end of the process, to check visually that the low-resolution cortex and head surfaces were properly generated and imported. If it doesn't look like the following picture, do not go any further in your source analysis, fix the anatomy first.


Files imported

The files that are imported from the subject_id folder are the following:

The successive steps that are performed by Brainstorm:

The files you can see in the database explorer at the end (with Volume atlases + Thickness):

Handling errors

How to check the quality of the result

It's hard to estimate what would be a good cortical reconstruction. Try to spot the most obvious errors, e.g. when the early stages of the brain extraction didn't perform well. Play with the Smooth slider in the Surface tab. If it looks like a brain (two separate hemispheres) in both smooth and original views, it is probably OK.

Display the cortex surface on top of the MRI slices, to make sure that they are well aligned, that the surface follows well the folds, and that left and right were not flipped: right-click on the low-resolution cortex > MRI registration > Check MRI/surface registration...


The cortex looks bad

It is critical to get a good cortex surface for source estimation. If the final cortex surface looks bad, it means that something didn't work well somewhere along the FreeSurfer pipeline. You can refer to the following page to fix the problems manually:

If after following these instructions you still don't manage to get good surfaces, you can try to run the automatic MRI segmentation from CAT12, BrainSuite or BrainVISA.

The head surface looks bad

It is not mandatory to have a perfect head surface to use many Brainstorm features. (For anonymity, it may actually be necessary to distort or obscure the face in figures.)

The head surface is important mainly for two reasons. First, for the alignment of the MEG sensors and the MRI, and second, for generating head models that incorporate the scalp surface (e.g. multi-layer BEM or FEM). If you digitized the head shape with a Polhemus device, you can automatically align the head surface (hence the MRI) with the MEG sensors (in the same referential as the Polhemus points). The quality of this automatic registration depends on the quality of both surfaces: the Polhemus head shape (green points) and the head surface from the MRI (grey surface). If you digitized lots of points on the nose but your head surface doesn't have a nose, these points are not going to help.

If the default head surface looks bad, you can try generating another one: right-click on the subject folder > Generate head surface. The options are:

Error in mne_read_surface.m

If you get an error message mentioning mne_read_surface.m, and the files pial.lh and pial.rh are only 2Kb, you probably had an issue with the transfer of symbolic links. See this forum post:

Cortical parcellations

The default analysis pipeline in FreeSurfer computes several parcellations of the cortical surface in anatomical regions. The description of this feature is available here:

With FreeSurfer 7, the following parcellations are always available:

Additional parcellations can be computed from FreeSurfer with mri_surf2surf (example):

These parcellations are imported in Brainstorm as scouts (cortical regions of interest). To access them from the interface: double-click on the cortex, go to the Scout tab, and click on the drop-down list to select another Atlas (ie group of scouts):


Desikan-Killiany atlas

Displayed respectively in: FreeSurfer, Brainstorm (high-resolution) and Brainstorm (15000 vertices)


Destrieux atlas

Displayed in Brainstorm with the original scouts colors (left) or classified in 6 regions (right): pre-frontal, frontal, central, parietal, temporal, occipital, occipital. You can switch between the two views with the button "Identify regions with colors" in the toolbar on the right of the scouts list.


The scouts are saved directly in the surface files. To check where they are saved: right-click on the low-resolution cortex file > File > View file contents. You can see that multiple "Atlas" structures are available, the first one that has Name='User scouts', and the second one Name='Brodmann'.


Volume parcellations

All the volume parcellations available in the mri subfolder are imported when the option "FreeSurfer + Volumes atlases" is selected. This includes:


Subcortical structures: aseg atlas

The file aseg.mgz contains a volume atlas of 40 subcortical regions. Brainstorm reads these volume labels and tesselates some of these regions, groups all the meshes in a large surface file where the regions are identified in an atlas called "Structures". It identifies: 8 bialateral structures (accumbens, amygdala, caudate, hippocampus, pallidum, putamen, thalamus, cerebellum) and 1 central structure (brainstem).

You can easily extract one structure (for example the brainstem or the cerebellum) by selecting the corresponding entries in the scouts list and selecting the menu Scout > Edit surface > Keep only selected scouts. It creates a new surface with only the selected regions. If you want to remove one or several structures, use the menu "Remove selected scouts" instead. More information.

Read more about the FreeSurfer subcortical atlas on the software wiki:


Registered spheres

The registered spheres are saved in each surface file in the field Reg.Sphere.Vertices. There is nothing that can be done with this information at this point, but it will become helpful when projecting the source results from the individual brains to the default anatomy of the protocol, for a group analysis of the results: Subject coregistration.

Read more about the FreeSurfer registration process on the software wiki:

Contralateral registration

When computing the contralateral registration (see instructions above), two additional files are generated in the FreeSurfer subject folder: surf/lh.rh.sphere.reg and surf/rh.lh.sphere.reg. These files define FreeSurfer spheres that register each hemisphere to the contralateral atlas, and therefore allow interpolating information from one hemisphere to the other. This is needed for projecting scouts between hemispheres, as done by the Scout tab menu Project to: Contralateral hemisphere.

When these extra files are available in the FreeSurfer subject folder, they are imported automatically in the cortex surface (field Reg.SphereLR). But note that this option is not part of the standard recon-all pipeline and the contralateral spheres must be computed manually.

Read more about the FreeSurfer 6.x option -contrasurfreg on the software wiki:


Mollweide projection

The FreeSurfer registered spheres can be used to compute a flat 2D projection of the cortex surface using the Mollweide projection, as described in this article: (Kang et al. 2019) Hemispherically-Unified Surface Maps of Human Cerebral Cortex: Reliability and Hemispheric Asymmetries.

Cortical thickness

The cortical thickness can be saved as a cortical map in the database (a "results" file). This result is generated when using the file format "FreeSurfer folder + Thickness maps" in the Import anatomy folder selection.


FSAverage template

Instead of the MNI ICBM152 brain, you can use the FreeSurfer average subject "FSAverage" as your default anatomy in Brainstorm. This template is an average of 40 subjects using a spherical averaging described in (Fischl et al. 1999).

To change the default, right-click on "(Default anatomy)" > Use template > FSAverage. If it is not available on your computer yet, it will be automatically downloaded from the server to your user folder: $HOME/.brainstorm/templates/anatomy. See tutorial: Using the anatomy templates.

If you are using the FSAverage template but not a regular user of FreeSurfer, please register on their website: registration page.


Running the folder import as a process

You can import the FreeSurfer folders from scripts, but you have to provide manually the position for all the fiducial points: process Import > Import anatomy > Import anatomy folder.

The corresponding process function is: brainstorm3/toolbox/process/functions/process_import_anatomy.m


Manual import of the anatomy

In case you need to import the MRI, surfaces and atlases separately instead of using the menu "Import anatomy folder", here is the sequence of operations to perform to get to the same result:

  1. From the Anatomy side of the database explorer: create a subject.

  2. Right-click on the subject folder > Import MRI > Select "mri/T1.mgz".

  3. Set the 6 fiducial points, or click on "Compute MNI normalization" (option maff8). Save.
  4. Right-click on the subject folder > Import surfaces > Select the FreeSurfer file format > Select simultaneously from the "surf" folder: lh.pial, lh.white, rh.pial, rh.white. Question "Apply transformation?": NO.

  5. Double-click on lh.pial to display it. In the scout tab: Atlas > Load atlas > select all the lh.*.annot files available in the label folder. Close the figure.

  6. Repeat for the other surfaces: lh.white, rh.pial, rh.white
  7. Right-click on lh.pial > MRI registration > Load FreeSurfer sphere > Select "surf/lh.sphere.reg"

  8. Repeat with the other surfaces (use rh.sphere.reg for the right hemisphere, white and pial surfaces)
  9. Select all the surfaces, right-click > Less vertices > 7500 vertices > Select the first option "Matlab reducepatch"

  10. Select lh.pial + rh.pial, right-click > Merge surfaces: Generates a surface cortex_300000V

  11. Select lh.white + rh.white, right-click > Merge surfaces: Generates a surface white_300000V

  12. Select lh.pial_7500V, rh.pial_7500V, right-click > Merge surfaces: Generates a surface cortex_15000V

  13. Select lh.white_7500V, rh.white_7500V, right-click > Merge surfaces: Generates a surface white_15000V

  14. Delete all the separate hemispheres: ?h.pial, ?h.white
  15. Double-click on cortex_15000V to set it as the default cortex
  16. Right-click on the subject folder > Import surfaces > Select the file format "Volume mask or atlas (subject space)" > Select the file mri/aseg.mgz. Question "Apply transformation?": NO.

  17. Right-click on the subject folder > Import MRI > Select the file format "Volume atlas (subject space)" > Select all the files mri/*aseg.mgz.

    • Question "Apply standard transformation?": NO
    • Question "Apply transformation?": YES
    • Question "How to register?": Ignore
    • Question "Reslice volume?": No
  18. Go to the functional view of the protocol, create a folder "FreeSurfer". Leave your mouse for a second over the new folder, an note the study index (iStudy).

  19. From the Matlab command window, you can import the thickness maps with the following call:
    • ThickFile = import_sources(iStudy, CortexHiFile, ThickLhFile, ThickRhFile, 'FS');

    • CortexHiFile = full path to the high-res cortex file (right-click > File > Copy file path to clipboard)

    • ThickLhFile = full path to the surf/lh.thickness file

    • ThickRhFile = full path to the surf/rh.thickness file

Additional documentation

Feedback: Comments, bug reports, suggestions, questions
Email address (if you expect an answer):

Tutorials/LabelFreeSurfer (last edited 2022-11-28 11:41:32 by FrancoisTadel)