CSci 6971: Image Registration Lecture 10: Registration Components February 13, 2004 Prof. Chuck Stewart, RPI Dr. Luis Ibanez, Kitware Prof. Chuck Stewart, RPI Dr. Luis Ibanez, Kitware
Image RegistrationLecture 10 2 Registration Components Basic Registration Framework
Image RegistrationLecture 10 3 Image Registration Framework Fixed Image Moving Image Metric Transform Interpolator Optimizer Parameters
Image RegistrationLecture 10 4 Image Registration #include ”itkImageRegistrationMethod.h” #include ”itkTranslationTransform.h” #include ”itkMeanSquaresImageToImageMetric.h” #include ”itkLinearInterpolateImageFunction.h” #include ”itkRegularStepGradientDescentOptimizer.h” #include ”itkImage.h” #include ”itkImageFileReader.h” #include ”itkImageFileWriter.h” #include ”itkResampleImageFilter.h”
Image RegistrationLecture 10 5 Image Registration const unsigned int Dimension = 2; typedef unsigned char PixelType; typedef itk::Image FixedImageType; typedef itk::Image MovingImageType; typedef itk::TranslationTransform TransformType; typedef itk::RegularStepGradientDescentOptimizer OptimizerType; typedef itk::LinearInterpolateImageFunction InterpolatorType; typedef itk::MeanSquaresImageToImageMetric MetricType; typedef itk::ImageRegistrationMethod RegistrationType;
Image RegistrationLecture 10 6 Image Registration TransformType::Pointer transform = TransformType::New(); OptimizerType::Pointer optimizer = OptimizerType::New(); InterpolatorType::Pointer interpolator = InterpolatorType::New(); MetricType::Pointer metric = MetricType::New(); RegistrationType::Pointer registrator = RegistrationType::New(); registrator->SetTransform( transform ); registrator->SetOptimizer( optimizer ); registrator->SetInterpolator( interpolator ); registrator->SetMetric( metric ); registrator->SetFixedImage( fixedImageReader->GetOutput() ); registrator->SetMovingImage( movingImageReader->GetOutput() );
Image RegistrationLecture 10 7 Image Registration registrator->SetFixedImageRegion( fixedImageReader->GetOutput()->GetBufferedRegion() ); typedef RegistrationType::ParametersType ParametersType; transform->SetIdentity(); registrator->SetInitialTransformParameters( transform->GetParameters() ); optimizer->SetMaximumStepLength( 4.00 ); optimizer->SetMinimumStepLength( 0.01 ); optimizer->SetNumberOfIterations( 100 ); optimizer->MaximizeOff();
Image RegistrationLecture 10 8 Image Registration try { registrator->StartRegistration (); } catch( itk::ExceptionObject & excp ) { std::cerr << “Error in registration” << std::endl; std::cerr << excp << std::endl; } transform->SetParameters( registrator->GetLastTransformParameters() );
Image RegistrationLecture 10 9 Image Registration Framework Fixed Image Moving Image Metric Transform Interpolator Optimizer Parameters Resampler Moving Registered
Image RegistrationLecture Image Registration typedef itk::ResampleImageFilter ResamplerType; ResamplerType ::Pointer resampler = ResamplerType::New(); resampler->SetTransform ( transform ); resampler->SetInput( movingImageReader->GetOutput() ); FixedImageType ::Pointer fixedImage = fixedImageReader->GetOutput(); resampler->SetOrigin( fixedImage->GetOrigin() ); resampler->SetSpacing( fixedImage->GetSpacing() ); resampler->SetSize( fixedImage->GetLargestPossibleRegion()->GetSize() ); resampler->Update();
Image RegistrationLecture Image Registration Tracking the Registration Process
Image RegistrationLecture Observing Registration #include ”itkCommand.h” class CommandIteration : public itk::Command { public: typedef CommandIteration Self; typedef itk::Command SuperClass; typedef itk::SmartPointer Pointer; itkNewMacro( Self ); protected: CommandIteration() {}; public: typedef itk::RegularStepGradientDescentOptimizer OptimizerType; typedef const OptimizerType * OptimizerPointer;
Image RegistrationLecture Observing Registration void Execute( itk::Object * caller, const itk::EventObject & event ) { this-> Execute( (const itk::Object *) caller, event ); } void Execute( const itk::Object * caller, const itk::EventObject & event ) { OptimizerPointer optimizer = dynamic_cast ( caller ); if( typeid( event ) == typeid( itk::IterationEvent ) ) { std::cout GetCurrentIteration() << “ : “; std::cout GetValue() << “ : “; std::cout GetCurrentPosition() << std::endl; } }
Image RegistrationLecture Observing Registration CommandIteration::Pointer observer = CommandIteration::New(); optimizer->AddObserver( itk::IterationEvent(), observer ) try { registrator->StartRegistration (); } catch( itk::ExceptionObject & excp ) { std::cerr << “Error in registration” << std::endl; std::cerr << excp << std::endl; }
Image RegistrationLecture Registration dirty little secrets Rotation – Translation Parameter Scaling
Image RegistrationLecture Registration dirty little secrets Fixed Image Moving Image Registered Moving Image
Image RegistrationLecture Gradient Descent Optimizer f( x, y ) S = L ∙ G( x, y ) f( x, y ) ∆ G( x, y ) =
Image RegistrationLecture Gradient Descent Optimizer f( x, y ) S = L ∙ G( x, y ) f( x, y ) ∆ G( x, y ) =
Image RegistrationLecture Gradient Descent Optimizer f( x, y ) S = L ∙ G( x, y ) f( x, y ) ∆ G( x, y ) =
Image RegistrationLecture Gradient Descent Optimizer f( x, y ) S = L ∙ G( x, y ) f( x, y ) ∆ G( x, y ) =
Image RegistrationLecture Gradient Descent Optimizer f( x, y ) S = L ∙ G( x, y ) f( x, y ) ∆ G( x, y ) =
Image RegistrationLecture Gradient Descent Optimizer f( x, y ) S = L ∙ G( x, y ) f( x, y ) ∆ G( x, y ) = How about a factor 1:100 ?
Image RegistrationLecture Radians & Millimeters 0.0 rad x y 1.57 rad 180 mm
Image RegistrationLecture Radians & Millimeters 0.0 rad x y 1.57 rad 180 mm 1.57 rad 180 mm 1:100
Image RegistrationLecture Other Transforms Centered Rigid 2D
Image RegistrationLecture Rotation around the Center y Fixed Transform 10 o x y Moving x
Image RegistrationLecture Centered Rigid 2D Transform #include ”itkImageRegistrationMethod.h” #include ”itkCenteredRigid2DTransform.h” #include ”itkMeanSquaresImageToImageMetric.h” #include ”itkLinearInterpolateImageFunction.h” #include ”itkRegularStepGradientDescentOptimizer.h” #include ”itkCenteredTransformInitializer.h” #include ”itkImage.h” #include ”itkImageFileReader.h” #include ”itkImageFileWriter.h” #include ”itkResampleImageFilter.h”
Image RegistrationLecture Centered Rigid 2D Transform const unsigned int Dimension = 2; typedef unsigned char PixelType; typedef itk::Image FixedImageType; typedef itk::Image MovingImageType; typedef itk::CenteredRigid2DTransform TransformType; typedef itk:: CenteredTransformInitializer InitializerType;
Image RegistrationLecture Centered Rigid 2D Transform TransformType::Pointer transform = TransformType::New(); InitializerType::Pointer initializer = InitializerType::New(); OptimizerType::Pointer optimizer = OptimizerType::New(); InterpolatorType::Pointer interpolator = InterpolatorType::New(); MetricType::Pointer metric = MetricType::New(); RegistrationType::Pointer registrator = RegistrationType::New(); registrator->SetTransform( transform ); registrator->SetOptimizer( optimizer ); registrator->SetInterpolator( interpolator ); registrator->SetMetric( metric ); registrator->SetFixedImage( fixedImageReader->GetOutput() ); registrator->SetMovingImage( movingImageReader->GetOutput() );
Image RegistrationLecture Centered Transform Initializer y Fixed Image Transform x y Moving Image x Geometry On
Image RegistrationLecture Centered Transform Initializer y Fixed Image Transform x y Moving Image x Moments On Xm = Sum( x ∙ I ) / Sum( I ) Ym = Sum( y ∙ I ) / Sum( I )
Image RegistrationLecture Centered Rigid 2D Transform registrator->SetFixedImageRegion( fixedImageReader->GetOutput()->GetBufferedRegion() ); initializer->SetTransform ( transform ); initializer->SetFixedImage( fixedImageReader->GetOutput() ); initializer->SetMovingImage( movingImageReader->GetOutput() ); initializer->MomentsOn(); initializer->InitializeTransform(); registrator->SetInitialTransformParameters( transform->GetParameters() );
Image RegistrationLecture Centered Rigid 2D Transform y x Array of Parameters P[ 0 ] P[ 1 ] P[ 2 ] P[ 3 ] P[ 4 ] Angle Center X Center Y Trans X Trans Y
Image RegistrationLecture Centered Rigid 2D Transform typedef OptimizerType::ScaleType OptimizerScalesType; OptimizerScalesType optimizerScales( optimizer->SetMaximumStepLength() ); const double translationScale = 1.0 / ; optimizerScales[ 0 ] = 1.0; optimizerScales[ 1 ] = translationScale; optimizerScales[ 2 ] = translationScale; optimizerScales[ 3 ] = translationScale; optimizerScales[ 4 ] = translationScale; optimizer->SetScales( optimizerScales );
Image RegistrationLecture Centered Rigid 2D Transform try { registrator->StartRegistration (); } catch( itk::ExceptionObject & excp ) { std::cerr << “Error in registration” << std::endl; std::cerr << excp << std::endl; } transform->SetParameters( registrator->GetLastTransformParameters() );
Image RegistrationLecture Image Registration Framework Fixed Image Moving Image Metric Transform Interpolator Optimizer Parameters Resampler Moving Registered
Image RegistrationLecture Centered Rigid 2D Transform typedef itk::ResampleImageFilter ResamplerType; ResamplerType ::Pointer resampler = ResamplerType::New(); resampler->SetTransform ( transform ); resampler->SetInput( movingImageReader->GetOutput() ); FixedImageType ::Pointer fixedImage = fixedImageReader->GetOutput(); resampler->SetOrigin( fixedImage->GetOrigin() ); resampler->SetSpacing( fixedImage->GetSpacing() ); resampler->SetSize( fixedImage->GetLargestPossibleRegion()->GetSize() ); resampler->Update();
Image RegistrationLecture Other Transforms Affine 2D
Image RegistrationLecture Affine Transforms M 11 M 12 T 1 M 21 M 22 T 2
Image RegistrationLecture Affine Transforms Q x M 11 M 12 P x T 1 Q y M 21 M 22 P y T 2 =∙+
Image RegistrationLecture Affine Transform – Shearing Q x 1 a P x T 1 Q y 0 1 P y T 2 =∙+
Image RegistrationLecture Shearing Component y x a 1 (x,y) ( x + ay, y )
Image RegistrationLecture Shearing Component y’ x y x’
Image RegistrationLecture Affine Transform – Shearing Q x 1 0 P x T 1 Q y b 1 P y T 2 =∙+
Image RegistrationLecture Shearing Component y x b 1 (x,y) ( x, y + bx )
Image RegistrationLecture Shearing Component y x y’ x’
Image RegistrationLecture Coefficients - Orders of Magnitude Q x P x 100 Q y P y 100 =∙+
Image RegistrationLecture Affine Transform – Rotation Q x cosθ -sinθ P x T 1 Q y sinθ cosθ P y T 2 = ∙+
Image RegistrationLecture Affine Transform – Scaling Q x S x 0 P x T 1 Q y 0 S y P y T 2 =∙+
Image RegistrationLecture Affine Transform - Parameterization M 11 M 12 T 1 M 21 M 22 T 2 [ P 0 P 1 P 2 P 3 P 4 P 5 ]
Image RegistrationLecture Parameter Scaling M 11 M 12 T 1 M 21 M 22 T 2 [ P 0 P 1 P 2 P 3 P 4 P 5 ] range [ ] scale [ ]
Image RegistrationLecture Centered Affine Transform #include ”itkImageRegistrationMethod.h” #include ”itkCenteredAffineTransform.h” #include ”itkMeanSquaresImageToImageMetric.h” #include ”itkLinearInterpolateImageFunction.h” #include ”itkRegularStepGradientDescentOptimizer.h” #include ”itkCenteredTransformInitializer.h” #include ”itkImage.h” #include ”itkImageFileReader.h” #include ”itkImageFileWriter.h” #include ”itkResampleImageFilter.h”
Image RegistrationLecture Centered Affine Transform const unsigned int Dimension = 2; typedef unsigned char PixelType; typedef itk::Image FixedImageType; typedef itk::Image MovingImageType; typedef itk::CenteredAffineTransform TransformType; typedef itk:: CenteredTransformInitializer InitializerType;
Image RegistrationLecture Centered Affine Transform TransformType::Pointer transform = TransformType::New(); InitializerType::Pointer initializer = InitializerType::New(); OptimizerType::Pointer optimizer = OptimizerType::New(); InterpolatorType::Pointer interpolator = InterpolatorType::New(); MetricType::Pointer metric = MetricType::New(); RegistrationType::Pointer registrator = RegistrationType::New(); registrator->SetTransform( transform ); registrator->SetOptimizer( optimizer ); registrator->SetInterpolator( interpolator ); registrator->SetMetric( metric ); registrator->SetFixedImage( fixedImageReader->GetOutput() ); registrator->SetMovingImage( movingImageReader->GetOutput() );
Image RegistrationLecture Centered Transform Initializer y Fixed Image Transform x y Moving Image x Geometry On
Image RegistrationLecture Centered Transform Initializer y Fixed Image Transform x y Moving Image x Moments On Xm = Sum( x ∙ I ) / Sum( I ) Ym = Sum( y ∙ I ) / Sum( I )
Image RegistrationLecture Centered Affine Transform registrator->SetFixedImageRegion( fixedImageReader->GetOutput()->GetBufferedRegion() ); initializer->SetTransform ( transform ); initializer->SetFixedImage( fixedImageReader->GetOutput() ); initializer->SetMovingImage( movingImageReader->GetOutput() ); initializer->MomentsOn(); initializer->InitializeTransform(); registrator->SetInitialTransformParameters( transform->GetParameters() );
Image RegistrationLecture Affine Transform - Parameterization M 11 M 12 T 1 M 21 M 22 T 2 P[0] P[1] P[2] P[3] P[4] P[5]
Image RegistrationLecture Centered Affine Transform typedef OptimizerType::ScaleType OptimizerScalesType; OptimizerScalesType optimizerScales( optimizer->GetNumberOfParameters() ); optimizerScales[ 0 ] = 1.0; optimizerScales[ 1 ] = 10.0; optimizerScales[ 2 ] = 10.0; optimizerScales[ 3 ] = 1.0; optimizerScales[ 4 ] = 0.01; optimizerScales[ 5 ] = 0.01; optimizer->SetScales( optimizerScales );
Image RegistrationLecture Centered Rigid 2D Transform try { registrator->StartRegistration (); } catch( itk::ExceptionObject & excp ) { std::cerr << “Error in registration” << std::endl; std::cerr << excp << std::endl; } transform->SetParameters( registrator->GetLastTransformParameters() );
Image RegistrationLecture Image Registration Framework Fixed Image Moving Image Metric Transform Interpolator Optimizer Parameters Resampler Moving Registered
Image RegistrationLecture Final Resampling typedef itk::ResampleImageFilter ResamplerType; ResamplerType ::Pointer resampler = ResamplerType::New(); resampler->SetTransform ( transform ); resampler->SetInput( movingImageReader->GetOutput() ); FixedImageType ::Pointer fixedImage = fixedImageReader->GetOutput(); resampler->SetOrigin( fixedImage->GetOrigin() ); resampler->SetSpacing( fixedImage->GetSpacing() ); resampler->SetSize( fixedImage->GetLargestPossibleRegion()->GetSize() ); resampler->Update();
Image RegistrationLecture End Enjoy ITK !