How to get metric value for a given set of transform parameters in ITK V4?

I’m trying to plot a profile of cost function (or metric) values for a 3D image registration study. This can be done easily in ITK V3 with the itk::ImageToImageMetric::GetValue(const ParametersType &parameters) function. So I can change the parameters in the argument to probe the cost function in the parametric space. However in ITK V4, only the function itk::ImageToImageMetricv4::GetValue() exists with no argument taken. I’m wondering how to get it done in the new registration frame. Any hints or examples? I’ll appreciate it very much if anyone could help!

ImageToImageMetricv4 inherits SetParameters(). You should call that prior to calling GetValue().

1 Like

Thank you very much, I found the answer by myself before reading your message.

Though, there is a problem in my code. My loop stops when the following error is raise :

RuntimeError: /work/ITK-source/ITK/Modules/Registration/Common/include/itkMeanSquaresImageToImageMetric.hxx:126:
ITK ERROR: MeanSquaresImageToImageMetric(0x5631eee2a330): Too many samples map outside moving image buffer: 0 / 2215440

How can I keep running for other values after one of the tuple (x,y) failed?

Use try/catch syntax to avoid that. Pseudocode:

for x ...
  for y ...
    try
    {
    metricXY = evaluate(fixedImage, movingImage, x, y);
    metrics[y][x] = metricXY;
    }
    catch(const itk::Exception& exc)
    {
    std::cout<<... // or just ignore it
    }