Tuesday 17 December 2013

IRTK Python

Python for Medical Imaging

There are several reasons for choosing Python for Medical Imaging. First of all, the main biomedical imaging library out there, ITK, offers both exhaustive SWIG wrappers and a simplified interface called SimpleITK, which can be directly installed from PyPI. Other major libraries, such as VTK for data visualization and OpenCV for Computer Vision also provide excellent Python wrappers.

Then comes the Python eco-system itself, whose ressources for Machine Learning and Image Processing have been growing in the last years with the main libraries: scipy.ndimage, scikit-image and scikit-learn. There are also Python modules for input/output of medical images, such as pydicom and nibabel.

Finally, enough is never enough, there is cython to easily mix python and C/C++ code.

But there's more to Python than a set of existing libraries. It is simple to write, yet powerful. It has a wide community, much wider than the limited scope of scientific computing. It is Open Source, which is a key element for research. It offers several possibilities for optimizing code, for instance making an efficient use of numpy, using joblib for parallelization or cython for C++ optimization.

Why another Medical Imaging library in Python?

IRTK is a Medical Imaging library developped within the BioMedIA group at Imperial College London, initially built around Daniel Rueckert's non-rigid registration using free-form deformations. While ITK deals with ND-images, can read most image formats and has a wide range of applications ranging from cell microscopy to satellite images, IRTK is much more focused, its core component being image registration. It can read NIFTI files, and write NIFTI and PNG files, and all images in IRTK are 4D (X, Y, Z, T), with flat dimensions where necessary. The code is only templated other VoxelType.

The main reason I chose to write a Python interface for IRTK instead of using what already existed is that it is much easier to collaborate within the lab if we all use a same code base. Moreover, I wanted medical images to be as much pythonic as possible, namely a subclass of numpy.ndarray which would automatically update its spatial coordinates when cropped.

Monday 16 December 2013

Thumbnails, default viewer and property tab in nautilus for medical images

This first post is on customising Ubuntu to your needs to make your work easier (and more enjoyable). It is accompanied by this github repository.

Here are quick changes to a brand new installation of Ubuntu:
  1. First of all, restart it with the Gnome classic (no effects) mode to get rid of blinking effects, and set it as default mode.
  2. Set a proper prompt in .bashrc:
    PS1="\[\033[1;30m\][\$?]<\[\033[1;35m\]\u\[\033[1;30m\]>{\$(date +%d-%m\" \"%H:%M)}[\w]\[\033[0m\] "
    and in .tcshrc:
    set prompt="%{\033[1;30m%}[%?]<%{\033n@[1;35m%}m%{\033[1;30m%}>{%D-%W %T}{\033\[0m[%~]} "
    The prompt is here to give you useful information such as current folder, current time or exit code of the last command.
  3. Set the location bar to text mode in nautilus, I find it much more easier to type in text with auto-completion than scroll-down and click on folders, and it enables you to copy and paste folder paths:
    gsettings set org.gnome.nautilus.preferences always-use-location-entry true
  4. Install nautilus-open-terminal to open a terminal in the current directory from nautilus:
    sudo apt-get install nautilus-open-terminal

As you can guess from its title, the main focus of this post is to give medical images what they lack compared with more common image formats: MIME types, thumbnails, open a chosen viewer when you double-click on them, and a property tab in nautilus.