Skip to main content

Label Augmented Modality Agnostic Registration: A Python-based workflow combining deep learning-based segmentation and numerical solutions to generate precise warpfields between different MRI modalities.

Project description

LAMAReg: Label Augmented Modality Agnostic Registration

Version PyPI version PyPI downloads GitHub issues GitHub stars

We introduced a novel approach for more accurate registration between modalities. This python based workflow combines deep learning-based segmentation and numerical solutions (ANTs) to generate precise warpfields, even for modalities with low signal-to-noise ratio, signal dropout and strong geometric distortions, such as diffusion MRI and fMRI acquisitions.

lamar_workflow

Overview

LAMAReg provides contrast-agnostic registration between different MRI modalities by using SynthSeg's brain parcellation to enable robust alignment between images with different contrasts (e.g., T1w to T2w, FLAIR to T1w, DWI to T1w).

This Python-based workflow combines deep learning-based segmentation (SynthSeg) and numerical optimization (ANTs) to generate precise warpfields, even for modalities with low signal-to-noise ratio, signal dropout, and strong geometric distortions, such as diffusion MRI and fMRI acquisitions.

!lamar_workflow

Installation

pip install -e .

Workflows

LAMAReg offers three main workflows and direct access to individual tools:

1. Full Registration Pipeline

Parcellate both input images, register them, and apply the transformation:

lamar register [options]

2. Generate Warpfield Only

Create warpfields without applying them to the input image:

lamar generate-warpfield [options]

3. Apply Existing Warpfield

Apply previously created warpfields to an input image:

lamar apply-warpfield [options]

4. Direct Tool Access

Run individual components directly:

lamar synthseg [options]      # Run SynthSeg brain parcellation
lamar coregister [options]    # Run ANTs coregistration
lamar apply-warp [options]    # Apply transformations
lamar dice-compare [options]  # Calculate Dice similarity coefficient

Command-Line Arguments

Full Registration

Required Arguments:

  • --moving PATH : Input image to be registered
  • --fixed PATH : Reference image (target space)
  • --output PATH : Output registered image
  • --moving-parc PATH : Path for moving image parcellation
  • --fixed-parc PATH : Path for fixed image parcellation
  • --registered-parc PATH : Path for registered parcellation
  • --affine PATH : Path for affine transformation
  • --warpfield PATH : Path for warp field
  • --inverse-warpfield PATH : Path for inverse warp field
  • --inverse-affine PATH : Path for inverse affine transformation

Optional Arguments:

  • --registration-method STR : Registration method (default: SyNRA)
  • --synthseg-threads N : SynthSeg threads (default: 1)
  • --ants-threads N : ANTs threads (default: 1)
  • --qc-csv PATH : Path for QC Dice score CSV file

Generate Warpfield

Same arguments as full registration, but without --output

Apply Warpfield

Required Arguments:

  • --moving PATH : Input image to transform
  • --fixed PATH : Reference space image
  • --output PATH : Output registered image
  • --warpfield PATH : Path to warp field
  • --affine PATH : Path to affine transformation

Optional Arguments:

  • --ants-threads N : ANTs threads (default: 1)

SynthSeg

Required Arguments:

  • --i PATH : Input image
  • --o PATH : Output segmentation

Optional Arguments:

  • --parc : Output parcellation
  • --cpu : Use CPU
  • --threads N : Number of threads

Dice Compare

Required Arguments:

  • --ref PATH : Path to reference parcellation image
  • --reg PATH : Path to registered parcellation image
  • --out PATH : Output CSV file path

Argument Parsing Logic

LAMAReg uses a subcommand-based CLI structure using the Python argparse library. Here's how it works:

  1. Main Parser: Defines the global command structure with subparsers for each workflow.
  2. Subparsers: Each workflow (register, generate-warpfield, etc.) has its own subparser with specific arguments.
  3. Command Routing: The main() function routes commands to the appropriate functions in the lamar module.
  4. Default Help: If no command is provided, the comprehensive help message is shown.
  5. Unknown Arguments: For commands like synthseg, additional arguments are parsed from unknown_args to handle SynthSeg-specific options.
  6. Direct Tool Access: Commands like coregister and apply-warp forward arguments to their respective modules.

All output files require explicit paths to ensure deterministic behavior and prevent accidental file overwrites.

Example Usage

Register DWI to T1w using example data:

lamar register --moving example_data/sub-HC001_ses-02_space-dwi_desc-b0.nii.gz --fixed example_data/sub-HC001_ses-01_T1w.nii.gz \ 
  --output output/sub-001_dwi_in_T1w.nii.gz --moving-parc output/sub-001_dwi_parc.nii.gz \
  --fixed-parc output/sub-001_T1w_parc.nii.gz --registered-parc output/sub-001_dwi_reg_parc.nii.gz \
  --affine output/dwi_to_T1w_affine.mat --warpfield output/dwi_to_T1w_warp.nii.gz \
  --inverse-warpfield output/T1w_to_dwi_warp.nii.gz --inverse-affine output/T1w_to_dwi_affine.mat \
  --synthseg-threads 4 --ants-threads 8

Generate parcellations separately:

lamar synthseg --i subject_t1w.nii.gz --o t1w_parcellation.nii.gz --parc
lamar synthseg --i subject_flair.nii.gz --o flair_parcellation.nii.gz --parc

Register using existing parcellations:

