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
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.
@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.
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)
normalizer.Update()