[Insight-users] How to register 2D RGB images

Jinzhong Yang jinzhong.yang at ieee.org
Mon Jan 14 11:53:44 EST 2008


I guess the problem is the metric you used to compare two RGB pixels. You
are not able to use class itkMeanSquaresImageToImageMetric to compare two
pixels in vector format. There is an example to register two RGB images:


http://www.seas.upenn.edu/~jtduda/itkvector.html


Good luck,
Jinzhong


On Jan 14, 2008 9:26 AM, chunfang wang <wchunfang at gmail.com> wrote:

> Hello Luis,
>
> I am a new user of itk, but no one in my lab have used it. So, when some
> problems comes, I am so sad.
> Looking forward of your help~~~
>
> I have some problems in the registration of RGB images.
> Now I explain my problems in detail:
>
> my work is to register two RGB images using the CenteredRigid2DTransform
> I have set the VectorResampleFilter  and VectorInterpolater
> but still the complier error is
>
> d:\program files\itk\insighttoolkit-3.4.0\code\common\itkCovariantVector.h(75)
> : error C2039: 'RealType' : is not a member of 'itk::NumericTraits<T>'
> 1>        with
> 1>        [
> 1>            T=itk::RGBPixel<double>
> 1>        ]
> 1>        D:\program files\itk\InsightToolkit-
> 3.4.0\Code\Common\itkPixelTraits.h(39) : see reference to class template
> instantiation 'itk::CovariantVector<T,NVectorDimension>' being compiled
> 1>        with
> 1>        [
> 1>            T=itk::RGBPixel<double>,
> 1>            NVectorDimension=2
> 1>        ]
>
> I don't know how to settle this problem, please give me some help!
> thanks very much
>
> my code is just refied the examples in itk
>
> #include "itkImageRegistrationMethod.h"
> #include "itkMeanSquaresImageToImageMetric.h"
> #include "itkVectorLinearInterpolateImageFunction.h"
> #include "itkRegularStepGradientDescentOptimizer.h "
> #include "itkImage.h"
> #include "itkRGBPixel.h"
> #include "itkCenteredRigid2DTransform.h"
>
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
>
> #include "itkVectorResampleImageFilter.h"
> #include "itkSubtractImageFilter.h"
> #include "itkRescaleIntensityImageFilter.h"
>
> int main( int argc, char *argv[] )
> {
>  if( argc < 4 )
>  {
>   std::cerr << "Missing Parameters " << std::endl;
>   std::cerr << "Usage: " << argv[0];
>   std::cerr << " fixedImageFile  movingImageFile ";
>   std::cerr << " outputImagefile  [differenceAfterRegistration] ";
>   std::cerr << " [differenceBeforeRegistration] ";
>   std::cerr << " [initialStepLength] "<< std::endl;
>   return EXIT_FAILURE;
>  }
>
>  const    unsigned int    Dimension = 2;
>  typedef  itk::RGBPixel< unsigned char >    PixelType;
>
>  typedef itk::Image< PixelType, Dimension >  FixedImageType;
>  typedef itk::Image< PixelType, Dimension >  MovingImageType;
>  typedef itk::CenteredRigid2DTransform< double > TransformType;
>
>  typedef itk::RegularStepGradientDescentOptimizer       OptimizerType;
>  typedef itk::MeanSquaresImageToImageMetric<
>   FixedImageType,
>   MovingImageType >    MetricType;
>  typedef itk:: VectorLinearInterpolateImageFunction<
>   MovingImageType,
>   double          >    InterpolatorType;
>  typedef itk::ImageRegistrationMethod<
>   FixedImageType,
>   MovingImageType >    RegistrationType;
>
>  MetricType::Pointer         metric        = MetricType::New();
>  OptimizerType::Pointer      optimizer     = OptimizerType::New();
>  InterpolatorType::Pointer   interpolator  = InterpolatorType::New();
>  RegistrationType::Pointer   registration  = RegistrationType::New();
>
>  registration->SetMetric(        metric        );
>  registration->SetOptimizer(     optimizer     );
>  registration->SetInterpolator(  interpolator  );
>
>
>  TransformType::Pointer  transform = TransformType::New();
>  registration->SetTransform( transform );
>
>
>  typedef itk::ImageFileReader< FixedImageType  > FixedImageReaderType;
>  typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;
>
>  FixedImageReaderType::Pointer  fixedImageReader  =
> FixedImageReaderType::New();
>  MovingImageReaderType::Pointer movingImageReader =
> MovingImageReaderType::New();
>
>  fixedImageReader->SetFileName(  argv[1] );
>  movingImageReader->SetFileName( argv[2] );
>
>
>  registration->SetFixedImage(    fixedImageReader->GetOutput()    );
>  registration->SetMovingImage(   movingImageReader->GetOutput()   );
>  fixedImageReader->Update();
>
>  registration->SetFixedImageRegion(
>   fixedImageReader->GetOutput()->GetBufferedRegion() );
>  fixedImageReader->Update();
>  movingImageReader->Update();
>
>  typedef FixedImageType::SpacingType    SpacingType;
>  typedef FixedImageType::PointType      OriginType;
>  typedef FixedImageType::RegionType     RegionType;
>  typedef FixedImageType::SizeType       SizeType;
>  FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput();
>
>  const SpacingType fixedSpacing = fixedImage->GetSpacing();
>  const OriginType  fixedOrigin  = fixedImage->GetOrigin();
>  const RegionType  fixedRegion  = fixedImage->GetLargestPossibleRegion();
>  const SizeType    fixedSize    = fixedRegion.GetSize();
>
>  TransformType::InputPointType centerFixed;
>
>  centerFixed[0] = fixedOrigin[0] + fixedSpacing[0] * fixedSize[0] / 2.0;
>  centerFixed[1] = fixedOrigin[1] + fixedSpacing[1] * fixedSize[1] / 2.0;
>
>  MovingImageType::Pointer movingImage = movingImageReader->GetOutput();
>
>  const SpacingType movingSpacing = movingImage->GetSpacing();
>  const OriginType  movingOrigin  = movingImage->GetOrigin();
>  const RegionType  movingRegion  =
> movingImage->GetLargestPossibleRegion();
>  const SizeType    movingSize    = movingRegion.GetSize();
>
>  TransformType::InputPointType centerMoving;
>
>  centerMoving[0] = movingOrigin[0] + movingSpacing[0] * movingSize[0] /
> 2.0;
>  centerMoving[1] = movingOrigin[1] + movingSpacing[1] * movingSize[1] /
> 2.0;
>
>  transform->SetCenter( centerFixed );
>  transform->SetTranslation( centerMoving - centerFixed );
>  transform->SetAngle( 0.0 );
>
>
>  registration->SetInitialTransformParameters( transform->GetParameters()
> );
>
>  // Software Guide : BeginCodeSnippet
>  typedef OptimizerType::ScalesType       OptimizerScalesType;
>  OptimizerScalesType optimizerScales( transform->GetNumberOfParameters()
> );
>  const double translationScale = 1.0 / 1000.0;
>
>  optimizerScales[0] = 1.0;
>  optimizerScales[1] = translationScale;
>  optimizerScales[2] = translationScale;
>  optimizerScales[3] = translationScale;
>  optimizerScales[4] = translationScale;
>
>  optimizer->SetScales( optimizerScales );
>
>  double initialStepLength = 0.1;
>  // Software Guide : EndCodeSnippet
>
>  if( argc > 6 )
>  {
>   initialStepLength = atof( argv[6] );
>  }
>
>  // Software Guide : BeginCodeSnippet
>  optimizer->SetRelaxationFactor( 0.6 );
>  optimizer->SetMaximumStepLength( initialStepLength );
>  optimizer->SetMinimumStepLength( 0.001 );
>  optimizer->SetNumberOfIterations( 200 );
>  // Software Guide : EndCodeSnippet
>
>
>  // Create the Command observer and register it with the optimizer.
>  //
>  CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();
>  optimizer->AddObserver( itk::IterationEvent(), observer );
>
>  try
>  {
>   registration->StartRegistration();
>  }
>  catch( itk::ExceptionObject & err )
>  {
>   std::cerr << "ExceptionObject caught !" << std::endl;
>   std::cerr << err << std::endl;
>   return EXIT_FAILURE;
>  }
>
>  OptimizerType::ParametersType finalParameters =
>   registration->GetLastTransformParameters();
>
>  const double finalAngle           = finalParameters[0];
>  const double finalRotationCenterX = finalParameters[1];
>  const double finalRotationCenterY = finalParameters[2];
>  const double finalTranslationX    = finalParameters[3];
>  const double finalTranslationY    = finalParameters[4];
>
>  const unsigned int numberOfIterations = optimizer->GetCurrentIteration();
>
>  const double bestValue = optimizer->GetValue();
>
> typedef itk::VectorResampleImageFilter<
>   MovingImageType,
>   FixedImageType >    ResampleFilterType;
>
>  TransformType::Pointer finalTransform = TransformType::New();
>
>  finalTransform->SetParameters( finalParameters );
>
>  ResampleFilterType::Pointer resample = ResampleFilterType::New();
>
>  resample->SetTransform( finalTransform );
>  resample->SetInput( movingImageReader->GetOutput() );
>
>  resample->SetSize(    fixedImage->GetLargestPossibleRegion().GetSize() );
>  resample->SetOutputOrigin(  fixedImage->GetOrigin() );
>  resample->SetOutputSpacing( fixedImage->GetSpacing() );
>  resample->SetDefaultPixelValue( 100 );
>
>  typedef itk::ImageFileWriter< FixedImageType >  WriterFixedType;
>
>  WriterFixedType::Pointer      writer =  WriterFixedType::New();
>
>  writer->SetFileName( argv[3] );
>
>  writer->SetInput( resample->GetOutput()   );
>
>  try
>  {
>   writer->Update();
>  }
>  catch( itk::ExceptionObject & excp )
>  {
>   std::cerr << "ExceptionObject while writing the resampled image !" <<
> std::endl;
>   std::cerr << excp << std::endl;
>   return EXIT_FAILURE;
>  }
> }
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20080114/e938b65f/attachment.html


More information about the Insight-users mailing list