[ITK] Problem with normalized mutual information

Dženan Zukić dzenanz at gmail.com
Sat Oct 8 15:59:32 EDT 2016


Hi Constantinus,

you did not set lower and upper bounds to the metric's histogram. The
following addition alleviates crashing:
metric->SetLowerBound(histogramSize);
metric->SetUpperBound(histogramSize);

Regards,
Dženan

On Fri, Oct 7, 2016 at 6:48 PM, Constantinus Spanakis <
c.spanakis83 at gmail.com> wrote:

> 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???
>
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20161008/f44144e2/attachment-0001.html>


More information about the Community mailing list