Download presentation
Presentation is loading. Please wait.
1
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
2
Image RegistrationLecture 10 2 Registration Components Basic Registration Framework
3
Image RegistrationLecture 10 3 Image Registration Framework Fixed Image Moving Image Metric Transform Interpolator Optimizer Parameters
4
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”
5
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;
6
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() );
7
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();
8
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() );
9
Image RegistrationLecture 10 9 Image Registration Framework Fixed Image Moving Image Metric Transform Interpolator Optimizer Parameters Resampler Moving Registered
10
Image RegistrationLecture 10 10 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();
11
Image RegistrationLecture 10 11 Image Registration Tracking the Registration Process
12
Image RegistrationLecture 10 12 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;
13
Image RegistrationLecture 10 13 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; } }
14
Image RegistrationLecture 10 14 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; }
15
Image RegistrationLecture 10 15 Registration dirty little secrets Rotation – Translation Parameter Scaling
16
Image RegistrationLecture 10 16 Registration dirty little secrets Fixed Image Moving Image Registered Moving Image
17
Image RegistrationLecture 10 17 Gradient Descent Optimizer f( x, y ) S = L ∙ G( x, y ) f( x, y ) ∆ G( x, y ) =
18
Image RegistrationLecture 10 18 Gradient Descent Optimizer f( x, y ) S = L ∙ G( x, y ) f( x, y ) ∆ G( x, y ) =
19
Image RegistrationLecture 10 19 Gradient Descent Optimizer f( x, y ) S = L ∙ G( x, y ) f( x, y ) ∆ G( x, y ) =
20
Image RegistrationLecture 10 20 Gradient Descent Optimizer f( x, y ) S = L ∙ G( x, y ) f( x, y ) ∆ G( x, y ) =
21
Image RegistrationLecture 10 21 Gradient Descent Optimizer f( x, y ) S = L ∙ G( x, y ) f( x, y ) ∆ G( x, y ) =
22
Image RegistrationLecture 10 22 Gradient Descent Optimizer f( x, y ) S = L ∙ G( x, y ) f( x, y ) ∆ G( x, y ) = How about a factor 1:100 ?
23
Image RegistrationLecture 10 23 Radians & Millimeters 0.0 rad x y 1.57 rad 180 mm
24
Image RegistrationLecture 10 24 Radians & Millimeters 0.0 rad x y 1.57 rad 180 mm 1.57 rad 180 mm 1:100
25
Image RegistrationLecture 10 25 Other Transforms Centered Rigid 2D
26
Image RegistrationLecture 10 26 Rotation around the Center y Fixed Transform 10 o x y Moving x
27
Image RegistrationLecture 10 27 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”
28
Image RegistrationLecture 10 28 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;
29
Image RegistrationLecture 10 29 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() );
30
Image RegistrationLecture 10 30 Centered Transform Initializer y Fixed Image Transform x y Moving Image x Geometry On
31
Image RegistrationLecture 10 31 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 )
32
Image RegistrationLecture 10 32 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() );
33
Image RegistrationLecture 10 33 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
34
Image RegistrationLecture 10 34 Centered Rigid 2D Transform typedef OptimizerType::ScaleType OptimizerScalesType; OptimizerScalesType optimizerScales( optimizer->SetMaximumStepLength() ); 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 );
35
Image RegistrationLecture 10 35 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() );
36
Image RegistrationLecture 10 36 Image Registration Framework Fixed Image Moving Image Metric Transform Interpolator Optimizer Parameters Resampler Moving Registered
37
Image RegistrationLecture 10 37 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();
38
Image RegistrationLecture 10 38 Other Transforms Affine 2D
39
Image RegistrationLecture 10 39 Affine Transforms M 11 M 12 T 1 M 21 M 22 T 2
40
Image RegistrationLecture 10 40 Affine Transforms Q x M 11 M 12 P x T 1 Q y M 21 M 22 P y T 2 =∙+
41
Image RegistrationLecture 10 41 Affine Transform – Shearing Q x 1 a P x T 1 Q y 0 1 P y T 2 =∙+
42
Image RegistrationLecture 10 42 Shearing Component y x a 1 (x,y) ( x + ay, y )
43
Image RegistrationLecture 10 43 Shearing Component y’ x y x’
44
Image RegistrationLecture 10 44 Affine Transform – Shearing Q x 1 0 P x T 1 Q y b 1 P y T 2 =∙+
45
Image RegistrationLecture 10 45 Shearing Component y x b 1 (x,y) ( x, y + bx )
46
Image RegistrationLecture 10 46 Shearing Component y x y’ x’
47
Image RegistrationLecture 10 47 Coefficients - Orders of Magnitude Q x 1.0 0.1 P x 100 Q y 0.1 1.0 P y 100 =∙+
48
Image RegistrationLecture 10 48 Affine Transform – Rotation Q x cosθ -sinθ P x T 1 Q y sinθ cosθ P y T 2 = ∙+
49
Image RegistrationLecture 10 49 Affine Transform – Scaling Q x S x 0 P x T 1 Q y 0 S y P y T 2 =∙+
50
Image RegistrationLecture 10 50 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 ]
51
Image RegistrationLecture 10 51 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 [ 1.0 0.1 0.1 1.0 100 100 ] scale [ 1.0 10 10 1.0 0.01 0.01 ]
52
Image RegistrationLecture 10 52 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”
53
Image RegistrationLecture 10 53 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;
54
Image RegistrationLecture 10 54 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() );
55
Image RegistrationLecture 10 55 Centered Transform Initializer y Fixed Image Transform x y Moving Image x Geometry On
56
Image RegistrationLecture 10 56 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 )
57
Image RegistrationLecture 10 57 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() );
58
Image RegistrationLecture 10 58 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]
59
Image RegistrationLecture 10 59 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 );
60
Image RegistrationLecture 10 60 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() );
61
Image RegistrationLecture 10 61 Image Registration Framework Fixed Image Moving Image Metric Transform Interpolator Optimizer Parameters Resampler Moving Registered
62
Image RegistrationLecture 10 62 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();
63
Image RegistrationLecture 10 63 End Enjoy ITK !
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.