Skip to content
/ ANTsPy Public

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.

License

Notifications You must be signed in to change notification settings

ANTsX/ANTsPy

Repository files navigation

Advanced Normalization Tools in Python

Coverage Status PyPI - Downloads Nightly Build ci-pytest ci-docker Docker Pulls Contributor Covenant PubMed

The ANTsPy library wraps the well-established C++ biomedical image processing framework ANTs. It includes blazing-fast reading and writing of medical images, algorithms for registration, segmentation, and statistical learning, as well as functions to create publication-ready visualizations.

If you are looking to train deep learning models on medical imaging datasets, you might be interested in ANTsPyNet which provides tools for training and visualizing deep learning models.


Installation

Pre-compiled binaries

The easiest way to install ANTsPy is via the latest pre-compiled binaries from PyPI.

pip install antspyx

Because of limited storage space, pip binaries are not available for every combination of python version and platform. We also have had to delete older releases to make space. If you cannot find a binary you need on PyPI, you can check the Releases page for archived binaries.

Some Mac OS Python installations have compatibility issues with the pre-compiled binaries. This means pip will not install binaries targeted for the current Mac OS version, and will instead try to compile from source. The compatibility checks can be disabled by setting the environment variable SYSTEM_VERSION_COMPAT=0. More details on the wiki.

Building from source

In some scenarios, it can make sense to build from source. In general, you can build ANTsPy as you would any other Python package.

git clone https://github.com/antsx/antspy
cd antspy
python -m pip install .

Further details about installing ANTsPy or building it from source can be found in the Installation Tutorial.


Quickstart

Here is a basic overview of some of the things you can do with ANTsPy. The main functionality includes reading / writing images, basic and advanced image operations, segmentation, registration, and visualization.

import ants

# read / write images
img = ants.image_read('path/to/image.nii.gz')
ants.image_write(img, 'path/to/image.nii.gz')

# basic operations
img + img2
img - img2
img[:20,:20,:20] # indexing returns an image

# advanced operations
img = ants.smooth_image(img, 2)
img = ants.resample_image(img, (3,3,3))
img.smooth_image(2).resample_image((3,3,3)) # chaining

# convert to or from numpy
arr = img.numpy()
img2 = ants.from_numpy(arr * 2)

# segmentation
result = ants.atropos(a=img, m='[0.2,1x1]', c='[2,0]', i='kmeans[3]', x=ants.get_mask(img))

# registration
result = ants.registration(fixed_image, moving_image, type_of_transform = 'SyN' )

# plotting
ants.plot(img, overlay = img > img.mean())

Tutorials

Resources for learning about ANTsPy can be found in the tutorials folder. A selection of especially useful tutorials is presented below.

  • Basic overview [Link]
  • Composite registrations [Link]
  • Multi-metric registration [Link]
  • Image math operations [Link]
  • Wrapping ITK code [Link]

More tutorials can be found in the ANTs repository.


Contributing

If you have a question or bug report the best way to get help is by posting an issue on the GitHub page. We welcome any new contributions and ideas. If you want to add code, the best way to get started is by reading the contributors guide that runs through the structure of the project and how we go about wrapping ITK and ANTs code in C++.

You can support our work by starring the repository, citing our methods when relevant, or suggesting new features in the issues tab. These actions help increase the project's visibility and community reach.


References

The main references can be found at the main ANTs repo. A Google Scholar search also reveals plenty of explanation of methods and evaluation results by the community and by ourselves.