This Python package provides functionality for processing T1-weighted MRI images using FreeSurfer and the Lausanne 2018 multi-scale atlas parcellation scheme. The implementation includes surface-based and volumetric processing across five different scales of brain parcellation.
Make this file in the root directory and fill in the paths to your FreeSurfer installation and subjects directory where freesurfer templates are stored.
{
"FREESURFER_HOME": "/Applications/freesurfer/7.3.2/",
"SUBJECTS_DIR": "subjects"
}
Download example subject directory from here and place it in the subjects
directory.
def __init__(self, t1, subjectID, output_dir=None)
Parameters:
t1
(str): Path to T1-weighted MRI imagesubjectID
(str): Unique identifier for the subjectoutput_dir
(str, optional): Custom output directory path
Configures the FreeSurfer environment variables and initializes the FreeSurfer setup.
Executes FreeSurfer's recon-all pipeline for structural MRI processing.
- Performs complete reconstruction including cortical surface generation
Implements the Lausanne 2018 atlas parcellation at five different scales. Each method:
- Performs surface-to-surface mapping for both hemispheres
- Calculates anatomical statistics
- Converts aparc to aseg format
- Converts output to NIfTI format
Common processing steps for each scale:
- Surface-to-surface mapping (left and right hemispheres)
- Anatomical statistics computation
- Parcellation conversion (MGZ to NIfTI)
Relocates processed data to a specified output directory if provided.
python freesurfer.py -t1 <t1_image_path> -s <subject_id> [-o <output_directory>]
Arguments:
-t1
: Path to T1-weighted image (required)-s
: Subject ID (required)-o
: Output directory (optional)
- FreeSurfer (v7)
- Python standard libraries:
os
subprocess
json
argparse
# Initialize processor
processor = Multiscaleatlas(
t1="/path/to/t1.nii.gz",
subjectID="sub-001",
output_dir="/path/to/output"
)
# Run full reconstruction
processor.recon_all()
# Process specific scale
processor.lausanne2018scale1()
# Move results to output directory
processor.move_output()
- Requires FreeSurfer to be properly installed and configured
- Environment variables are loaded from
setup_environment.json
- All scales (1-5) of the Lausanne 2018 atlas are supported
- Output includes both surface (.annot) and volumetric (.mgz, .nii.gz) formats
subject_id/
├── label/
│ ├── lh.lausanne2018.scale*.annot
│ └── rh.lausanne2018.scale*.annot
├── stats/
│ ├── lh.lausanne2018.scale*.stats
│ └── rh.lausanne2018.scale*.stats
└── mri/
├── lausanne2018.scale*.mgz
└── lausanne2018.scale*.nii.gz
Where * represents scales 1 through 5.