Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

FreeSurfer: recon-all-clinical

Run this notebook

This notebook was prepared for an audience of clinicians at the 2025 PACTALS conference (Pan-Asian consortium of Treatment and Research in ALS) in Melbourne.

Author: Thomas Shaw Date: 1 Sept 2025

thomshaw92

0000-0003-2490-0532

License:

MIT License

Note: If this notebook uses neuroimaging tools from Neurocontainers, those tools retain their original licenses. Please see Neurodesk citation guidelines for details.

Citations and Resources:

Tools included in this workflow

recon-all-clinical:

  • Karthik Gopinath, Douglas N. Greve, Colin Magdamo, Steve Arnold, Sudeshna Das, Oula Puonti, Juan Eugenio Iglesias, “Recon-all-clinical”: Cortical surface reconstruction and analysis of heterogeneous clinical brain MRI, Medical Image Analysis, Volume 103, 2025, 103608, ISSN 1361-8415, Gopinath et al. (2025).

Dataset:

T1 weighted MP2RAGE at 7T (healthy control)

  • Shaw TB, York A, Barth M, Bollmann S. Towards Optimising MRI Characterisation of Tissue (TOMCAT) Dataset including all Longitudinal Automatic Segmentation of Hippocampal Subfields (LASHiS) data. Data Brief. 2020 Jul 20;32:106043. doi: Shaw et al. (2020) PMID: 32793772; PMCID: PMC7415822.

General Instructions:

📘 How to Use This Notebook

This notebook is an interactive document. It mixes short explanations (like this box) with computer code that runs automatically.

  • 👆 Click on a cell (the boxes with text or code)

  • ▶️ Run it by pressing Command + Enter (Mac) or Control + Enter (Windows/Linux)

  • ⏭️ Or use the play button in the toolbar above

  • ⬇️ Move to the next cell and repeat


🧩 What happens when you run a cell?

The computer will either:

  • ✏️ Show you some text or figures

  • 🖥️ Run an analysis step in the background

  • 📂 Save results into a folder


💡 Tip: Always read the explanation above each code cell first – it tells you in plain words what the computer will do.

There are a few dataformats that are used in this tutorial:

  • Files that end in ‘.mgz’ and ‘nii.gz’ are volumetric images (either showing the brain or a specific region of the brain).

  • Files that end in ‘.stat’ are statistics files.

  • Files that end in .txt are just text-files.

  • Files that end in ‘.csv’ are datasheets.

  • Files that end in ‘.pial, .surf etc’ are surface files.

Load the module for this workbook

📦 What is a "Module"?

A module is just a way of telling the computer: “Please make this special software ready to use.”

  • 🎛️ We only load the ones we need, when we need them

  • 🔑 Loading a module is like unlocking the tool so we can use it


🚀 In this notebook

We will load FreeSurfer 8 – the software that analyses our scans. Once loaded, the commands will be available for us to run.

module load freesurfer/8.0.0

➡️ Just like before: click the cell, then press Command + Enter (Mac) or Control + Enter (Windows/Linux) to load it.

['freesurfer/8.0.0']

Let’s try running the command with the --help flag!

 
Recon-all-like stream for clinical scans of arbigrary orientation/resolution/contrast
 
Use this script to process clinical scans of arbitrary orientation, resolution, and 
contrast. It essentially runs a combination of:
* SynthSeg: to obtain a volumetric segmentation and linear registration to Talairach space
* SynthSR: to have a higher resolution 1mm MPRAGE for visualization
* SynthDist: to fit surfaces by predicting the distance maps and reconstructing topologically accurate cortical surfaces
 
Using this module is very simple: you just provide an input scan, the subject name, the
number of threads you want to use, and (optionally) the subjects directory:
 
   recon-all-clinical.sh INPUT_SCAN SUBJECT_ID THREADS [SUBJECT_DIR]
 
   (the argument [SUBJECT_DIR] is only necessary if the
    environment variable SUBJECTS_DIR has not been set
    or if you want to override it)
 
This stream runs a bit faster than the original recon-all, since the volumetric
segmentation is much faster than the iterative Bayesian method in the standard stream
 
If you use this stream for your analysis, please cite:
 
K Gopinath, DN Greeve, S Das, S Arnold, C Magdamo, JE Iglesias:
Cortical analysis of heterogeneous clinical brain MRI scans for large-scale neuroimaging studies
https://arxiv.org/abs/2305.01827
 
B Billot, DN Greve, O Puonti, A Thielscher, K Van Leemput, B Fischl, AV Dalca, JE Iglesias:
SynthSeg: Segmentation of brain MRI scans of any contrast and resolution without retraining
Medical Image Analysis, 83, 102789 (2023)
 
