Title: ITK Registration Methods
1ITK Registration Methods
Kitware Inc.
2Overview
- Image Resampling
- Registration Framework
- Multi-Modality
- Multi-Resolution
- Deformable registration
3Image Resampling
4Why Resampling ?
Resamplingis the Essence of Intensity-BasedImag
e Registration
5What is an Image ?
An Image is a sampling of a continuous field
using a discrete grid
6Image Origin Spacing
Spacing (Sx)
Spacing (Sy)
Origin (Ox,Oy)
7Image Sampling Grid
Spacing (Sx)
Spacing (Sy)
Origin (Ox,Oy)
8Image Pixel
Spacing (Sx)
Pixel Value
Pixel Region
Spacing (Sy)
Origin (Ox,Oy)
9Image Indices
Spacing (Sx)
Pixel Index
0,7
4,7
0,6
0,5
0,4
0,3
0,2
Spacing (Sy)
0,1
0,0
1,0
2,0
3,0
4,0
5,0
Origin (Ox,Oy)
10Index to Physical Coordinates
Spacing (Sx)
Pixel Index
0,7
4,7
0,6
0,5
P0 Index0 x Spacing0 Origin0
P1 Index1 x Spacing1 Origin1
0,4
Index0 floor( ( P0 - Origin0 ) /
Spacing0 0.5 )
0,3
Index1 floor( ( P1 - Origin1 ) /
Spacing1 0.5 )
0,2
Spacing (Sy)
0,1
0,0
1,0
2,0
3,0
4,0
5,0
Origin (Ox,Oy)
11Image Region
Spacing (Sx)
Pixel Value
Image Region
Pixel Region
Spacing (Sy)
Origin (Ox,Oy)
12Image Region
Spacing (Sx)
Region Size
Image Region
3,5
Starting Index
2,3
Spacing (Sy)
Origin (Ox,Oy)
13Basic Resampling
ResamplingTrivial Cases
14Sub-Sampling by Half
Spacing (Sx)
Image Region
Spacing (Sy)
Origin (Ox,Oy)
15Sub-Sampling by Half
New Spacing Sx
New Spacing Sy
New Origin (Ox,Oy)
Origin (Ox,Oy)
16Super-Sampling by Double
Spacing ( Sx/2 )
Spacing (Sx)
Spacing ( Sy/2 )
Image Region
Spacing (Sy)
Origin (Ox,Oy)
17Super-Sampling by Double
New Spacing Sx
New Origin (Ox,Oy)
Origin (Ox,Oy)
18Resampling in ITK
itkResampleImageFilter
19Resampling in ITK
Origin
Spacing
Region Size
Resample Filter
Region Start
Transform
Interpolator
20Resample Image Filter
include "itkImage.h" include "itkResampleImageFi
lter.h" include "itkIdentityTransform.h include
"itkLinearInterpolateImageFunction.h" typedef
itkImagelt char, 2 gt ImageType ImageTypePoin
ter inputImage GetImageSomeHow() typedef
itkResampleImageFilterlt ImageType gt
FilterType FilterTypePointer resampler
FilterTypeNew() ImageTypeSizeType
size size0 200 size1 300 ImageTypeIn
dexType start start0 0 start1 0
21Resample Image Filter
ImageTypePointType origin origin0 10.0
// millimeters origin1 25.5 //
millimeters ImageTypeSpacingType spacing
spacing0 2.0 // millimeters spacing1
1.5 // millimeters resampler-gtSetOutputSpacing(
spacing ) resampler-gtSetOutputOrigin( origin
) resampler-gtSetSize( size ) resampler-gtSetOutp
utStartIndex( start ) resampler-gtSetDefaultPixel
Value( 100 ) resampler-gtSetInput( inputImage )
22Resample Image Filter
typedef itkLinearInterpolateImageFunctionlt
ImageType,
double gt
InterpolatorType InterpolatorTypePointer
interpolator InterpolatorTypeNew() typedef
itkTranslationTransformlt double, 2 gt
TransformType TransformTypePointer transform
TransformTypeNew() transform-gtSetIdentity()
resampler-gtSetInterpolator( interpolator
) resampler-gtSetTransform( transform
) resampler-gtUpdate() const ImageType
outputImage resampler-gtGetOutput()
23Basic Registration
24Coordinate System Conversions
25Things I will not do
26Fixed Image Moving Image
27Selecting Moving Fixed Images
In principle the denomination of Fixed Image
Moving Image is arbitrary
In practice the moving image is the one that will
be resampled into the fixed image coordinate
system
28Quiz 1
Images from the same patient
Moving Image ? Fixed Image ?
Images provided as part of the project
Retrospective Image Registration Evaluation,
NIH, Project No. 8R01EB002124-03, Principal
Investigator, J. Michael Fitzpatrick, Vanderbilt
University, Nashville, TN.
29Quiz 2
Images from the same patient
What scale factor ?
- 2.0
- 1.0
- 0.5
Images provided as part of the project
Retrospective Image Registration Evaluation,
NIH, Project No. 8R01EB002124-03, Principal
Investigator, J. Michael Fitzpatrick, Vanderbilt
University, Nashville, TN.
30Things I will not do
31Registration in ITK
MultiResolutionRegistrationFramework
ImageRegistrationFramework
PDEBasedRegistration
FEMBasedRegistration
32Registration Framework
33Components
Registration Method
FixedImage
Metric
Optimizer
Interpolator
MovingImage
Transform
34Image Metrics
- Mean Squares
- Normalized Correlation
- Mean Reciprocal Square Difference
- Mutual Information- Viola-Wells- Mattes-
Histogram based- Histogram normalized
35Transforms
- Translation
- Scaling
- Rotation
- Rigid3D
- Rigid2D
- Affine
- BSplines
- Splines TPS, EBS, VS
36Optimizers
- Gradient Descent
- Regular Step Gradient Descent
- Conjugate Gradient
- Levenberg-Marquardt
- One plus One Evolutionary Algorithm
37Interpolators
- Nearest Neighbor
- Linear
- BSpline
38Exercise 20
39Image Registration
40Image Registration
include itkImageRegistrationMethod.h include
itkTranslationTransform.h include
itkMeanSquaresImageToImageMetric.h include
itkLinearInterpolateImageFunction.h include
itkRegularStepGradientDescentOptimizer.h includ
e itkImage.h include itkImageFileReader.h in
clude itkImageFileWriter.h include
itkResampleImageFilter.h
41Image Registration
const unsigned int Dimension 2 typedef
unsigned char PixelType typedef itkImagelt
PixelType , Dimension gt
FixedImageType typedef itkImagelt PixelType ,
Dimension gt
MovingImageType typedef itkTranslationTransfo
rmlt double, Dimension gt TransformType typed
ef itkRegularStepGradientDescentOptimizer
OptimizerType typedef
itkLinearInterpolateImageFunctionlt
MovingImageType ,
double gt InterpolatorType typedef
itkMeanSquaresImageToImageMetriclt
FixedImageType , MovingImageType gt
MetricType typedef itkImageRegistratio
nMethodlt FixedImageType
, MovingImageType gt RegistrationType
42Image Registration
TransformTypePointer transform
TransformTypeNew() OptimizerTypePointer
optimizer OptimizerTypeNew() Interpolato
rTypePointer interpolator
InterpolatorTypeNew() MetricTypePointer
metric MetricTypeNew() Regist
rationTypePointer registrator
RegistrationTypeNew() registrator-gtSetTransfor
m( transform ) registrator-gtSetOptimizer(
optimizer ) registrator-gtSetInterpolator(
interpolator ) registrator-gtSetMetric(
metric ) registrator-gtSetFixedImage(
fixedImageReader-gtGetOutput() ) registrator-gtSetM
ovingImage( movingImageReader-gtGetOutput() )
43Image Registration
registrator-gtSetFixedImageRegion(
fixedImageReader-gtGetOutput()-gtGetBufferedR
egion() ) typedef RegistrationTypeParameters
Type ParametersType transform-gtSetIdentity()
registrator-gtSetInitialTransformParameters(
transform-gtGetParameters()
) optimizer-gtSetMaximumStepLength( 4.00 )
optimizer-gtSetMinimumStepLength( 0.01
) optimizer-gtSetNumberOfIterations( 100
) optimizer-gtMaximizeOff()
44Image Registration
try registrator-gtStartRegistrati
on () catch( itkExceptionObject excp
) stdcerr ltlt Error in
registration ltlt stdendl stdcerr
ltlt excp ltlt stdendl transform-gtSetParam
eters(
registrator-gtGetLastTransformParameters() )
45Image Registration
typedef itkResampleImageFilterlt
FixedImageType , MovingImageType gt
ResamplerType ResamplerType Pointer
resampler ResamplerTypeNew() resampler-gtSet
Transform ( transform ) resampler-gtSetInput(
movingImageReader-gtGetOutput() ) FixedImageType
Pointer fixedImage fixedImageReader-gtGetOut
put() resampler-gtSetOrigin( fixedImage-gtGetOrigin
() ) resampler-gtSetSpacing( fixedImage-gtGetSpacin
g() ) resampler-gtSetSize(
fixedImage-gtGetLargestPossibleRegion()-gtGetSize
() ) resampler-gtUpdate()
46Tracking theRegistration Process
47Observing Registration
include itkCommand.h class CommandIteration
public itkCommand public typedef
CommandIteration Self typedef itkCommand
SuperClass typedef itkSmartPointerlt
Self gt Pointer itkNewMacro( Self
) protected CommandIteration()
public typedef itkRegularStepGradientD
escentOptimizer OptimizerType typedef
const OptimizerType
OptimizerPointer
48Observing Registration
- void Execute( itkObject caller, const
itkEventObject event ) this-gt
Execute( (const itkObject ) caller, event
) - void Execute( const itkObject caller, const
itkEventObject event )
OptimizerPointer optimizer
dynamic_castlt
OptimizerPointer gt( caller ) - if( typeid( event ) typeid(
itkIterationEvent ) ) - stdcout ltlt optimizer-gtGetCurrentIterat
ion() ltlt - stdcout ltlt optimizer-gtGetValue() ltlt
- stdcout ltlt optimizer-gtGetCurrentPositi
on() ltlt stdendl -
49Image Registration
- CommandIterationPointer observer
CommandIterationNew() - optimizer-gtAddObserver( itkIterationEvent(),
observer ) - try registrator-gtStartRegistrati
on () - catch( itkExceptionObject excp )
- stdcerr ltlt Error in registration
ltlt stdendl stdcerr ltlt excp ltlt
stdendl
50Image Similarity Metrics
51Image Metrics
How similar is image A to image B ?
52Image Metrics
Does Image B matches Image A better than
Image C ?
53Image Metrics
gtlt
Match( A , B )
Match( A , C )
Image A
Image C
Image B
54Image Metrics
Match( A , B )Simplest MetricMean Squared
Differences
55Mean Squared Differences
For each pixel in A
Image A
Image B
Difference( index ) A( index ) B( index )
Sum Difference( index ) 2
Match( A , B ) Sum / numberOfPixels
56For each pixel in the Fixed Image
57Image Metrics
FixedImage
Metric
Value
MovingImage
Interpolator
Transform
Parameters
58Mean Squared Differences
include "itkImage.h" include "itkMeanSquaresImag
eToImageMetric.h" include "itkLinearInterpolateIm
ageFunction.h" include "itkTranslationTransform.h
" typedef itkImagelt char, 2 gt
ImageType ImageTypeConstPointer fixedImage
GetFixedImage() ImageTypeConstPointer
movingImage GetMovingImage() typedef
itkLinearInterpolateImageFunctionlt
ImageType,
double gt
InterpolatorType InterpolatorTy
pePointer interpolator InterpolatorTypeNew()
typedef itkTranslationTransformlt double, 2
gt TransformType TransformTypePointer
transform TransformTypeNew()
59Mean Squared Differences
typedef itkMeanSquaresImageToImageMetriclt
ImageType, ImageType gt
MetricType MetricTypePointer metric
MetricTypeNew() metric-gtSetInterpolator(
interpolator ) metric-gtSetTransform( transform
) metric-gtSetFixedImage( fixedImage
) metric-gtSetMovingImage( movingImage
) MetricTypeTransformParametersType
translation( Dimension ) translation0
12 translation1 27 double value
metric-gtGetValue( translation )
60Mean Squared Differences
MetricTypeTransformParametersType translation(
Dimension ) double value2121 for( int dx
0 dx lt 20 dx) for( int dy 0 dy lt
20 dy) translation0
dx translation1 dy valuedxdy
metric-gtGetValue( translation )
61Evaluating many matches
y
y
Transform
x
x
Fixed Image
Moving Image
62Plotting the Metric
Mean Squared Differences
Transform Parametric Space
63Plotting the Metric
Mean Squared Differences
Transform Parametric Space
64Evaluating many matches
y
y
Transform
(-15,-25) mm
x
x
Fixed Image
Moving Image
65Plotting the Metric
Mean Squared Differences
Transform Parametric Space
66Plotting the Metric
Mean Squared Differences
Transform Parametric Space
67The Best Transform Parameters
Evaluation of thefull parameter spaceis
equivalent to performingoptimization by
exhaustive search
68The Best Transform Parameters
Very SafebutVery Slow
69The Best Transform Parameters
Better Optimization Methodsfor
exampleGradient Descent
70Image Registration Framework
FixedImage
Metric
MovingImage
Interpolator
Optimizer
Transform
Parameters
71Gradient Descent Optimizer
f( x , y )
S Step
L LearningRate
S L G( x , y )
72Gradient Descent Optimizer
f( x , y )
S L G( x , y )
73Gradient Descent Optimizer
f( x , y )
L too large
S L G( x , y )
74Gradient Descent Optimizer
f( x , y )
L too small
S L G( x , y )
75Gradient Descent Optimizer
Whats wrong with this algorithm ?
76Gradient Descent Optimizer
millimeters
S Units ?
f(x,y) Units ?
intensity
G(x,y) Units ?
intensity / millimeters
S L G( x , y )
L Units ?
millimeters2 / intensity
77Gradient Descent Optimizer
f( x )
S L G( x )
1
1
78Gradient Descent Optimizer
f( x )
S L G( x )
S Large in high gradients
S Small in low gradients
1
1
79Gradient Descent Optimizer
f( x )
S L G( x )
Works great with this function
Works badly with this function
80Gradient Descent Variant
Driving Safe !
81Regular Step Gradient Descent
f( x )
S D G( x )
If G changes direction
Di Di-1 / 2.0
D1
D1
D2
D1
82Regular Step Gradient Descent
f( x )
S D G( x )
User Selects D1
User Selects Dstop
User Selects Gstop
D1
D1
D2
D1
83Optimizers are like a car
Watch while you are driving !
84Watch over your optimizer
ExampleOptimizer registering an image with
itself starting at (-15mm, -25mm)
85Plotting the Optimizers Path
Mean Squared Differences
Step Length 1.0 mm
86Plotting the Optimizers Path
Mean Squared Differences
Step Length 2.0 mm
87Plotting the Optimizers Path
Mean Squared Differences
Step Length 5.0 mm
88Plotting the Optimizers Path
Mean Squared Differences
Step Length 10.0 mm
89Plotting the Optimizers Path
Mean Squared Differences
Step Length 20.0 mm
90Plotting the Optimizers Path
Mean Squared Differences
Step Length 40.0 mm
91Watch over your optimizer
ExampleOptimizer registering an image shifted
by (-15mm, -25mm)The optimizer starts at
(0mm,0mm)
92Plotting the Optimizers Path
Mean Squared Differences
Step Length 1.0 mm
93Plotting the Optimizers Path
Mean Squared Differences
Step Length 2.0 mm
94Plotting the Optimizers Path
Mean Squared Differences
Step Length 5.0 mm
95Plotting the Optimizers Path
Mean Squared Differences
Step Length 10.0 mm
96Plotting the Optimizers Path
Mean Squared Differences
Step Length 20.0 mm
97Plotting the Optimizers Path
Mean Squared Differences
Step Length 40.0 mm
98Multi - Modality
99Multi-Modality Registration
100Multiple Image Modalities
Number of pairs
101Multiple Image Modalities
More possible pairs
102Mutual Information
103Mutual Information
104Exercise 21
105Image Registration
106Image Registration
include itkImageRegistrationMethod.h include
itkTranslationTransform.h include
itkMattesMutualInformationImageToImageMetric.h
include itkLinearInterpolateImageFunction.h inc
lude itkRegularStepGradientDescentOptimizer.h i
nclude itkImage.h include itkImageFileReader.h
include itkImageFileWriter.h include
itkResampleImageFilter.h
107Image Registration
const unsigned int Dimension 2 typedef
unsigned char PixelType typedef itkImagelt
PixelType , Dimension gt
FixedImageType typedef itkImagelt PixelType ,
Dimension gt
MovingImageType typedef itkTranslationTransfo
rmlt double, Dimension gt TransformType typed
ef itkRegularStepGradientDescentOptimizer
OptimizerType typedef
itkLinearInterpolateImageFunctionlt
MovingImageType ,
double gt InterpolatorType typedef
itkMattesMutualInformationImageToImageMetriclt
FixedImageType ,
MovingImageType gt MetricType typedef
itkImageRegistrationMethodlt
FixedImageType , MovingImageType gt
RegistrationType
108Image Registration
TransformTypePointer transform
TransformTypeNew() OptimizerTypePointer
optimizer OptimizerTypeNew() Interpolato
rTypePointer interpolator
InterpolatorTypeNew() MetricTypePointer
metric MetricTypeNew() Regist
rationTypePointer registrator
RegistrationTypeNew() registrator-gtSetTransfor
m( transform ) registrator-gtSetOptimizer(
optimizer ) registrator-gtSetInterpolator(
interpolator ) registrator-gtSetMetric(
metric ) registrator-gtSetFixedImage(
fixedImageReader-gtGetOutput() ) registrator-gtSetM
ovingImage( movingImageReader-gtGetOutput() )
109Image Registration
registrator-gtSetFixedImageRegion(
fixedImageReader-gtGetOutput()-gtGetBufferedR
egion() ) typedef RegistrationTypeParameters
Type ParametersType transform-gtSetIdentity()
registrator-gtSetInitialTransformParameters(
transform-gtGetParameters()
) optimizer-gtSetMaximumStepLength( 4.00 )
optimizer-gtSetMinimumStepLength( 0.05
) optimizer-gtSetNumberOfIterations( 200
) optimizer-gtMaximizeOff()
110Image Registration
metric-gtSetNumberOfHistogramBins( 20 )
// Metric specificmetric-gtSetNumb
erOfSpatialSamples( 10000 ) //
Metric specific try
registrator-gtStartRegistration () catch(
itkExceptionObject excp )
stdcerr ltlt Error in registration ltlt
stdendl stdcerr ltlt excp ltlt
stdendl transform-gtSetParameters(
registrator-gtGetLast
TransformParameters() )
111Image Registration
typedef itkResampleImageFilterlt
FixedImageType , MovingImageType gt
ResamplerType ResamplerType Pointer
resampler ResamplerTypeNew() resampler-gtSet
Transform ( transform ) resampler-gtSetInput(
movingImageReader-gtGetOutput() ) FixedImageType
Pointer fixedImage fixedImageReader-gtGetOut
put() resampler-gtSetOrigin( fixedImage-gtGetOrigin
() ) resampler-gtSetSpacing( fixedImage-gtGetSpacin
g() ) resampler-gtSetSize(
fixedImage-gtGetLargestPossibleRegion()-gtGetSize
() ) resampler-gtUpdate()
112Rotation TranslationParameter Scaling
113Exercise 22
114Image Registration
115Image Registration
include itkImageRegistrationMethod.h include
itkCenteredRigid2DTransform.h include
itkMeanSquaresImageToImageMetric.h include
itkLinearInterpolateImageFunction.h include
itkRegularStepGradientDescentOptimizer.h includ
e itkCenteredTransformInitializer.h include
itkImage.h include itkImageFileReader.h incl
ude itkImageFileWriter.h include
itkResampleImageFilter.h
116Image Registration
const unsigned int Dimension 2 typedef
unsigned char PixelType typedef itkImagelt
PixelType , Dimension gt
FixedImageType typedef itkImagelt PixelType ,
Dimension gt MovingImageType typedef
itkCenteredRigid2DTransformlt double gt
TransformType typedef itk
CenteredTransformInitializerlt
TransformType ,
FixedImageType ,
MovingImageType
gt InitializerType
117Image Registration
TransformTypePointer transform
TransformTypeNew() InitializerTypePointer
initializer InitializerTypeNew() Opt
imizerTypePointer optimizer
OptimizerTypeNew() InterpolatorTypePointer
interpolator InterpolatorTypeNew() MetricTy
pePointer metric
MetricTypeNew() RegistrationTypePointer
registrator RegistrationTypeNew() regist
rator-gtSetTransform( transform )
registrator-gtSetOptimizer( optimizer )
registrator-gtSetInterpolator( interpolator )
registrator-gtSetMetric( metric
) registrator-gtSetFixedImage(
fixedImageReader-gtGetOutput() ) registrator-gtSetM
ovingImage( movingImageReader-gtGetOutput() )
118Image Registration
registrator-gtSetFixedImageRegion(
fixedImageReader-gtGetOutput()-gtGetBuffe
redRegion() ) initializer-gtSetTransform (
transform ) initializer-gtSetFixedImage(
fixedImageReader-gtGetOutput()
) initializer-gtSetMovingImage(
movingImageReader-gtGetOutput() ) initializer-gtMo
mentsOn() initializer-gtInitializeTransform() r
egistrator-gtSetInitialTransformParameters(
transform-gtGetParameters() )
119Image Registration
typedef OptimizerTypeScaleType
OptimizerScalesType OptimizerScalesType
optimizerScales(
optimizer-gtSetMaximumStepLength(
) ) const double translationScale 1.0 /
1000.0 optimizerScales 0 1.0
optimizerScales 1 translationScale
optimizerScales 2 translationScale
optimizerScales 3 translationScale
optimizerScales 4 translationScale
optimizer-gtSetScales( optimizerScales )
120Image Registration
try registrator-gtStartRegistrati
on () catch( itkExceptionObject excp
) stdcerr ltlt Error in
registration ltlt stdendl stdcerr
ltlt excp ltlt stdendl transform-gtSetParam
eters(
registrator-gtGetLastTransformParameters() )
121Image Registration
typedef itkResampleImageFilterlt
FixedImageType , MovingImageType gt
ResamplerType ResamplerType Pointer
resampler ResamplerTypeNew() resampler-gtSet
Transform ( transform ) resampler-gtSetInput(
movingImageReader-gtGetOutput() ) FixedImageType
Pointer fixedImage fixedImageReader-gtGetOut
put() resampler-gtSetOrigin( fixedImage-gtGetOrigi
n() ) resampler-gtSetSpacing( fixedImage-gtGetSpaci
ng() ) resampler-gtSetSize(
fixedImage-gtGetLargestPossibleRegion()-gtGetSiz
e() ) resampler-gtUpdate()
122Multi - Resolution
123Multi-ResolutionRegistration Framework
- Improve speed
- Accuracy
- Robustness
124Multi-ResolutionRegistration Framework
125Multi-ResolutionRegistration Framework
- Flexible framework allows change of
- Parameters
- Components
- between resolution levels
126Enjoy ITK !