Brain Imaging Analysis Tutorial

Overview

Estimated Time45 minutes
DifficultyIntermediate
PrerequisitesPython 3.9+

What You'll Learn

  • Load and preprocess brain MRI scans
  • Extract shape features using BrainShapeToolKit
  • Apply differentiable appearance modeling with DiffAM
  • Visualize and interpret results

Dataset

This tutorial uses the ADNI dataset (Alzheimer's Disease Neuroimaging Initiative). Ensure you have obtained access and downloaded the appropriate MRI scans before proceeding.

Step 1: Setup Environment

Clone and install both BrainShapeToolKit and DiffAM repositories:

git clone https://github.com/SSTDV-Project/BrainShapeToolKit.git
git clone https://github.com/SSTDV-Project/DiffAM.git
cd BrainShapeToolKit && pip install -e .
cd ../DiffAM && pip install -e .

Step 2: Load and Preprocess Data

Load a brain MRI scan and extract the surface mesh:

import nibabel as nib
import numpy as np
from brainshapetoolkit import MeshProcessor

mri = nib.load('data/sample_brain.nii.gz')
mri_data = mri.get_fdata()
processor = MeshProcessor()
mesh = processor.extract_surface(mri_data, threshold=0.5)
mesh_smooth = processor.smooth(mesh, iterations=10)

Step 3: Extract Shape Features

Compute quantitative shape features from the smoothed mesh:

from brainshapetoolkit.features import ShapeFeatures
feature_extractor = ShapeFeatures()
features = feature_extractor.compute(mesh_smooth)
print(f"Surface area: {features['surface_area']:.2f} mm²")

Step 4: Appearance Modeling with DiffAM

Use DiffAM to extract appearance embeddings and generate synthetic variants:

import diffam
model = diffam.DiffAM(pretrained=True)
embeddings = model.extract_embeddings(mesh_smooth)
synthetic = model.interpolate(embeddings, n_samples=5)

Citation

If you use BrainShapeToolKit or DiffAM in your research, please cite:

@software{brainshapetoolkit,
  title   = {BrainShapeToolKit},
  author  = {SSTDV Project},
  year    = {2024},
  url     = {https://github.com/SSTDV-Project/BrainShapeToolKit}
}

@software{diffam,
  title   = {DiffAM: Differentiable Appearance Modeling},
  author  = {SSTDV Project},
  year    = {2024},
  url     = {https://github.com/SSTDV-Project/DiffAM}
}

← Back to Tutorials