is there a way to set custom metric in itk registration in python?

I have a similarity metric that I’d like to use in ImageRegistrationMethod in itk python, is there any way to do so?

1 Like

Hi @sedghi,

Yes. If it is an existing method in ITK, it can be used from Python with the ImageRegistrationMethod.

If it is a new method you created your self, you can quickly wrap it in Python, and create an installable Python Package. More information:

Please let us know if you have any questions.

Thanks @matt
actually my custom made metric is implemented in python. Do I still need to create an installable python package?

1 Like

@matt.mccormick
I was wondering if there is any update on this issue?
Is there any python callable (function) for the optimizer interface right now?

@sedghi There is not a python callable (function) interface to supply your own method right now, but that is a great idea. @pieper has been thinking about it, too.

I don’t think it is that hard to implement. What do you think about an itk.PythonImageRegistrationMetricv4 class? This class would be similar to itk.ImageToImageMetricv4, but it would have additional methods,

  • GetValuePythonCallback
  • GetDerivativePythonCallback
  • GetValueAndDerivativePythonCallback

These methods would be passed Python functions that accept the ImageToImageMetricv4 as an argument and would need to return required value and derivative values.

1 Like

Sounds great @matt.mccormick! Yes, @sedghi and I worked together looking into this so hopefully he can let us know if these methods would be enough to cover the use case.

1 Like

Any progress on this front?

I created this issue for tracking:

Note that we have similar functionality to define an image filter in Python:

1 Like