Dear all,<br><br>I am trying to check the metric (Mattes MI) values between two images, while rotating the one over the other.<br>Therefore I use Euler2DTransform. <br>The results though of the plot aren't the expected.<br>
I am comparing two test images where the one is rotated 10 degrees over the other,<br>and the metric minimum is appeared in the value 1.<br>Do you know what might be the problem, or what should I change in the following code?<br>
<br>Thanks a lot<br>Best Regards<br>Giorgos <br>........................................................................<br>#include "itkImage.h"<br>#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br>
#include "itkMattesMutualInformationImageToImageMetric.h"<br>#include "itkEuler2DTransform.h"<br>
#include "itkLinearInterpolateImageFunction.h"<br><br>int main( int argc, char * argv[] )<br>{<br> if( argc < 3 )<br> {<br> std::cerr << "Usage: " << std::endl;<br> std::cerr << argv[0] << " fixedImage movingImage" << std::endl;<br>
return 1;<br> }<br><br> const unsigned int Dimension = 2;<br> typedef unsigned char PixelType;<br> typedef itk::Image< PixelType, Dimension > ImageType;<br> typedef itk::Image< PixelType, Dimension > ImageType;<br>
typedef itk::ImageFileReader< ImageType > ReaderType;<br><br> ReaderType::Pointer fixedReader = ReaderType::New();<br> ReaderType::Pointer movingReader = ReaderType::New();<br><br> fixedReader->SetFileName( argv[ 1 ] );<br>
movingReader->SetFileName( argv[ 2 ] );<br><br> try <br> {<br> fixedReader->Update();<br> movingReader->Update();<br> }<br> catch( itk::ExceptionObject & excep )<br> {<br> std::cerr << "Exception catched !" << std::endl;<br>
std::cerr << excep << std::endl;<br> }<br><br> typedef itk::MattesMutualInformationImageToImageMetric< ImageType, ImageType > MetricType;<br> MetricType::Pointer metric = MetricType::New();<br>
<br> typedef itk::Euler2DTransform< double > TransformType;<br> TransformType::Pointer transform = TransformType::New();<br><br> typedef itk::LinearInterpolateImageFunction< <br> ImageType, double > InterpolatorType;<br>
InterpolatorType::Pointer interpolator = InterpolatorType::New();<br><br> metric->SetInterpolator( interpolator );<br> metric->SetTransform( transform );<br><br> metric->SetNumberOfHistogramBins( 20 );<br> metric->SetNumberOfSpatialSamples( 10000 );<br>
<br> transform->SetIdentity();<br><br> ImageType::ConstPointer fixedImage = fixedReader->GetOutput();<br> ImageType::ConstPointer movingImage = movingReader->GetOutput();<br><br> metric->SetFixedImage( fixedImage );<br>
metric->SetMovingImage( movingImage );<br><br> metric->SetFixedImageRegion( fixedImage->GetBufferedRegion() );<br><br> try <br> {<br> metric->Initialize();<br> }<br> catch( itk::ExceptionObject & excep )<br>
{<br> std::cerr << "Exception catched !" << std::endl;<br> std::cerr << excep << std::endl;<br> return -1;<br> }<br><br> MetricType::TransformParametersType parameters( transform->GetNumberOfParameters() );<br>
<br> int RangeOfDegrees=50;<br> double RangeInRadians=RangeOfDegrees * atan(1.0)/45.0;<br> <br> for (double i=-RangeInRadians; i<=RangeInRadians; i+=atan(1.0)/45.0)<br> {<br> parameters[0] = i;<br>
parameters[1] = 0;<br> parameters[2] = 0;<br> <br> const double value = metric->GetValue( parameters );<br> double finalAngleInDegrees = i * 45.0 / atan(1.0);<br> std::cout << finalAngleInDegrees << " " << value << std::endl;<br>
}<br> std::cout << std::endl;<br> return 0;<br>}<br>