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.
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.
Take the next T1 scan.nii or .nii.gz
Find AC-PC, align the headART acpcdetect
Register to the MNI152 templateFLIRT, 12 dof
Strip the skull, fix biasBET, then ANTs N4
FSL FASTthe primary method
K-meansbrightness is all it knows
ANTs Atroposspatial model, no partial volumes
Count volumes, measure agreementagreement as Dice overlap
Render the 3D brain?
Build a marching-cubes surfaceturntable GIF, interactive page
Write the scan's HTML reportmaps from the primary method
More scans left?
One overview page for the runplus the cohort volumes CSV
Take the next T1 scan(.nii or .nii.gz) → Find AC-PC, align the head
Find AC-PC, align the head(ART acpcdetect) → Register to the MNI152 template
Register to the MNI152 template(FLIRT, 12 dof) → Strip the skull, fix bias
Strip the skull, fix bias(BET, then ANTs N4) → FSL FAST → K-means → ANTs Atropos
K-means(brightness is all it knows) → Count volumes, measure agreement
ANTs Atropos(spatial model, no partial volumes) → Count volumes, measure agreement
Count volumes, measure agreement(agreement as Dice overlap) → Render the 3D brain?
Render the 3D brain? → yes, default: Build a marching-cubes surface → no (--no-3d): Write the scan's HTML report
Build a marching-cubes surface(turntable GIF, interactive page) → Write the scan's HTML report
Write the scan's HTML report(maps from the primary method) → More scans left?
More scans left? → yes: Take the next T1 scan → no: One overview page for the run
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.
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.
How it fits together
Simplified on purpose. The real thing has more arrows and at least one config file nobody understands.
Screenshots
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.
Tissue volumes of the three demo scans: grey matter lands near 45% every time.
Related projects
Spin-off · Infortrend
Libraries & toolsVision & imaging7070 stars on GitHub
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.