[ITK] Problem with computing Normalized mutual information betwee two images

Constantinus Spanakis c.spanakis83 at gmail.com
Sun Jan 17 14:22:16 EST 2016


Hello. I tried to compute the normalized mutual information between two
images, based on an example at

http://itk.org/Wiki/ITK/Examples/Broken/ImageProcessing/MutualInformationImageToImageFilter
.

I changed the example in order to compute the mutual information between
two images and it worked fine, but when I changed from mutual information
to normalized mutual information I get stuck at getting the value of
normalized mutual information(last line in following code). To be precise,
I get memory access violation, something that didn't happen with mutual
informaion. Here is the code:

const    unsigned int    Dimension = 2;
  typedef  unsigned char   PixelType;

  typedef itk::Image< PixelType, Dimension >  FixedImageType;
  typedef itk::Image< PixelType, Dimension >  MovingImageType;

  typedef itk::CenteredRigid2DTransform< double > TransformType;


  typedef itk::LinearInterpolateImageFunction<
                                    MovingImageType,
                                    double             > InterpolatorType;


  typedef itk::NormalizedMutualInformationHistogramImageToImageMetric2<
                                          FixedImageType,
                                          MovingImageType >    MetricType;

  typedef itk::ImageFileReader<FixedImageType> FixedReaderType;
  typedef itk::ImageFileReader<MovingImageType> MovingReaderType;



  /*Read images*/

  FixedReaderType::Pointer fixedReader = FixedReaderType::New();
  MovingReaderType::Pointer movingReader = MovingReaderType::New();

  fixedReader->SetFileName(argv[1]);
  movingReader->SetFileName(argv[2]);

  fixedReader->Update();
  movingReader->Update();



  /*Set metric*/
  MetricType::Pointer metric = MetricType::New();

  metric->SetFixedImage(fixedReader->GetOutput());
  metric->SetMovingImage(movingReader->GetOutput());

metric->SetFixedImageRegion(fixedReader->GetOutput()->GetLargestPossibleRegion());

  MetricType::HistogramType::SizeType h;
  h.SetSize(2);
  h[0] = h[1] = 128;
  metric->SetHistogramSize(h);

  //metric->SetNumberOfSpatialSamples(1000);

  InterpolatorType::Pointer interp = InterpolatorType::New();
  interp->SetInputImage(movingReader->GetOutput());
  metric->SetInterpolator(interp);

  MetricType::ScalesType scales;
  scales.Fill(1.0);
  metric->SetDerivativeStepLengthScales(scales);

  FixedImageType::SizeType s =
fixedReader->GetOutput()->GetLargestPossibleRegion().GetSize();


  /*Set Transform*/
  double c[2];
  c[0] = (s[0] - 1.0) / 2.0;
  c[1] = (s[1] - 1.0) / 2.0;

  TransformType::Pointer transform = TransformType::New();
  metric->SetTransform(transform);
  transform->SetAngle(0.12);

  TransformType::TranslationType t;
  t[0] = t[1] = 10;
  transform->SetTranslation(t);
  transform->SetCenter(c);
  TransformType::ParametersType p;
  p.SetSize(5);
  p.Fill(0.0);
  std::cout << "transformation: " << p<< std::endl;
  std::cout << "Mutual Information: " << metric->GetValue(p) << std::endl;

What could be the problem?
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Το
παρόν email στάλθηκε από ασφαλή υπολογιστή που προστατεύεται από το Avast.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20160117/973ca180/attachment.html>


More information about the Community mailing list