Monitoring registration progress in python - and status of itk vs simpleitk for registration

As I started to discuss in a different thread (Can I use conjugate gradient optimizer for registration in python?How can I do ?), I wanted to try out performing image registration in python with itk. While the initial example ( works, it is not trivial to find documentation on how to modify it.

For example, I would like to add a command observer. There is an example here but it is only in c++ and it uses the itkImageRegistrationMethod rather than itkImageRegistrationMethodv4:

Searching for itk.Command and python in google or discourse did not (at least easily) lead to any example.

Should simpleitk be prefered for these sort of tasks? The examples look more developed in python and there doesn’t seem to be a confusing choice of ImageRegistrationMethod or ImageRegistrationMethodv4 in simpleitk.


If SimpleITK’s compact and easy to use interface does whats needed, is there a good reason not to use it for a particular task?

Great question. I was reading about the improved interoperability between itk and numpy and was looking forward to playing with it. Having no experience with itk in python but having experience with itk in c++ from a long time ago, my first try was to use itk rather than simpleitk.

Given the first impression of itk in python, I guess I’ll use simpleitk :slight_smile:

ITK seamless integration with NumPy is a nice feature.

You can find out how to manually convert SimpleITK’s Image to NumPy in the Notebook examples: Some improvements to SimpleITK’s interoperability with NumPy will be coming in the future.

1 Like

Thanks. A bit off topic from the title of the post but while simpleitk solved 2 of the 3 problems is faced in my first toy example (i.e. the command observer and the use of LBFGS as the optimiser), I am still unable to register vector images as I get the following error:

sitk::ERROR: Filter does not support fixed image type: vector of 32-bit float

Are other vector image types supported for registration? A quick search didn’t lead to useful results on this matter.

I don’t believe that any of the ITKv4 metrics directly support vector image. @ntustison would know for certain the metrics or if the methods do directly support it.

However, the ITKv4 registration does support multi-metric. This would enable one metric for each pair of components. This feature is not available in SimpleITK, but is certainly available in C++ ITK. I’m not sure if ITK Python has it, the infrastructure certainly could easily support it with some effort.

1 Like

Hey @tvercaut ,

@blowekamp is correct in that vector images aren’t directly supported in the ITKv4 metrics. However, if you’re looking to do image registration in python, specifically ANTs registration, you might want to check out ANTsPy.


1 Like

Any itk.Object in Python can be passed a Python callable, i.e. a Python function on a Python class that has a __call__ method to its AddObserver method. AddObserver takes the specific itk.EventObject to be observed along with the command to execute when the event occurs.

Here is an example:

import itk

image = itk.imread('/home/matt/data/aneurism.nrrd')

normalizer = itk.NormalizeImageFilter.New(image)

def my_python_function():
    print('hey from a python function')
normalizer.AddObserver(itk.StartEvent(), my_python_function)


The examples are in need of updates :slight_smile: :open_book:

1 Like