I followed the examples in Doxygen Docutment, but failed. There is no ConjugateGradientLineSearchOptimizerv4Template member in itk, and the itk.ConjugateGradientOptimizer can not be used by itk.ImageRegistrationMethodv4 object.
I am interested in this as well and will broaden a bit the question as it’s tagged as beginner one. It’s been a while since I used ITK and haven’t used the python version before. I was hoping that through the new python interface, using ITK for registration of vector images with a custom optimiser (LBFGSB in my case) would be a breeze. It’s not really the case yet…
The choice of ImageRegistrationMethodv4 over ImageRegistrationMethod seems undocumented. Is ImageRegistrationMethod meant to be the latest one or is it a relic from ITK v3?
Assuming for now that v4 is preferable as this is showcased in the first example:
I tried to instantiate a vector image registration by adapting the example but got an error:
itk.MeanSquaresImageToImageMetricv4 is not wrapped for input type `itk.Image[itk.Vector[itk.F,3],2], itk.Image[itk.Vector[itk.F,3],2]`.
I averaged my images across the last dimension to nonetheless try and change the optimiser to LBFGSBOptimiser (
itk.LBFGSBOptimizer.New()) but got a type error:
TypeError: in method 'itkImageRegistrationMethodv4REGv4F2F2_SetOptimizer', argument 2 of type 'itkObjectToObjectOptimizerBaseTemplateD *'
I then moved on to try and instantiate a LBFGSBOptimizerv4 (
itk.LBFGSBOptimizerv4.New()) but got an error as well:
AttributeError: module 'itk' has no attribute 'LBFGSBOptimizerv4'
Through another thread (Monitoring registration progress in python - and status of itk vs simpleitk for registration) I realised that switching to LBFGS or Conjugate Gradient is at least easy in simpleitk (where additionally there is no question of v4 or no v4):
In the example https://simpleitk.readthedocs.io/en/master/link_ImageRegistrationMethod1_docs.html, just use
ImageRegistrationMethod is part of v3 registration framework. Both v3 and v4 are expected to coexist for foreseeable future. v3 and v4 frameworks cannot be mixed. v4 is newer and more flexible, but more complicated.
itk.MeanSquaresImageToImageMetricv4 is not wrapped … for vector images
Indeed. I don’t know whether that was done to keep wrapping size down or because
MeanSquaresImageToImageMetricv4 does not work with vector images.
LBFGSBOptimizerv4 is also not wrapped for Python. But adding wrapping for optimizers should be easy (example).