ANTsPy is a Python library which wraps the well-established C++ biomedical image processing library 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 your medical images, you might be interested in ANTsPyNet which provides tools for training and visualizing deep learning models. ANTsPy and ANTsPyNet seamlessly integrate with the greater Python community, particularly deep learning libraries, scikit-learn, and numpy.
We recommend that users install the latest pre-compiled binaries, which takes ~1 minute.
For MacOS and Linux:
pip install antspyx
Because of limited storage space, pip binaries are not available for every combination of python version and platform. Additionally, we are required to remove outdated wheels. If we do not have releases for your platform, you can check the Github Releases page or build from source with:
git clone https://github.com/ANTsX/ANTsPy
cd ANTsPy
python3 setup.py install
If you want more detailed instructions on compiling ANTsPy from source, you can read the installation tutorial.
We cannot store the entire history of releases because storage space on pip
is limited. If you need an older release, you can check the Github Releases page or
build from source. To install a specific version from source, you can try the following:
pip install 'antspyx @ git+https://github.com/ANTsX/[email protected]'
which will attempt to build from source (requires a machine with developer tools).
Non-release commits have wheels built automatically, which are available for download for a limited period. Look under the Actions tab. Then click on the commit for the software version you want. Recent commits will have wheels stored as "artifacts".
Wheels are built locally like this:
rm -r -f build/ antspymm.egg-info/ dist/
python3 setup.py sdist bdist_wheel
pipx run twine upload dist/*
Available on Docker Hub. To build ANTsPy docker images, see the (installation tutorial)(https://github.com/ANTsX/ANTsPy/blob/master/tutorials/InstallingANTsPy.md#docker-installation).
Here is an example of reading in an image, using various utility functions such as resampling and masking, then performing three-class Atropos segmentation.
from ants import atropos, get_ants_data, image_read, resample_image, get_mask
img = image_read(get_ants_data("r16"))
img = resample_image(img, (64,64), 1, 0 )
mask = get_mask(img)
segs1 = atropos(a=img, m='[0.2,1x1]', c='[2,0]', i='kmeans[3]', x=mask )
We provide numerous tutorials for new users: https://github.com/ANTsX/ANTsPy/tree/master/tutorials
In some cases, you may need some other libraries if they are not already installed eg if cmake says something about
a missing png library or a missing Python.h
file.
sudo apt-get install libblas-dev liblapack-dev
sudo apt-get install gfortran
sudo apt-get install libpng-dev
sudo apt-get install python3-dev # for python3.x installs
cd docs
sphinx-apidoc -o source/ ../
make html