B Billot, C Magdamo, SE Arnold, S Das, JE Iglesias:
Robust machine learning segmentation for large-scale analysis of heterogeneous clinical brain MRI datasets
PNAS, 120(9), e2216399120 (2023)
 
SynthSR: a public AI tool to turn heterogeneous clinical brain scans into high-resolution T1-weighted images for 3D morphometry
JE Iglesias, B Billot, Y Balbastre, C Magdamo, S Arnold, S Das, B Edlow, D Alexander, P Golland, B Fischl
Science Advances, 9(5), eadd3607 (2023)
 

📥 Downloading the Data

We will now download a sample brain scan (called mp2rage.nii.gz) from the Open Science Framework.

  • 🌐 This file comes from an open research resource

  • 🧠 It is a standard type of MRI scan used for brain structure

  • 📂 We will use it today as our example dataset


➡️ Click the cell below, then press Command + Enter (Mac) or Control + Enter (Windows/Linux) to start the download.

Downloading File
usage: osf fetch [-h] [-f] [-U] remote [local]
osf fetch: error: Local file ./data/structural/mp2rage.nii.gz already exists, not overwriting.
./data/structural/mp2rage.nii.gz

🖼️ Viewing mp2rage.nii.gz

We will now open the mp2rage.nii.gz file. This is the patient’s T1-weighted MRI scan that FreeSurfer will change into its own format.

  • 🎛️ We display it in grayscale so brain tissue boundaries are clear

  • 📐 Brightness/contrast is automatically adjusted (ignores empty space and extreme values)

  • ➕ Crosshairs help you line up the same point across axial, coronal, and sagittal slices

  • 🧭 The viewer lets you scroll through slices and explore the brain interactively


➡️ Click the cell below, then press Command + Enter (Mac) or Control + Enter. This will open mp2rage.nii.gz in the interactive viewer.

[HF-patcher] mp2rage: path → url
Loading...

Run

🧠 Automated Brain Scan Processing using recon-all clinical

This step prepares our MRI data so it can be processed automatically. Think of it like setting up the folders and tools before we start the real analysis.

  • ✔️

    Creates a folder

    where results will be saved

  • ✔️

    Checks everything is ready

    before running

  • ✔️ Run the command "recon-all-clinical.sh"

In plain words: we are telling the computer:
"Here’s the scan. Put the results in this folder. Run the pipeline."

⚠️ Don’t worry about the code details – they’re just making sure the computer behaves!


➡️ When you are ready, hit Command + Enter (Mac) or Control + Enter (Windows/Linux), or press the ▶️ play button after clicking on the cell below.

Fetching long content....

🎨 Viewing aseg.mgz

Now we will open the aseg.mgz file. This is FreeSurfer’s automatic brain segmentation, where different brain structures are given unique numbers and colors.

  • 📂 aseg.mgz = FreeSurfer’s anatomical segmentation file

  • 🎨 Each color = a different brain structure (e.g., hippocampus, ventricles, cortex)

  • 🧩 Helps us check if FreeSurfer labelled the brain correctly

  • ➕ Crosshairs line up the same spot across all views


➡️ Click the cell below, then press Command + Enter (Mac) or Control + Enter (Windows/Linux). This will open aseg.mgz in the viewer with FreeSurfer colors.

Loading...

Viewing the Pial Surfaces

Now we will look at the pial surfaces. These are '3D' models of the outer surface of the brain (the grey matter boundary). FreeSurfer creates one for each hemisphere.

  • 📂 lh.pial = left hemisphere surface

  • 📂 rh.pial = right hemisphere surface

  • 🔴 Left hemisphere is shown in red

  • 🔵 Right hemisphere is shown in blue

  • Displayed in a fully interactive 3D view (you can rotate and zoom)


➡️ Click the cell below, then press Command + Enter (Mac) or Control + Enter (Windows/Linux). You’ll see a 3D model of the brain surface – red for left, blue for right.

[HF-patcher] lh.pial: path → url
[HF-patcher] rh.pial: path → url
Loading...

⚪ Viewing the White Matter Surfaces

Now we will open the white matter surfaces. These are 3D models of the inner boundary of the cortex, where the grey matter meets the white matter. They are used by FreeSurfer to measure cortical thickness.

  • 📂 lh.white = left hemisphere white surface

  • 📂 rh.white = right hemisphere white surface

  • 🟠 Left hemisphere is shown in orange

  • 🔵 Right hemisphere is shown in light blue

  • 🌐 Fully interactive 3D display – rotate and zoom to explore


➡️ Click the cell below, then press Command + Enter (Mac) or Control + Enter (Windows/Linux). You’ll see the white matter surfaces in 3D (orange = left, blue = right).

