Using ANTs package on Google Colaboratory

Suyog Jadhav
Mar 28, 2019 · 3 min read

A Primer on ANTs and Google Colaboratory

Advanced Normalization Tools (or simply, ANTs) is one of the few packages available in the domain of brain MRI study. It is the state-of-the-art package currently available for various tasks related to brain MRI scans like registration, normalization and bias field correction (including both N3 and N4 bias field correction). Though the package hasn’t been updated with a major release in a while, it works pretty well on PCs.

Google Colaboratory (or simply, Colab) has quickly risen to become one of the most commonly used platforms by machine learning researchers and students all over the globe. Through Colab, Google provides users free access to cloud resources for machine learning. With a Google account, you get access to a Google’s version of IPython Notebook backed by either CPU, GPU, or even TPU runtime (you get to choose).

I am currently working on a project dubbed Brainy which is based on brain tumor segmentation from MRI scans of the patient’s brain. At the time of writing this article, I couldn’t get ANTs to install on the Colab environment. There are not many helpful articles on the internet, and the existing pre-built binaries were too outdated. After some iterations, I was able to build ANTs from the source on Colab itself. The binaries included in the next section were built specifically for Colab and should work fine on Colab. However, if you run into an error, do let me know by raising an issue here.


Pre-Built Binaries

I will try to keep this section updated by posting a new binary based on the latest master branch of ANTsX/ANTs after a major release.

Installation Instructions

  1. Open the latest build from above links. It is a Google Drive link. Add the .7z file to your drive by clicking the Add to Drive icon.
  2. Open a new Colab notebook.
  3. Mount the drive by running the following cell:
from google.colab import drive 
drive.mount('/gdrive')

4. Drive is now mounted at /gdrive. Copy the archive from your drive using cp and extract it using 7z.

!cp '/gdrive/My Drive/ANTs-28–03–2019.7z' ./
!7z x ANTs-28–03–2019.7z

5. Now copy the entire contents of the newly created bin folder to /usr/local/bin/:

!cp bin/* /usr/local/bin

6. Test the installation by running:

!which antsRegistration

it should output full path to antsRegistration (which should be /usr/local/bin/antsRegistration in our case)

That’s it! If you face any errors, please let me know.


Building on your own

If you are curious to know the steps to build ANTs on Colab, view the notebook used to build the above binaries here. Keep in mind that it takes a LOT of time to compile. If you build a more recent version than available above, hit me up and I will add it above.


Originally published at suyogjadhav.com on March 28, 2019.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade