[Insight-users] Re: using itk::MeanSquaresImageToImageMetric code

Luis Ibanez luis.ibanez at kitware.com
Sun Jan 20 20:36:38 EST 2008


Hi  hjlin2177



You are right,

The itkIdentityTransform *does not* implement the method

                 GetParameters()


mainly because... no parameters are needed to define an
identity transform.

Therefore you are getting the exception that is thrown
from the base class itkTransform in lines 154-155.



What you may want to do in this case is to replace the
IdentityTransform with a TranslationTransform and to
initialize the new transform by calling


        transform->SetIdentity()


This should behave just as an Identity transform.


Please let us know if you find any other problems,


    Thanks


       Luis


---------------------------
hjlin2177 at hotmail.com wrote:
> Hey Luis,
> 
> I am having trouble with the following code. I am trying to compare the 2 images after registration using MeaSquaresImageToImageMetric code. Compilation of the following code was successful. But when I try to run it, I get the following error:
> 
> Error: IdentityTransform(0x81282d8): Subclasses should override this method.
> 
> I think the problem is at the line
> const double error = metric->GetValue( transform->GetParameters() ); 
> but I am not sure how to fix it. 
> 
> Please help. 
> 
> #include <itkImage.h>
> #include <itkCommand.h>
> #include <itkImageFileReader.h>
> #include <itkImageFileWriter.h>
> #include <itkCastImageFilter.h>
> #include <itkMeanSquaresImageToImageMetric.h>
> #include <itkIdentityTransform.h>
> #include <itkLinearInterpolateImageFunction.h>
> 
> int main( int argc, char *argv[] )
> {
>   if ( argc < 3 )
>   {
>     std::cerr << "Missing Parameters " << std::endl;
>     std::cerr << "Usage: " << argv[0];
>     std::cerr << "fixedImageFile movingImageFile" << std::endl;
>     std::cerr << "Typical: 060105_seg.vtk 060114_seg.vtk" << std::endl;
>     return EXIT_FAILURE;
>   }
> 
>   const unsigned int Dimension = 3;
>   typedef short PixelType;
>   typedef short OutputPixelType;
>   typedef short InternalPixelType;
>   typedef itk::Vector< float, Dimension > VectorPixelType;
> 
>   typedef itk::Image< PixelType, Dimension > FixedImageType;
>   typedef itk::Image< PixelType, Dimension > MovingImageType;
>   typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
>   typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
> 
>   typedef itk::ImageFileReader< FixedImageType > FixedImageReaderType;
>   typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;
>   typedef itk::CastImageFilter< FixedImageType, InternalImageType > FixedImageCasterType;
>   typedef itk::CastImageFilter< MovingImageType, InternalImageType > MovingImageCasterType;
>   typedef itk::IdentityTransform< double, Dimension > TransformType;
>   typedef itk::MeanSquaresImageToImageMetric< InternalImageType, InternalImageType > MetricType;
>   typedef itk::LinearInterpolateImageFunction < InternalImageType, double > InterpolatorType;
>   typedef itk::CastImageFilter< InternalImageType, OutputImageType > CastFilterType;
> 
>   FixedImageReaderType::Pointer fixedImageReader = FixedImageReaderType::New();
>   MovingImageReaderType::Pointer movingImageReader = MovingImageReaderType::New();
>   fixedImageReader->SetFileName( argv[1] );
>   movingImageReader->SetFileName( argv[2] );
> 
>   FixedImageCasterType::Pointer fixedImageCaster = FixedImageCasterType::New();
>   MovingImageCasterType::Pointer movingImageCaster = MovingImageCasterType::New();
>   fixedImageCaster->SetInput( fixedImageReader->GetOutput() );
>   movingImageCaster->SetInput( movingImageReader->GetOutput() );
>   fixedImageCaster->Update();
>   movingImageCaster->Update();
> 
>   TransformType::Pointer transform = TransformType::New();
>   MetricType::Pointer metric = MetricType::New()
>   InterpolatorType::Pointer interpolator = InterpolatorType::New();
>   InternalImageType::Pointer fixedImage = fixedImageCaster->GetOutput();
>   InternalImageType::Pointer movingImage = movingImageCaster->GetOutput();
>   metric->SetFixedImage( fixedImage );
>   metric->SetMovingImage( movingImage );
>   metric->SetTransform( transform );
>   metric->SetInterpolator( interpolator );
>   metric->SetFixedImageRegion( movingImage->GetBufferedRegion() );
> 
>   const double error = metric->GetValue();
>   std::cout << "Error between two images is == " << error << std::endl;
> 
>   return EXIT_SUCCESS;
> }
> 
> 


More information about the Insight-users mailing list