[HF-patcher] lh.white: path → url
[HF-patcher] rh.white: path → url
Loading...

🌐 Viewing the Inflated Surface

Now we will look at the inflated brain surface. This is a special 3D model where the folds (sulci and gyri) are “smoothed out” so the entire cortex can be seen more clearly. It is very useful for visualising activity maps or large-scale anatomy without folds hiding important areas.

  • 📂 lh.inflated = inflated left hemisphere surface

  • 🔴 Left hemisphere is shown here in light red

  • 👁️ The sulci (valleys) are expanded so you can see regions that are normally hidden inside folds

  • 🌐 Fully interactive 3D view – rotate and zoom to explore the cortical sheet


➡️ Click the cell below, then press Command + Enter (Mac) or Control + Enter (Windows/Linux). You’ll see the inflated left hemisphere in 3D.

[HF-patcher] lh.inflated: path → url
Loading...

🗂️ Inspecting the Subject Folder & Logs

This step shows the top-level contents of the subject’s FreeSurfer folder and the run logs. Use it to confirm that key outputs exist and to find logs if something went wrong.

SUBJECTS_DIR = ./data/structural/recon-all-clinical
SUBJECT     = TestSubject
Path        = ./data/structural/recon-all-clinical/TestSubject
    

📁 What the main folders mean

FolderPurpose
mri/All volumetric outputs (.mgz), e.g. native.mgz, aseg.mgz
surf/Cortical meshes (.white, .pial, .inflated) and annotations (.annot)
label/Region labels and color tables (.ctab)
stats/Per-region thickness/surface area stats (for group analysis)
scripts/Run logs, IsRunning flags, and command histories
Tip: If a run crashes or stalls, check scripts/ for recent log files and any IsRunning* flags.

➡️ Click the cell below, then press Command + Enter (Mac) or Control + Enter (Windows/Linux) to list the directory tree and show log files.

=== Subject directory tree (top) ===
total 32K
drwxrwxr-x 2 jovyan jovyan 4.0K Apr  9 03:26 label
drwxrwxr-x 3 jovyan jovyan 4.0K Apr  9 03:37 mri
drwxrwxr-x 2 jovyan jovyan 4.0K Apr  9 05:14 scripts
drwxrwxr-x 2 jovyan jovyan 4.0K Apr  9 03:26 stats
drwxrwxr-x 2 jovyan jovyan 4.0K Apr  9 04:36 surf
drwxrwxr-x 2 jovyan jovyan 4.0K Apr  9 01:37 tmp
drwxrwxr-x 2 jovyan jovyan 4.0K Apr  9 01:37 touch
drwxrwxr-x 2 jovyan jovyan 4.0K Apr  9 01:37 trash

=== Logs/scripts ===
total 348K
-rw-rw-r-- 1 jovyan jovyan 341K Apr  9 05:14 recon-all-clinical.log
mri/         All volumetric outputs (.mgz).
surf/        Cortical meshes and annotation files (.white, .pial, .inflated, .annot).
label/       Labels, annotation tables (.ctab), region lists.
stats/       Cortex thickness/surface area stats per region (for group analysis).
scripts/     Run logs, IsRunning flags, and command histories.

Dependencies in Jupyter/Python

  • Using the package watermark to document system environment and software versions used in this notebook, alongside the Neurodesktop version extracted from the JUPYTER_IMAGE or NEURODESKTOP_VERSION environment variables.

Last updated: 2026-04-09T05:14:08.282738+00:00

Python implementation: CPython
Python version       : 3.13.9
IPython version      : 9.7.0

Compiler    : GCC 14.3.0
OS          : Linux
Release     : 5.15.0-171-generic
Machine     : x86_64
Processor   : x86_64
CPU cores   : 32
Architecture: 64bit

IPython  : 9.7.0
ipyniivue: 2.4.4
json     : 2.0.9
nibabel  : 5.3.3
numpy    : 2.3.5

Neurodesktop version: 2025-12-20
References
  1. Gopinath, K., Greve, D. N., Magdamo, C., Arnold, S., Das, S., Puonti, O., & Iglesias, J. E. (2025). “Recon-all-clinical”: Cortical surface reconstruction and analysis of heterogeneous clinical brain MRI. Medical Image Analysis, 103, 103608. 10.1016/j.media.2025.103608
  2. Shaw, T. B., York, A., Barth, M., & Bollmann, S. (2020). Towards Optimising MRI Characterisation of Tissue (TOMCAT) Dataset including all Longitudinal Automatic Segmentation of Hippocampal Subfields (LASHiS) data. Data in Brief, 32, 106043. 10.1016/j.dib.2020.106043