Changes In ITK Mattes Mutual Information Metric

You mean at git hub?

You could look at the files’ blame on your local computer. But yes, GitHub has an integrated blame tool as well.

I’m not familiar with that tool. I looked it over, but did not get the point.
How can I use blame to help me?
Thanks again!

Looking at the blame tells you that @stnava contributed to that class. If you can find more people who wrote the class, they might be able to help you better than me.

Auhh, I got it!
Makes sense!
Yeah lets see if anyone else can help me!
Thanks.

@dzenanz, can you please confirm the following question:

1- The bool member (this->m_UseExplicitPDFDerivatives) means that it will use b-spline functions as the kernel density function when it is TRUE? I’m guessing that because the papers say that b-splines have explicit derivatives.

I don’t know. Somebody else might know :smiley:

That’s ok… Hahah that code is a lot of organized mess!

@dzenanz, I’m getting further.
I need to understand the this->m_UseExplicitPDFDerivatives, but it is not so demanding right now.

Now, I need to know some aspects related to C++ and ITK architecture. If you can help me again, I’ll be grateful.

1 - I need to know how to pass an additional variable to the metric class (.hxx) from my main .cpp during the execution. The new entropy needs an additional variable x. And I want to send the x value during the execution.

2 - I created the new .h and .hxx by editing itkMattes[…].h and itkMattes[…].h.
Now, I include the new .h class in the beggining of the main file (.cpp) and create the objects and so on… everything nice and smooth. But, in the main class, when I set the metric to the registration object, it shows an error:

ImageRegistration4.cxx:153: error: no matching function for call to 
‘itk::ImageRegistrationMethodv4<itk::Image<float, 2u>, itk::Image<float, 2u>, 
itk::TranslationTransform<double, 2u> 
>::SetMetric(itk::MachadoMutualInformationImageToImageMetric<itk::Image<float, 2u>, 
itk::Image<float, 2u> >::Pointer&)’
registration->SetMetric(metric);
                              ^

Thanks again!

  1. make m_X a member, and add public setter and getter (SetX and GetX). You can use macros for that.
  2. your metric must derive from ObjectToObjectMetricBaseTemplate. MattesMutualInformationImageToImageMetricv4 derives from ImageToImageMetricv4, which derives from ObjectToObjectMetric, which derives from ObjectToObjectMetricBaseTemplate.

Beware that MattesMutualInformationImageToImageMetric (without v4 in the name) derives from ImageToImageMetric, which derives from SingleValuedCostFunction, which derives from CostFunction, which derives from CostFunctionTemplate, which derives from Object. This means that v4 registration framework is largely incompatible with v3 framework.

1 Like

Perfect. I’ll work on those details carefully.
I thought I was already sure that I was working with V4 versions, but now I have to double check.

make m_X a member, and add public setter and getter ( SetX and GetX ). You can use [macros] for that.

You mean, create a variable in the “.h” class and create getters and setters in both “.h” and “.hxx” classes?

I’ll work on that.
Thanks!

With standard macro approach, you don’t need any code in .hxx. A use sample is here and here.

Great. I did it all. No errors, so far. However, I’m not being able to RUN the whole code.
I’m getting stuck in the following statement:

if( this->m_JointPDFSum < itk::NumericTraits< PDFValueType >::epsilon() )
  {
   itkExceptionMacro("Joint PDF summed to zero");
   }

from the […]Machado[…].hxx class.

I checked the whole class, back and fourth, and found that m_JointPDFSum
is calculated in the same class, inside the method GetValueCommonAfterThreadedExecution(), as follows:

// Sum of this threads domain into the this->m_JointPDFSum that covers that part of the domain.
 JointPDFValueType const * pdfPtr = pdfPtrStart;
 CompensatedSummation< PDFValueType > jointPDFSum;
 for( SizeValueType i = 0; i < numberOfVoxels; ++i )
 {
  jointPDFSum += *( pdfPtr++ );
 }
 this->m_JointPDFSum = jointPDFSum.GetSum();

But I looked around and, I think, it is not being calculated at the right execution time. I don’t know. Could you help me by checking it?

The ERROR message I get is:

0   -1   [NaN, NaN]
ExceptionObject caught !

itk::ExceptionObject (0x28c4ef0)
Location: "unknown" 
File: /home/leonardo/Desktop/Modulos- Source/Modulos_to_ITK/Registration/MultiModalityMachadoMI/itkMachadoMutualInformationImageToImageMetricv4.hxx
Line: 280
Description: itk::ERROR: MachadoMutualInformationImageToImageMetricv4(0x28d1320): Joint PDF 
summed to zero


07:45:24: /home/leonardo/Desktop/Modulos- 
Source/Modulos_to_ITK/Registration/MultiModalityMachadoMI/build/ImageRegistration4 exited with 
code 1

Thanks again!

This usually happens when there is no overlap between the images, which mostly happens when the initial transform is not good. Double check that before any other debugging.

Hum… I see.

Well, I’m using the registration example ImageRegistration4.cpp
the same used to test Mattes metric. And actually I did not change any aspect at all, except the metric calling from Mattes metric to Machado Metric.h files…

Those are the images fixed and moving respectively.

BrainT1SliceBorder20.png
BrainProtonDensitySliceShifted13x17y.png

BrainT1SliceBorder20BrainProtonDensitySliceShifted13x17y

Maybe some part of the code is not executing at all. Check whether you correctly override the respective functions. Compile your code with highest level of warning messages, examine them etc. Debug it :smiley:

Yeah! I’ll work on it!!
Thanks again!

Guys, I did it!
Finally, it worked as expected. The last problems I mentioned were related to my bad editions and systematical errors.
Thanks a lot… @dzenanz! Your help was fundamental for that!
Now I have to optimize the method but… essentially it’s working!

Many, many Thanks!

1 Like

Before (left) and After registration (right):
CheckerboardBefore CheckerboardAfter

Good to hear it worked. Are you going to share your code?