Slicer  4.10
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
itkImageToImageRegistrationHelper.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: ImageRegistrator.h,v $
5  Language: C++
6  Date: $Date: 2006/11/06 14:39:34 $
7  Version: $Revision: 1.15 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 
18 #ifndef itkImageToImageRegistrationHelper_h
19 #define itkImageToImageRegistrationHelper_h
20 
21 #include "itkImage.h"
22 #include "itkCommand.h"
23 
30 
31 namespace itk
32 {
33 
34 template <class TImage>
35 class ImageToImageRegistrationHelper : public Object
36 {
37 
38 public:
39 
41  typedef Object Superclass;
42  typedef SmartPointer<Self> Pointer;
43  typedef SmartPointer<const Self> ConstPointer;
44 
46 
47  itkNewMacro( Self );
48 
49  //
50  // Custom Typedefs
51  //
52  typedef TImage ImageType;
53 
54  typedef typename TImage::PixelType PixelType;
55 
56  itkStaticConstMacro( ImageDimension, unsigned int,
57  TImage::ImageDimension );
58 
59  //
60  // Available Registration Methods
61  //
64 
67 
70 
73 
76 
79 
80  //
81  // Typedefs for the parameters of the registration methods
82  //
85 
88 
91 
98 
105 
108 
109  typedef std::vector<std::vector<float> > LandmarkVectorType;
110 
111  typedef typename TImage::PointType PointType;
112 
115 
118 
120 
123 
124  //
125  // Custom Methods
126  //
127 
128  // **************
129  // **************
130  // Specify the fixed and moving images
131  // **************
132  // **************
133  void LoadFixedImage( const std::string filename );
134 
135  itkSetConstObjectMacro( FixedImage, TImage );
136  itkGetConstObjectMacro( FixedImage, TImage );
137 
138  void LoadMovingImage( const std::string filename );
139 
140  itkSetConstObjectMacro( MovingImage, TImage );
141  itkGetConstObjectMacro( MovingImage, TImage );
142 
143  // **************
144  // Generic file-save function
145  // **************
146  void SaveImage( const std::string filename, const TImage * image );
147 
148  itkSetMacro( RandomNumberSeed, unsigned int );
149  itkGetMacro( RandomNumberSeed, unsigned int );
150 
151  // **************
152  // **************
153  // Specify how the fixed image should be sampled when computing the metric and
154  // what ROI of the moving image is valid
155  // **************
156  // **************
157  itkSetMacro( UseFixedImageMaskObject, bool );
158  itkGetConstMacro( UseFixedImageMaskObject, bool );
159  itkBooleanMacro( UseFixedImageMaskObject );
160 
161  void SetFixedImageMaskObject( const MaskObjectType * mask );
162 
163  itkGetConstObjectMacro( FixedImageMaskObject, MaskObjectType );
164 
165  itkSetMacro( UseMovingImageMaskObject, bool );
166  itkGetConstMacro( UseMovingImageMaskObject, bool );
167  itkBooleanMacro( UseMovingImageMaskObject );
168 
169  void SetMovingImageMaskObject( const MaskObjectType * mask );
170 
171  itkGetConstObjectMacro( MovingImageMaskObject, MaskObjectType );
172 
173  itkSetMacro(UseRegionOfInterest, bool);
174  itkGetMacro(UseRegionOfInterest, bool);
175  itkSetMacro(RegionOfInterestPoint1, PointType);
176  itkGetMacro(RegionOfInterestPoint1, PointType);
177  itkSetMacro(RegionOfInterestPoint2, PointType);
178  itkGetMacro(RegionOfInterestPoint2, PointType);
179  void SetRegionOfInterest( const PointType & point1, const PointType & point2 );
180 
181  void SetRegionOfInterest( const std::vector<float> & points );
182 
183  // **************
184  // Initialize the moving image mask as the region of initial overlap
185  // between the fixed and moving images
186  // **************
187  itkSetMacro( SampleFromOverlap, bool );
188  itkGetMacro( SampleFromOverlap, bool );
189  itkBooleanMacro( SampleFromOverlap);
190 
191  itkSetMacro( SampleIntensityPortion, double );
192  itkGetConstMacro( SampleIntensityPortion, double );
193 
194  // **************
195  // **************
196  // Update
197  // **************
198  // **************
199  void Initialize( void );
200 
203  void Update( void );
204 
205  // **************
206  // **************
207  // Resample
208  // **************
209  // **************
210  typename TImage::ConstPointer ResampleImage(
213  ::LINEAR_INTERPOLATION, const TImage * movingImage = NULL,
214  const MatrixTransformType * matrixTransform = NULL, const BSplineTransformType * bsplineTransform = NULL,
215  PixelType defaultPixelValue = 0 );
216 
217  // Returns the moving image resampled into the space of the fixed image
218  typename TImage::ConstPointer GetFinalMovingImage(InterpolationMethodEnumType interp
220  ::LINEAR_INTERPOLATION );
221 
222  // **************
223  // **************
224  // Compute registration "accuracy" by comparing a resampled moving image
225  // with a baseline image.
226  // **************
227  // **************
228 
229  // Specify the baseline image.
230  void LoadBaselineImage( const std::string filename );
231 
232  itkSetConstObjectMacro( BaselineImage, TImage );
233 
234  // Bound the required accuracy for the registration test to "pass"
235  itkSetMacro( BaselineNumberOfFailedPixelsTolerance, unsigned int );
236  itkSetMacro( BaselineIntensityTolerance, PixelType );
237  itkSetMacro( BaselineRadiusTolerance, unsigned int );
238 
239  // Must be called after setting the BaselineImage in order to resample
240  // the moving image into the BaselineImage space, compute differences,
241  // and determine if it passed the test within the specified tolerances
242  void ComputeBaselineDifference( void );
243 
244  itkGetConstObjectMacro( BaselineDifferenceImage, TImage );
245  itkGetConstObjectMacro( BaselineResampledMovingImage, TImage );
246  itkGetMacro( BaselineNumberOfFailedPixels, unsigned int );
247  itkGetMacro( BaselineTestPassed, bool );
248 
249  // **************
250  // **************
251  // Process Control
252  // **************
253  // **************
254 
255  // **************
256  // Control which steps of the registration pipeline are applied
257  // **************
258  itkSetMacro( EnableLoadedRegistration, bool );
259  itkGetConstMacro( EnableLoadedRegistration, bool );
260  itkBooleanMacro( EnableLoadedRegistration );
261 
262  itkSetMacro( EnableInitialRegistration, bool );
263  itkGetConstMacro( EnableInitialRegistration, bool );
264  itkBooleanMacro( EnableInitialRegistration );
265 
266  itkSetMacro( EnableRigidRegistration, bool );
267  itkGetConstMacro( EnableRigidRegistration, bool );
268  itkBooleanMacro( EnableRigidRegistration );
269 
270  itkSetMacro( EnableAffineRegistration, bool );
271  itkGetConstMacro( EnableAffineRegistration, bool );
272  itkBooleanMacro( EnableAffineRegistration );
273 
274  itkSetMacro( EnableBSplineRegistration, bool );
275  itkGetConstMacro( EnableBSplineRegistration, bool );
276  itkBooleanMacro( EnableBSplineRegistration );
277 
278  // **************
279  // Specify the expected magnitudes within the transform. Used to
280  // guide the operating space of the optimizers
281  // **************
282  itkSetMacro( ExpectedOffsetPixelMagnitude, double );
283  itkGetConstMacro( ExpectedOffsetPixelMagnitude, double );
284 
285  itkSetMacro( ExpectedRotationMagnitude, double );
286  itkGetConstMacro( ExpectedRotationMagnitude, double );
287 
288  itkSetMacro( ExpectedScaleMagnitude, double );
289  itkGetConstMacro( ExpectedScaleMagnitude, double );
290 
291  itkSetMacro( ExpectedSkewMagnitude, double );
292  itkGetConstMacro( ExpectedSkewMagnitude, double );
293 
294  // **************
295  // Return the current product of the registration pipeline
296  // **************
297  itkGetConstObjectMacro( CurrentMatrixTransform, MatrixTransformType );
298  itkGetConstObjectMacro( CurrentBSplineTransform, BSplineTransformType );
299 
300  // The image used for registration is updated at certain points in the
301  // registration pipeline for speed and transform composition.
302  // Specifically, the image is resmpled using the loaded transforms prior
303  // to running the initial registration method and the image is resampled
304  // after the affine registration / prior to running bspline registration
305  // The result of these resamplings is available as the CurrentMovingImage.
306  itkGetConstObjectMacro( CurrentMovingImage, TImage );
307  itkGetConstObjectMacro( LoadedTransformResampledImage, TImage );
308  itkGetConstObjectMacro( MatrixTransformResampledImage, TImage );
309  itkGetConstObjectMacro( BSplineTransformResampledImage, TImage );
310 
311  // **************
312  // Not implemented at this time :(
313  // **************
314  void LoadParameters( const std::string filename );
315 
316  void SaveParameters( const std::string filename );
317 
318  // **************
319  // Final metric value after the pipeline has completed
320  // **************
321  itkGetMacro( FinalMetricValue, double );
322 
323  // **************
324  // Determine if progress messages should be sent to cout
325  // **************
326  itkSetMacro( ReportProgress, bool );
327  itkGetMacro( ReportProgress, bool );
328  itkBooleanMacro( ReportProgress );
329 
330  itkSetMacro( MinimizeMemory, bool );
331  itkGetMacro( MinimizeMemory, bool );
332  itkBooleanMacro( MinimizeMemory );
333 
334  //
335  // Loaded transforms parameters
336  //
337  void LoadTransform( const std::string filename );
338 
339  void SaveTransform( const std::string filename );
340 
341  void SetLoadedMatrixTransform( const MatrixTransformType & tfm );
342 
343  itkGetConstObjectMacro( LoadedMatrixTransform, MatrixTransformType );
344 
346 
347  itkGetConstObjectMacro( LoadedBSplineTransform, BSplineTransformType );
348 
349  //
350  // Initial Parameters
351  //
352  itkSetMacro( InitialMethodEnum, InitialMethodEnumType );
353  itkGetConstMacro( InitialMethodEnum, InitialMethodEnumType );
354  void SetFixedLandmarks( const LandmarkVectorType & fixedLandmarks );
355 
356  void SetMovingLandmarks( const LandmarkVectorType & movingLandmarks );
357 
358  //
359  // Rigid Parameters
360  //
361  itkSetMacro( RigidSamplingRatio, double );
362  itkGetConstMacro( RigidSamplingRatio, double );
363 
364  itkSetMacro( RigidTargetError, double );
365  itkGetConstMacro( RigidTargetError, double );
366 
367  itkSetMacro( RigidMaxIterations, unsigned int );
368  itkGetConstMacro( RigidMaxIterations, unsigned int );
369 
370  itkSetMacro( RigidMetricMethodEnum, MetricMethodEnumType );
371  itkGetConstMacro( RigidMetricMethodEnum, MetricMethodEnumType );
372 
373  itkSetMacro( RigidInterpolationMethodEnum, InterpolationMethodEnumType );
374  itkGetConstMacro( RigidInterpolationMethodEnum, InterpolationMethodEnumType );
375 
376  itkGetConstObjectMacro( RigidTransform, RigidTransformType );
377  itkGetMacro( RigidMetricValue, double );
378 
379  //
380  // Affine Parameters
381  //
382  itkSetMacro( AffineSamplingRatio, double );
383  itkGetConstMacro( AffineSamplingRatio, double );
384 
385  itkSetMacro( AffineTargetError, double );
386  itkGetConstMacro( AffineTargetError, double );
387 
388  itkSetMacro( AffineMaxIterations, unsigned int );
389  itkGetConstMacro( AffineMaxIterations, unsigned int );
390 
391  itkSetMacro( AffineMetricMethodEnum, MetricMethodEnumType );
392  itkGetConstMacro( AffineMetricMethodEnum, MetricMethodEnumType );
393 
394  itkSetMacro( AffineInterpolationMethodEnum, InterpolationMethodEnumType );
395  itkGetConstMacro( AffineInterpolationMethodEnum, InterpolationMethodEnumType );
396 
397  itkGetConstObjectMacro( AffineTransform, AffineTransformType );
398  itkGetMacro( AffineMetricValue, double );
399 
400  //
401  // BSpline Parameters
402  //
403  itkSetMacro( BSplineSamplingRatio, double );
404  itkGetConstMacro( BSplineSamplingRatio, double );
405 
406  itkSetMacro( BSplineTargetError, double );
407  itkGetConstMacro( BSplineTargetError, double );
408 
409  itkSetMacro( BSplineMaxIterations, unsigned int );
410  itkGetConstMacro( BSplineMaxIterations, unsigned int );
411 
412  itkSetMacro( BSplineControlPointPixelSpacing, double );
413  itkGetConstMacro( BSplineControlPointPixelSpacing, double );
414 
415  itkSetMacro( BSplineMetricMethodEnum, MetricMethodEnumType );
416  itkGetConstMacro( BSplineMetricMethodEnum, MetricMethodEnumType );
417 
418  itkSetMacro( BSplineInterpolationMethodEnum, InterpolationMethodEnumType );
419  itkGetConstMacro( BSplineInterpolationMethodEnum, InterpolationMethodEnumType );
420 
421  itkGetConstObjectMacro( BSplineTransform, BSplineTransformType );
422  itkGetMacro( BSplineMetricValue, double );
423 protected:
424 
426  virtual ~ImageToImageRegistrationHelper( void );
427 
428  void PrintSelfHelper( std::ostream & os, Indent indent, const std::string basename, MetricMethodEnumType metric,
429  InterpolationMethodEnumType interpolation ) const;
430 
431  void PrintSelf( std::ostream & os, Indent indent ) const ITK_OVERRIDE;
432 
433 private:
434 
436  LandmarkPointType;
438  LandmarkPointContainer;
439 
440  ImageToImageRegistrationHelper( const Self & ); // Purposely not implemented
441  void operator =( const Self & ); // Purposely not implemented
442 
443  // Data
444  typename TImage::ConstPointer m_FixedImage;
445  typename TImage::ConstPointer m_MovingImage;
446 
447  bool m_SampleFromOverlap;
448  double m_SampleIntensityPortion;
449 
450  bool m_UseFixedImageMaskObject;
451  typename MaskObjectType::ConstPointer m_FixedImageMaskObject;
452  bool m_UseMovingImageMaskObject;
453  typename MaskObjectType::ConstPointer m_MovingImageMaskObject;
454 
455  bool m_UseRegionOfInterest;
456  PointType m_RegionOfInterestPoint1;
457  PointType m_RegionOfInterestPoint2;
458 
459  unsigned int m_RandomNumberSeed;
460 
461  // Process
462  bool m_EnableLoadedRegistration;
463  bool m_EnableInitialRegistration;
464  bool m_EnableRigidRegistration;
465  bool m_EnableAffineRegistration;
466  bool m_EnableBSplineRegistration;
467 
468  double m_ExpectedOffsetPixelMagnitude;
469  double m_ExpectedRotationMagnitude;
470  double m_ExpectedScaleMagnitude;
471  double m_ExpectedSkewMagnitude;
472 
473  bool m_CompletedInitialization;
474  RegistrationStageEnumType m_CompletedStage;
475  bool m_CompletedResampling;
476 
477  typename TImage::ConstPointer m_CurrentMovingImage;
478  typename MatrixTransformType::Pointer m_CurrentMatrixTransform;
479  typename BSplineTransformType::Pointer m_CurrentBSplineTransform;
480 
481  typename TImage::ConstPointer m_LoadedTransformResampledImage;
482  typename TImage::ConstPointer m_MatrixTransformResampledImage;
483  typename TImage::ConstPointer m_BSplineTransformResampledImage;
484 
485  double m_FinalMetricValue;
486 
487  typename TImage::ConstPointer m_BaselineImage;
488  unsigned int m_BaselineNumberOfFailedPixelsTolerance;
489  PixelType m_BaselineIntensityTolerance;
490  unsigned int m_BaselineRadiusTolerance;
491  typename TImage::ConstPointer m_BaselineResampledMovingImage;
492  typename TImage::ConstPointer m_BaselineDifferenceImage;
493  unsigned int m_BaselineNumberOfFailedPixels;
494  bool m_BaselineTestPassed;
495 
496  bool m_ReportProgress;
497  bool m_MinimizeMemory;
498 
499  // Loaded Tansform
500  typename MatrixTransformType::Pointer m_LoadedMatrixTransform;
501  typename BSplineTransformType::Pointer m_LoadedBSplineTransform;
502 
503  // Initial Parameters
504  InitialMethodEnumType m_InitialMethodEnum;
505  typename InitialTransformType::Pointer m_InitialTransform;
506  LandmarkPointContainer m_FixedLandmarks;
507  LandmarkPointContainer m_MovingLandmarks;
508 
509  // Rigid Parameters
510  double m_RigidSamplingRatio;
511  double m_RigidTargetError;
512  unsigned int m_RigidMaxIterations;
513 
514  typename RigidTransformType::Pointer m_RigidTransform;
515  MetricMethodEnumType m_RigidMetricMethodEnum;
516  InterpolationMethodEnumType m_RigidInterpolationMethodEnum;
517 
518  double m_RigidMetricValue;
519 
520  // Affine Parameters
521  double m_AffineSamplingRatio;
522  double m_AffineTargetError;
523  unsigned int m_AffineMaxIterations;
524 
525  typename AffineTransformType::Pointer m_AffineTransform;
526  MetricMethodEnumType m_AffineMetricMethodEnum;
527  InterpolationMethodEnumType m_AffineInterpolationMethodEnum;
528 
529  double m_AffineMetricValue;
530 
531  // BSpline Parameters
532  double m_BSplineSamplingRatio;
533  double m_BSplineTargetError;
534  unsigned int m_BSplineMaxIterations;
535  double m_BSplineControlPointPixelSpacing;
536 
537  typename BSplineTransformType::Pointer m_BSplineTransform;
538  MetricMethodEnumType m_BSplineMetricMethodEnum;
539  InterpolationMethodEnumType m_BSplineInterpolationMethodEnum;
540 
541  double m_BSplineMetricValue;
542 
543 };
544 
545 }
546 
547 #ifndef ITK_MANUAL_INSTANTIATION
548 #include "itkImageToImageRegistrationHelper.txx"
549 #endif
550 
551 #endif
void SetFixedLandmarks(const LandmarkVectorType &fixedLandmarks)
OptimizedImageToImageRegistrationMethod< TImage > OptimizedRegistrationMethodType
void SetLoadedBSplineTransform(const BSplineTransformType &tfm)
void LoadParameters(const std::string filename)
itkGetConstObjectMacro(FixedImage, TImage)
void SaveImage(const std::string filename, const TImage *image)
RigidRegistrationMethodType::TransformType RigidTransformType
void SaveParameters(const std::string filename)
void SetMovingLandmarks(const LandmarkVectorType &movingLandmarks)
Simplified inverse ITK transforms.
itkTypeMacro(ImageToImageRegistrationHelper, Object)
BSplineImageToImageRegistrationMethod< TImage > BSplineRegistrationMethodType
void LoadBaselineImage(const std::string filename)
AffineTransform< double, itkGetStaticConstMacro(ImageDimension)> TransformType
RegistrationMethodType::MaskObjectType MaskObjectType
OptimizedRegistrationMethodType::InterpolationMethodEnumType InterpolationMethodEnumType
OptimizedRegistrationMethodType::MetricMethodEnumType MetricMethodEnumType
void SetMovingImageMaskObject(const MaskObjectType *mask)
void LoadFixedImage(const std::string filename)
void SetLoadedMatrixTransform(const MatrixTransformType &tfm)
TImage::ConstPointer ResampleImage(InterpolationMethodEnumType interp=OptimizedRegistrationMethodType ::LINEAR_INTERPOLATION, const TImage *movingImage=NULL, const MatrixTransformType *matrixTransform=NULL, const BSplineTransformType *bsplineTransform=NULL, PixelType defaultPixelValue=0)
ImageToImageRegistrationMethod< TImage > RegistrationMethodType
void LoadMovingImage(const std::string filename)
InitialRegistrationMethodType::TransformType InitialTransformType
Point< double, itkGetStaticConstMacro(ImageDimension)> LandmarkPointType
AffineRegistrationMethodType::TransformType AffineTransformType
itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension)
itkSetConstObjectMacro(FixedImage, TImage)
void SaveTransform(const std::string filename)
AffineImageToImageRegistrationMethod< TImage > AffineRegistrationMethodType
TImage::ConstPointer GetFinalMovingImage(InterpolationMethodEnumType interp=OptimizedRegistrationMethodType ::LINEAR_INTERPOLATION)
std::vector< std::vector< float > > LandmarkVectorType
itkSetMacro(RandomNumberSeed, unsigned int)
void SetRegionOfInterest(const PointType &point1, const PointType &point2)
SpatialObject< itkGetStaticConstMacro(ImageDimension)> MaskObjectType
itkGetConstMacro(UseFixedImageMaskObject, bool)
void LoadTransform(const std::string filename)
RigidImageToImageRegistrationMethod< TImage > RigidRegistrationMethodType
itkBooleanMacro(UseFixedImageMaskObject)
BSplineRegistrationMethodType::TransformType BSplineTransformType
itkGetMacro(RandomNumberSeed, unsigned int)
void SetFixedImageMaskObject(const MaskObjectType *mask)
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
void PrintSelfHelper(std::ostream &os, Indent indent, const std::string basename, MetricMethodEnumType metric, InterpolationMethodEnumType interpolation) const
InitialImageToImageRegistrationMethod< TImage > InitialRegistrationMethodType