lamar register --moving subject_flair.nii.gz --fixed subject_t1w.nii.gz \
  --output registered_flair.nii.gz --moving-parc flair_parcellation.nii.gz \
  --fixed-parc t1w_parcellation.nii.gz --registered-parc registered_parcellation.nii.gz \
  --affine flair_to_t1w_affine.mat --warpfield flair_to_t1w_warp.nii.gz \
  --inverse-warpfield t1w_to_flair_warp.nii.gz --inverse-affine t1w_to_flair_affine.mat

Apply existing warpfield:

lamar apply-warpfield --moving subject_flair.nii.gz --fixed subject_t1w.nii.gz \
  --output registered_flair.nii.gz --warpfield flair_to_t1w_warp.nii.gz \
  --affine flair_to_t1w_affine.mat

Evaluate registration quality:

lamar dice-compare --ref reference_parcellation.nii.gz \
  --reg registered_parcellation.nii.gz --out dice_scores.csv

Working with Existing Parcellations

LAMAReg is designed to work with both new and existing parcellations:

  1. Generate New Parcellations: If you provide paths to non-existing parcellation files, LAMAReg will generate them using SynthSeg.

  2. Use Existing Parcellations: If the parcellation files already exist, LAMAReg will use them directly without regenerating them.

This flexibility allows you to:

  • Process data end-to-end in a single command
  • Pre-compute parcellations for reuse across multiple registrations
  • Mix existing and new parcellations in your workflow

Technical Implementation

LAMAReg's registration approach consists of three main steps:

  1. Brain Parcellation: SynthSeg generates contrast-agnostic parcellations of both the moving and fixed images.
  2. Registration: ANTs registers the parcellations using the SyNRA method (rigid + affine + SyN).
  3. Transformation Application: The resulting transformation is applied to the original moving image.

This approach enables accurate registration between images with different contrast properties where direct intensity-based registration might fail.

Directory Structure

LAMAR/
├── setup.py
├── requirements.txt
├── README.md
├── lamar/
│   ├── __init__.py
│   ├── cli.py
│   ├── scripts/
│   │   ├── lamar.py
│   │   ├── apply_warp.py
│   │   ├── coregister.py
│   │   ├── synthseg.py
│   │   └── dice_compare.py
│   ├── SynthSeg/
│   │   └── ... (SynthSeg code files)
│   └── ext/
│       ├── lab2im/
│       └── neuron/

Notes

  • LAMAReg works with any MRI modality combination
  • If parcellation files already exist, they will be used directly
  • All output files need explicit paths to ensure deterministic behavior
  • The transforms can be reused with the apply-warpfield command
  • Use dice-compare to evaluate registration quality

References

  1. Billot, Benjamin, et al. "Robust machine learning segmentation for large-scale analysis of heterogeneous clinical brain MRI datasets." Proceedings of the National Academy of Sciences 120.9 (2023): e2216399120.
  2. Avants, Brian B., Nick Tustison, and Gang Song. "Advanced normalization tools (ANTS)." Insight j 2.365 (2009): 1-35.

License

This project is licensed under the MIT License.

Contributors

  • Ian Goodall-Halliwell
  • Paul Bautin
  • Nya Yazdi
  • Kevin Du
  • Raul R. Cruces

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lamareg-1.0.0.tar.gz (189.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

lamareg-1.0.0-cp310-cp312-win_amd64.whl (235.8 kB view details)

Uploaded CPython 3.12Windows x86-64

lamareg-1.0.0-cp310-cp312-manylinux_2_17_x86_64.whl (234.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

lamareg-1.0.0-cp310-cp312-macosx_10_9_x86_64.whl (234.4 kB view details)

Uploaded CPython 3.12macOS 10.9+ x86-64

File details

Details for the file lamareg-1.0.0.tar.gz.

File metadata

  • Download URL: lamareg-1.0.0.tar.gz
  • Upload date:
  • Size: 189.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for lamareg-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f11f8d41b65529ec6d76a40c2c2b85949d6646a63d0c20f8f0d3a42996bca4ad
MD5 5a3064a9f61c564305de71e0d2bc13c2
BLAKE2b-256 c0d7373d40770047825cd561f8c213ab90b6ea5c82e556c4c1523a5d05868227

See more details on using hashes here.

File details

Details for the file lamareg-1.0.0-cp310-cp312-win_amd64.whl.

File metadata

  • Download URL: lamareg-1.0.0-cp310-cp312-win_amd64.whl
  • Upload date:
  • Size: 235.8 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for lamareg-1.0.0-cp310-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0638d6c2a36d6e36a4616f0e44c4c5de615dc134442cce7fdafc5b0032b4b25a
MD5 b5bd0340625cadca6808f81e104ba466
BLAKE2b-256 3b24c7e28c247069f67514b9c417077832e8f420b2d71c026e358cc4caf71930

See more details on using hashes here.

File details

Details for the file lamareg-1.0.0-cp310-cp312-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for lamareg-1.0.0-cp310-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 88a378b5c95cda572f7f0719d5d3f38c987e91cff3bfe006de8424929d0e8b9f
MD5 00338c702a4014efcd9157cef0ff9ee5
BLAKE2b-256 82c30d8ce739724c4bc4d54517addb0c04cb5d1bf970995dd482e135a29cc0b0

See more details on using hashes here.

File details

Details for the file lamareg-1.0.0-cp310-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lamareg-1.0.0-cp310-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ac7b45a4089fd9c237271e2927022f83e148e6dbe6f376505ee47a69e079ed30
MD5 dab2034dca695cc5007e5ec4934241a8
BLAKE2b-256 157dc896b829a0b1f22b899963bf92c80fd7f5675cafe0e8c06f1edc7c71b93a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page