[Insight-users] Pixel difference between two images

Bill Lorensen bill.lorensen at gmail.com
Mon Oct 10 12:11:30 EDT 2011


You needed to specify the region and interpolator.

This should work. I'll add it as a wiki example. Supply two images on
the command line. If you repeat the same image, the results should be
0.

Bill
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkMeanSquaresImageToImageMetric.h"
#include "itkLinearInterpolateImageFunction.h"
#include "itkIdentityTransform.h"

int main(int argc, char *argv[])
{
 typedef itk::Image< double, 2 >         ImageType;
 typedef itk::ImageFileReader<ImageType> ReaderType;

 if (argc < 3)
   {
   std::cout << "Usage: " << argv[0] << " imageFile1 imageFile2" << std::endl;
   return EXIT_FAILURE;
   }
 ReaderType::Pointer fixedReader = ReaderType::New();
 fixedReader->SetFileName(argv[1]);
 fixedReader->Update();

 ReaderType::Pointer movingReader = ReaderType::New();
 movingReader->SetFileName(argv[2]);
 movingReader->Update();

 ImageType::Pointer fixedImage = fixedReader->GetOutput();
 ImageType::Pointer movingImage = movingReader->GetOutput();

 typedef itk::MeanSquaresImageToImageMetric < ImageType , ImageType >
                                               MetricType;
 typedef itk::LinearInterpolateImageFunction<ImageType, double >
                                               InterpolatorType;
 typedef itk::IdentityTransform < double , 2 > TransformType;

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

 InterpolatorType::Pointer interpolator = InterpolatorType::New();
 interpolator->SetInputImage( fixedImage );

 metric->SetFixedImage( fixedImage );
 metric->SetMovingImage( movingImage );
 metric->SetFixedImageRegion( fixedImage->GetLargestPossibleRegion() );
 metric->SetInterpolator( interpolator.GetPointer() );
 metric->SetTransform( transform );
 metric->SetInterpolator( interpolator );

 TransformType::ParametersType params;

 metric->Initialize();
 std::cout << metric->GetValue( params ) << std::endl ;

 return EXIT_SUCCESS;
}


On Wed, Oct 5, 2011 at 5:46 PM, soheilghafurian
<soheilghafurian at yahoo.com> wrote:
> Hi Cori. I made the changes you said, but I still get the same error:
>
> Debug Error!
> This application has requested the Runtime to terminate it in an unusal way.
>
> here is the code ( the previous one + two new corrections you made) :
>
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include <itkMeanSquaresImageToImageMetric.h>
> #include <itkIdentityTransform.h>
>
> #include "QuickView.h"
>
> using namespace std ;
>
> int main()
> {
>  typedef itk::Image< double, 2 >         ImageType;
>  typedef itk::ImageFileReader<ImageType> ReaderType;
>
>  ReaderType::Pointer reader = ReaderType::New();
>  reader->SetFileName("Image.png");
>  reader->Update() ;
>
>  QuickView viewer;
>  viewer.AddImage<ImageType>(reader->GetOutput());
>
>
>  ImageType::Pointer FixedImage = reader->GetOutput() ;
>  ImageType::Pointer MovingImage = reader->GetOutput() ;
>
>  typedef itk::MeanSquaresImageToImageMetric < ImageType , ImageType >
> MetricType ;
>  typedef itk::IdentityTransform < double , 2 > TransformType ;
>
>  MetricType::Pointer metric = MetricType::New() ;
>  TransformType::Pointer transform = TransformType::New() ;
>
>  metric->SetFixedImage( FixedImage ) ;
>  metric->SetMovingImage( MovingImage ) ;
>  metric->SetTransform( transform ) ;
>
>  TransformType::ParametersType params ;
>
>  metric->Initialize() ;
>  cout<<endl<< metric->GetValue( params ) << endl ;
>
> //  viewer.Visualize();
>
>  return EXIT_SUCCESS;
> }
>
> --
> View this message in context: http://itk-insight-users.2283740.n2.nabble.com/Pixel-difference-between-two-images-tp6832343p6863968.html
> Sent from the ITK Insight Users mailing list archive at Nabble.com.
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>


More information about the Insight-users mailing list