[ITK] Problem with normalized mutual information

Constantinus Spanakis c.spanakis83 at gmail.com
Fri Oct 7 18:48:22 EDT 2016


Hello I tried to modify the MutualInformationImageToImageFilter example and
tried to make it read images and calculate their normalized mutual
informaion. Here is the code:

#include "itkMutualInformationImageToImageMetric.h"
#include "itkRandomImageSource.h"
#include "itkTranslationTransform.h"
#include"itkCenteredRigid2DTransform.h"
#include "itkLinearInterpolateImageFunction.h"
#include"itkImageFileReader.h"
#include"itkNormalizedMutualInformationHistogramImageToImageMetric.h"


typedef itk::Image< unsigned char, 2>  ImageType;
//typedef itk::Image< float, 2> ImageType;

int main( int argc, char *argv[] )
{

const    unsigned int    ImageDimension = 2;
typedef  signed short    PixelType;
typedef itk::Image<PixelType, ImageDimension> FixedImage;
typedef itk::Image<PixelType, ImageDimension> MovingImage;

typedef itk::ImageFileReader<FixedImage> FixedImageTypeReader;
typedef itk::ImageFileReader<MovingImage> MovingImageTypeReader;

FixedImageTypeReader::Pointer fixedreader = FixedImageTypeReader::New();
MovingImageTypeReader::Pointer movingreader = MovingImageTypeReader::New();

fixedreader->SetFileName(argv[1]);
movingreader->SetFileName(argv[2]);

fixedreader->Update();
movingreader->Update();
FixedImage::Pointer fixedImage = fixedreader->GetOutput();
MovingImage::Pointer movingImage = movingreader->GetOutput();


  typedef itk::TranslationTransform<double, 2> TranslationTransformType; //
This cannot be float for some reason?
  TranslationTransformType::Pointer transform =
TranslationTransformType::New();

  /*typedef itk::MutualInformationImageToImageMetric<FixedImage,
MovingImage >    MetricType;*/

  typedef
itk::NormalizedMutualInformationHistogramImageToImageMetric<FixedImage,
MovingImage> MetricType;


  MetricType::Pointer metric = MetricType::New();

  metric->SetTransform(transform);


  metric->SetFixedImageRegion(fixedImage->GetLargestPossibleRegion());

  MetricType::HistogramType::SizeType histogramSize;
  histogramSize.SetSize(2);
  histogramSize[0] = 64;
  histogramSize[1] = 64;

  metric->SetHistogramSize(histogramSize);

  const unsigned int numberOfParameters =
transform->GetNumberOfParameters();
  typedef MetricType::ScalesType ScalesType;
  ScalesType scales(numberOfParameters);

  scales.Fill(1.0);

  metric->SetDerivativeStepLengthScales(scales);

  metric->SetFixedImage(fixedImage);
  metric->SetMovingImage(movingImage);

  metric->SetFixedImageRegion(fixedImage->GetLargestPossibleRegion());

  itk::LinearInterpolateImageFunction<MovingImage, double>::Pointer
interpolator = itk::LinearInterpolateImageFunction<MovingImage,
double>::New();
  interpolator->SetInputImage(fixedImage);
  metric->SetInterpolator(interpolator);

  TranslationTransformType::ParametersType parameters;
  parameters.SetSize(2);
  parameters.Fill(0);
  std::cout << "parameters: " << parameters << std::endl;
  printf("before problem\n");
  MetricType::MeasureType value = metric->GetValue(parameters);
  printf("after problem\n");
  std::cout << "Value: " << value << std::endl;

  return EXIT_SUCCESS;
}

The problem is that every time I call metric->GetValue(parameters); the
programme crashes. What could be the problem???
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20161008/dcb8d137/attachment.html>


More information about the Community mailing list