Skip to content
Nat Lee

Keyboard shortcuts

Turn these off if they get in the way of a screen reader or voice control. The setting is saved in this browser.

1
Home
2
Work
3
Projects
4
About
5
Experience
/
Search projects
?
Show this panel

Medical Imaging

Spin-off · Infortrend

Brain MRI Pipeline

From a T1 scan to tissue maps and QC

An end-to-end Nipype pipeline with FSL FAST, K-means and ANTs Atropos segmentation, tissue volumes, bias-correction metrics and an interactive 3D brain.

Role
Creator & Maintainer
Period
2020.01 – 2026.11
Status
Completed
Categories
Vision & imaging
Origin
Infortrend
Stack
  • Python
  • Nipype
  • FSL
  • ANTs
  • Nilearn
  • Docker
Brain MRI Pipeline, screenshot 1

Overview

A research and learning pipeline for T1-weighted MRI: AC-PC alignment, MNI152 registration, skull stripping and N4 bias correction, followed by a choice of FSL FAST, K-means or ANTs Atropos. It compares segmentation agreement, reports tissue volumes and QC metrics, and produces a 3D view and HTML report per scan. Demo scans come from openly licensed OpenNeuro data.

What it's good for

Lets students and researchers watch each preprocessing step instead of trusting a black box: every node writes its own folder, so any in-between image opens in FSLeyes or ITK-SNAP. It's a teaching tool, not a medical device, and the README says so out loud.

Diagrams

Main paths only. The edge cases stayed in the code.

N4 lowered the CJV on all three demo scans. Numbers, not vibes.

Point at a box to see what it connects to.

  1. Take the next T1 scan(.nii or .nii.gz) → Find AC-PC, align the head
  2. Find AC-PC, align the head(ART acpcdetect) → Register to the MNI152 template
  3. Register to the MNI152 template(FLIRT, 12 dof) → Strip the skull, fix bias
  4. Strip the skull, fix bias(BET, then ANTs N4) → FSL FAST → K-means → ANTs Atropos
  5. FSL FAST(the primary method) → Count volumes, measure agreement
  6. K-means(brightness is all it knows) → Count volumes, measure agreement
  7. ANTs Atropos(spatial model, no partial volumes) → Count volumes, measure agreement
  8. Count volumes, measure agreement(agreement as Dice overlap) → Render the 3D brain?
  9. Render the 3D brain? → yes, default: Build a marching-cubes surface → no (--no-3d): Write the scan's HTML report
  10. Build a marching-cubes surface(turntable GIF, interactive page) → Write the scan's HTML report
  11. Write the scan's HTML report(maps from the primary method) → More scans left?
  12. More scans left? → yes: Take the next T1 scan → no: One overview page for the run
  13. One overview page for the run(plus the cohort volumes CSV)

Features

  • AC-PC alignment, registration, skull stripping and N4 correction
  • Selectable FAST, K-means or Atropos segmentation
  • Tissue volumes, Dice agreement and before/after QC
  • Interactive 3D brain, turntable GIF and HTML reports

The problem

  • Keeping specialised imaging tools reproducible
  • Comparing tissue segmentation methods on the same corrected scan

What I did

  • A focused Docker image containing the required tools
  • Shared N4-corrected inputs with selectable primary segmentation

Results

  • Reproducible CPU pipeline with openly licensed demo scans
  • Per-scan tissue maps, quantitative QC and HTML reports
One demo scan after each step: original, AC-PC, registered, skull stripped, N4.
One demo scan after each step: original, AC-PC, registered, skull stripped, N4.

What I learned

  • The first comparison had K-means cut every brain into near-equal thirds. The pipeline did it: K-means clustered the equalised image, whose histogram is flat.
  • K-means sorts voxels by brightness alone and gave 5 to 7 points less grey matter than FAST, so FAST became the default in November 2026.
  • N4 bias correction lowered the grey/white CJV on every demo scan (sub-01: 0.64 to 0.56), so the step earns its place with numbers.
  • The same slices segmented three ways: K-means, FSL FAST and ANTs Atropos.
    The same slices segmented three ways: K-means, FSL FAST and ANTs Atropos.
  • N4's estimated bias field, and the grey and white matter peaks pulling apart after it.
    N4's estimated bias field, and the grey and white matter peaks pulling apart after it.
  • Tissue volumes of the three demo scans: grey matter lands near 45% every time.
    Tissue volumes of the three demo scans: grey matter lands near 45% every time.
  • Spin-off · Infortrend
    Libraries & toolsVision & imaging7070 stars on GitHub

    Blur Generator

    Makes perfectly good images worse on purpose: motion, lens, Gaussian and depth-aware blur, for training models that have to cope with bad photos.

    2021Completed
  • Libraries & toolsVision & imaging2626 stars on GitHub

    HEIC2PNG

    Turns iPhone HEIC photos into PNG from the CLI, a shell pipe or Python. A small tool for a small, recurring annoyance.

    2022Completed
  • Spin-off · Infortrend
    Libraries & toolsVision & imaging7676 stars on GitHub

    Batch Crop Images

    Draw a crop box once and it is applied to a whole folder of similar images. Written because I refused to crop them one by one, and apparently other people refused too.

    2019Completed