[ITK] problem with calculating Normalized Mutual Information

Dženan Zukić dzenanz at gmail.com
Tue Nov 22 09:03:34 EST 2016


Hi Constantinus,

the line
RigidTransformType::OutputVectorType translation =
rigidtransform->GetTranslation();
copies the translation into a new variable. Changing the new variable
translation leaves the rigidtransform totally unaffected. After setting
values to translation, you should do something like
rigidtransform->SetTranslation(translation);

Regards,
Dženan

On Tue, Nov 22, 2016 at 2:52 AM, Constantinus Spanakis <
c.spanakis83 at gmail.com> wrote:

> Hello. I want to caculate mutual information between 2 images. The problem
> is that the outcome changes only when the angle of rotation changes. What
> could be the problem?
>
> #include "itkMutualInformationImageToImageMetric.h"
> #include "itkRandomImageSource.h"
> #include "itkTranslationTransform.h"
> #include"itkCenteredRigid2DTransform.h"
> #include "itkCenteredTransformInitializer.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  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;
>
> 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::CenteredRigid2DTransform<double> RigidTransformType;
>   typedef itk::CenteredTransformInitializer < RigidTransformType,
> FixedImage, MovingImage> RigidTransformInitializerType;
>
>
>   RigidTransformType::Pointer rigidtransform = RigidTransformType::New();
>   RigidTransformInitializerType::Pointer initializer =
> RigidTransformInitializerType::New();
>
>   initializer->SetTransform(rigidtransform);
>   initializer->SetFixedImage(fixedreader->GetOutput());
>   initializer->SetMovingImage(movingreader->GetOutput());
>   initializer->GeometryOn();
>   initializer->InitializeTransform();
>
>   rigidtransform->SetAngleInDegrees(atof(argv[3]));
>
>   RigidTransformType::OutputVectorType translation = rigidtransform->
> GetTranslation();
>   translation[0] = atof(argv[4]);
>   translation[1] = atof(argv[5]);
>
>
>
>   /*typedef itk::MutualInformationImageToImageMetric<FixedImage,
> MovingImage >    MetricType;*/
>
>   typedef itk::NormalizedMutualInformationHistogramImageToImageMetric<FixedImage,
> MovingImage> MetricType;
>
>
>   MetricType::Pointer metric = MetricType::New();
>
>   metric->SetTransform(rigidtransform);
>
>
>   metric->SetFixedImageRegion(fixedImage->GetLargestPossibleRegion());
>   MetricType::MeasurementVectorType lower, upper;
>   lower.SetSize(2);
>   lower.Fill(0);
>
>   upper.SetSize(2);
>   upper.Fill(255);
>
>   metric->SetLowerBound(lower);
>   metric->SetUpperBound(upper);
>
>   MetricType::HistogramType::SizeType histogramSize;
>   histogramSize.SetSize(2);
>   histogramSize[0] = 128;
>   histogramSize[1] = 128;
>
>   metric->SetHistogramSize(histogramSize);
>
>   const unsigned int numberOfParameters = rigidtransform->
> 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);
>
>
>
>   std::cout << fixedreader->GetOutput()->GetLargestPossibleRegion().
> GetSize();
>   RigidTransformType::InputPointType m = rigidtransform->GetCenter();
>   m[0] = 300;
>   m[1] = 300;
>   rigidtransform->SetCenter(m);
>   std::cout << "parameters: " << rigidtransform->GetParameters() <<
> std::endl;
>   std::cout << "pcenter: " << m << std::endl;
>
>   metric->SetTransformParameters(rigidtransform->GetParameters());
>   MetricType::MeasureType value = metric->GetValue(
> rigidtransform->GetParameters());
>
>   std::cout << "Value: " << value << std::endl;
>
>   return EXIT_SUCCESS;
> }
>
>
> _______________________________________________
> 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/20161122/33c0777c/attachment-0001.html>


More information about the Community mailing list