[ITK] Problem regarding the computation of Normalized Mutual Information

Francois Budin francois.budin at kitware.com
Thu May 11 17:00:37 EDT 2017


Hello Constantinus,

You need to initialize the metric first.

You can add:
      metric->Initialize();
before calling your "test()" function.

Hope this helps,
Francois

On Thu, May 11, 2017 at 9:07 AM, Constantinus Spanakis <
c.spanakis83 at gmail.com> wrote:

> Hello. I want to compute the Normalized Mutual information of two images
> when I give a specific transformation. Below is my code.
>
> #include "itkMutualInformationImageToImageMetric.h"
> #include "itkRandomImageSource.h"
> #include "itkTranslationTransform.h"
> #include"itkCenteredRigid2DTransform.h"
> #include "itkCenteredTransformInitializer.h"
> #include "itkLinearInterpolateImageFunction.h"
> #include"itkImageFileReader.h"
> #include"itkNormalizedMutualInformationHistogramImageToImageMetric.h"
> #include "itkMattesMutualInformationImageToImageMetric.h"
> #include "itkMutualInformationImageToImageMetric.h"
>
> # include <cstdlib>
> # include <iostream>
> # include <iomanip>
> # include <fstream>
> # include <iomanip>
> # include <cmath>
> # include <ctime>
> # include <cstring>
> # include <random>
>
>
>
>
> using namespace std;
>
>
>
> int main(int argc, char *argv[]);
>
>
>
>
>
> const    unsigned int    ImageDimension = 2;
> typedef  unsigned char    PixelType;
> typedef itk::Image<PixelType, ImageDimension> FixedImage;
> typedef itk::Image<PixelType, ImageDimension> MovingImage;
>
> typedef itk::ImageFileReader<FixedImage> FixedImageTypeReader;
> typedef itk::ImageFileReader<MovingImage> MovingImageTypeReader;
>
> typedef itk::CenteredRigid2DTransform<double> RigidTransformType;
>
>
> typedef itk::NormalizedMutualInformationHistogramImageToImageMetric<FixedImage,
> MovingImage> MetricType;
> //typedef itk::MattesMutualInformationImageToImageMetric<FixedImage,
> MovingImage> MetricType;
> //typedef itk::MutualInformationImageToImageMetric<FixedImage,
> MovingImage> MetricType;
>
>
>
> typedef itk::CenteredTransformInitializer<RigidTransformType, FixedImage,
> MovingImage> InitializerType;
>
> RigidTransformType::Pointer rigidtransform;
>
>
>
>
> MetricType::MeasureType test(double *arg , MetricType::Pointer metric){
> MetricType::MeasureType v=0;
> int i;
> double a, e, f;
> a = arg[0] ;
>
> e = arg[1];
> f = arg[2];
> rigidtransform->SetAngle(a);
> RigidTransformType::OutputVectorType t = rigidtransform->GetTranslation();
> t[0] = e;
> t[1] = f;
> rigidtransform->SetTranslation(t);
> RigidTransformType::ParametersType p;
> p.SetSize(5);
> p[0] = a;
> p[1] = 255.5;
> p[2] = 255.5;
> p[3] = e;
> p[4] = f;
>
> metric->UseAllPixelsOn();
> metric->SetTransform(rigidtransform);
>
> cout<<p<<endl;
> return metric->GetValue(p);
> }
>
>
>
>
> int main( int argc, char *argv[] )
> {
>
>
> 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();
>
> MetricType::Pointer metric;
> rigidtransform = RigidTransformType::New();
>
> MetricType::HistogramSizeType h;
> h.SetSize(2);
> h[0] = h[1]=64;
>
>
>
> metric = MetricType::New();
>
> metric->SetTransform(rigidtransform);
> metric->SetHistogramSize(h);
> metric->SetNumberOfFixedImageSamples(10000);
> metric->SetNumberOfSpatialSamples(10000);
> metric->SetFixedImage(fixedImage);
> metric->SetMovingImage(movingImage);
> metric->SetFixedImageRegion(fixedImage->GetLargestPossibleRegion());
>
> const unsigned int numberOfParameters = rigidtransform->
> GetNumberOfParameters();
>
>
>
>
>
> std::cout<<"Spacing: "<<movingImage->GetSpacing()<<", Origin:
> "<<movingImage->GetOrigin()<<", Direction: "<<movingImage->GetDirection()
> <<std::endl;
>
>
>
> itk::LinearInterpolateImageFunction<MovingImage, double>::Pointer
> interpolator = itk::LinearInterpolateImageFunction<MovingImage,
> double>::New();
> interpolator->SetInputImage(movingImage);
> metric->SetInterpolator(interpolator);
>
> InitializerType::Pointer initializer = InitializerType::New();
> initializer->SetTransform(rigidtransform);
> initializer->SetFixedImage(fixedreader->GetOutput());
> initializer->SetMovingImage(movingreader->GetOutput());
> initializer->GeometryOn();
> initializer->InitializeTransform();
>
> std::cout << fixedreader->GetOutput()->GetLargestPossibleRegion().
> GetSize();
> RigidTransformType::InputPointType mc = rigidtransform->GetCenter();
>
> MovingImage::SizeType c = movingreader->GetOutput()->
> GetLargestPossibleRegion().GetSize();
>
>
> rigidtransform->SetCenter(mc);
> std::cout << "parameters: " << rigidtransform->GetParameters() <<
> std::endl;
> std::cout << "pcenter: " << mc << std::endl;
>
> double p[3];
> p[0] = 0.52;
> p[1] = -138;
> p[2] = 52;
>
> std::cout << "Value: " << test(p,metric) << std::endl;
>
>
> return EXIT_SUCCESS;
> }
>
> Whenever I execute the code, I get a strange message (see attached image).
> 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/20170511/38e3fc6a/attachment.html>


More information about the Community mailing list