Skip to content
ANTsXPublic

About

Processing and deep learning utilities for quantitative medical imaging with PyTorch

Resources

Stars

7 stars

Watchers

3 watching

Forks

Repository files navigation

ANTsTorch — conceptual brain illustration combining MRI, colored segmentation, and a deformation grid

ANTsTorch

Medical imaging with PyTorch, powered by ANTsX

Deep learning architectures · Pretrained applications · Differentiable image processing · Registration

Python PyTorch License PyPI - Downloads ANTsX paper

Documentation · Examples · API guide · Benchmarks · Model validation


ANTsTorch brings the ANTsX medical imaging ecosystem to PyTorch. Build and train 2-D and 3-D networks, apply pretrained models to ANTs images, and explore tensor-based bias correction, registration, cortical thickness estimation, and normalizing flows.

It complements ANTsPyNet and ANTsRNet, with ports of ANTsPyNet architectures and pretrained applications. Porting and numerical validation are ongoing; see the validation guide for the scope of available comparison evidence.

What you can do

Area Capabilities Start here
Deep learning 2-D and 3-D U-Nets, ResNets, dense networks, deep back-projection networks, and task-specific architectures U-Net example
Pretrained applications Brain extraction, tissue segmentation, anatomical labeling, lung imaging, super-resolution, and more Application catalog
Image processing Preprocessing, augmentation, and tensor-native N4 bias field correction N4 example
Registration SyN, affine, and B-spline stationary velocity field registration SyN tutorial · B-spline tutorial
Cortical thickness Segmentation-driven workflows and a tensor implementation of DiReCT Implementation guide
Normalizing flows Flow architectures and LAMNR hybrid training workflows Training guide

Installation

Requires Python 3.10+ and Git. From a terminal:

git clone https://github.com/ANTsX/ANTsTorch.git
cd ANTsTorch
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e .

On Windows, activate the environment with .venv\Scripts\activate.

For a direct installation without a working checkout:

python -m pip install git+https://github.com/ANTsX/ANTsTorch.git

Installation includes ANTsPy, PyTorch, JAX, and other scientific dependencies. Git is needed for the antsnormflows dependency. See the installation guide for device selection, downloads, and caching.

Quick start

Build a 2-D U-Net

Run a forward pass with synthetic input; no image or model downloads are needed.

import torch
import antstorch

model = antstorch.create_unet_model_2d(
    input_channel_size=1,
    number_of_outputs=3,
    number_of_filters=(8, 16, 32),
    mode="classification",
).eval()

image = torch.rand(1, 1, 64, 64)  # batch, channels, height, width
with torch.inference_mode():
    probabilities = model(image)

print(tuple(probabilities.shape))  # (1, 3, 64, 64)

This network has random weights. Train it before using its predictions for segmentation.

Extract a brain from a T1 MRI

Use a local scalar 3-D T1 image with a pretrained model:

import ants
import antstorch

image = ants.image_read("t1.nii.gz").clone("float")
probability = antstorch.brain_extraction(image, modality="t1", device="cpu")
mask = ants.threshold_image(probability, 0.5, 1.0, 1, 0)
ants.image_write(image * mask, "t1_brain.nii.gz")

Weights and templates download on first use and are cached under ~/.antstorch. This example thresholds the probability map at 0.5; inspect the result for your data. Other extraction modalities may return different output structures.

Run the examples

Explore the Jupyter notebook collection, starting with Getting started. It includes U-Net, N4, SyN, brain extraction, Deep Atropos, cortical thickness, Harvard–Oxford, DKT, SIAM, B-spline fitting and registration, data augmentation, denoising, Deep FLASH, white matter hyperintensities, mouse brain analysis and MRI super-resolution workflows.

python -m pip install -e '.[notebooks]'
python -m ipykernel install --user --name python3 --display-name "Python 3 (ANTsTorch)"

Open a notebook in Jupyter or VS Code and select this kernel. The first three notebooks use synthetic data; registration and pretrained applications download sample images or model assets. See the example guide for resources and outputs.

Pretrained applications

The application layer provides ANTsPyNet model ports and integrations with published PyTorch models. Available workflows include:

Domain Applications
Brain extraction T1, T2, T2*, FA, FLAIR, PET, MRA; T1 three-tissue, hemisphere, and lobe variants
Brain anatomy Deep Atropos tissue segmentation, Desikan–Killiany–Tourville and Harvard–Oxford labeling, Deep FLASH, cerebellar morphology, cortical thickness
Whole-head segmentation Original SIAM v0.3 via nnU-Net, with the optional siam extra; usage and model downloads
Small structures HippMapp3r and two-stage hippocampus segmentation, hypothalamus and subunits, claustrum
White matter lesions SYSU-Media, HyperMapp3r, ANTsXNet WMH, and SHIVA PVS/WMH ensembles
Lung imaging Extraction in proton MRI, CT, ventilation MRI, and X-ray; lobe, airway, vessel, and pulmonary artery segmentation
Mouse imaging & histology Brain extraction, parcellation, cortical thickness, histology masks, and histology super-resolution
Image quality & enhancement MRI modality classification, neural image quality assessment, MRI super-resolution, and anisotropic 2×–6× super-resolution

Availability does not imply numerical parity for every modality or model variant. The model validation guide explains the comparison harness, saved evidence, and remaining gaps.

Benchmarks

The benchmark guide brings together comparison protocols, recorded results, figures, and instructions for reproducing the runs.

Suite Comparisons Measures
Registration ANTsTorch, syntx, FireANTs, and an ANTs C++ baseline on Mindboggle-101; the reported run covers 30 of the 90 defined pairs DKT31 label overlap (Dice), deformable registration time, Jacobian statistics, and folding percentage
Image-processing primitives ANTs and ANTsTorch implementations of N4 bias correction, denoising, cortical thickness, and B-spline fitting Run time and numerical agreement, with recorded MPS and CUDA results

Registration comparisons use a shared affine initialization in the default fair mode. Read the results alongside their hardware, model settings, and inverse-transform conventions; CPU and GPU timings describe different execution environments. The guide includes the data requirements and commands needed to reproduce each comparison.

Learn more

Research, community & license

For background and applications, see the ANTsX ecosystem publication.

Questions, bug reports, and contributions are welcome through GitHub Issues and pull requests. Please include a minimal example and relevant package versions when reporting a problem.

ANTsTorch is released under the Apache License 2.0.

We gratefully acknowledge grant support from the Office of Naval Research (N0014-23-1-2317).

About

Processing and deep learning utilities for quantitative medical imaging with PyTorch

Resources

Stars

7 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages