Slicer  4.11
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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();
200 
203  void Update();
204 
205  // **************
206  // **************
207  // Resample
208  // **************
209  // **************
210  typename TImage::ConstPointer ResampleImage(
213  ::LINEAR_INTERPOLATION, const TImage * movingImage = nullptr,
214  const MatrixTransformType * matrixTransform = nullptr, const BSplineTransformType * bsplineTransform = nullptr,
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
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:
426 
427  void PrintSelfHelper( std::ostream & os, Indent indent, const std::string basename, MetricMethodEnumType metric,
428  InterpolationMethodEnumType interpolation ) const;
429 
430  void PrintSelf( std::ostream & os, Indent indent ) const override;
431 
432 private:
433 
435  LandmarkPointType;
437  LandmarkPointContainer;
438 
439  ImageToImageRegistrationHelper( const Self & ); // Purposely not implemented
440  void operator =( const Self & ); // Purposely not implemented
441 
442  // Data
443  typename TImage::ConstPointer m_FixedImage;
444  typename TImage::ConstPointer m_MovingImage;
445 
446  bool m_SampleFromOverlap;
447  double m_SampleIntensityPortion;
448 
449  bool m_UseFixedImageMaskObject;
450  typename MaskObjectType::ConstPointer m_FixedImageMaskObject;
451  bool m_UseMovingImageMaskObject;
452  typename MaskObjectType::ConstPointer m_MovingImageMaskObject;
453 
454  bool m_UseRegionOfInterest;
455  PointType m_RegionOfInterestPoint1;
456  PointType m_RegionOfInterestPoint2;
457 
458  unsigned int m_RandomNumberSeed;
459 
460  // Process
461  bool m_EnableLoadedRegistration;
462  bool m_EnableInitialRegistration;
463  bool m_EnableRigidRegistration;
464  bool m_EnableAffineRegistration;
465  bool m_EnableBSplineRegistration;
466 
467  double m_ExpectedOffsetPixelMagnitude;
468  double m_ExpectedRotationMagnitude;
469  double m_ExpectedScaleMagnitude;
470  double m_ExpectedSkewMagnitude;
471 
472  bool m_CompletedInitialization;
473  RegistrationStageEnumType m_CompletedStage;
474  bool m_CompletedResampling;
475 
476  typename TImage::ConstPointer m_CurrentMovingImage;
477  typename MatrixTransformType::Pointer m_CurrentMatrixTransform;
478  typename BSplineTransformType::Pointer m_CurrentBSplineTransform;
479 
480  typename TImage::ConstPointer m_LoadedTransformResampledImage;
481  typename TImage::ConstPointer m_MatrixTransformResampledImage;
482  typename TImage::ConstPointer m_BSplineTransformResampledImage;
483 
484  double m_FinalMetricValue;
485 
486  typename TImage::ConstPointer m_BaselineImage;
487  unsigned int m_BaselineNumberOfFailedPixelsTolerance;
488  PixelType m_BaselineIntensityTolerance;
489  unsigned int m_BaselineRadiusTolerance;
490  typename TImage::ConstPointer m_BaselineResampledMovingImage;
491  typename TImage::ConstPointer m_BaselineDifferenceImage;
492  unsigned int m_BaselineNumberOfFailedPixels;
493  bool m_BaselineTestPassed;
494 
495  bool m_ReportProgress;
496  bool m_MinimizeMemory;
497 
498  // Loaded Tansform
499  typename MatrixTransformType::Pointer m_LoadedMatrixTransform;
500  typename BSplineTransformType::Pointer m_LoadedBSplineTransform;
501 
502  // Initial Parameters
503  InitialMethodEnumType m_InitialMethodEnum;
504  typename InitialTransformType::Pointer m_InitialTransform;
505  LandmarkPointContainer m_FixedLandmarks;
506  LandmarkPointContainer m_MovingLandmarks;
507 
508  // Rigid Parameters
509  double m_RigidSamplingRatio;
510  double m_RigidTargetError;
511  unsigned int m_RigidMaxIterations;
512 
513  typename RigidTransformType::Pointer m_RigidTransform;
514  MetricMethodEnumType m_RigidMetricMethodEnum;
515  InterpolationMethodEnumType m_RigidInterpolationMethodEnum;
516 
517  double m_RigidMetricValue;
518 
519  // Affine Parameters
520  double m_AffineSamplingRatio;
521  double m_AffineTargetError;
522  unsigned int m_AffineMaxIterations;
523 
524  typename AffineTransformType::Pointer m_AffineTransform;
525  MetricMethodEnumType m_AffineMetricMethodEnum;
526  InterpolationMethodEnumType m_AffineInterpolationMethodEnum;
527 
528  double m_AffineMetricValue;
529 
530  // BSpline Parameters
531  double m_BSplineSamplingRatio;
532  double m_BSplineTargetError;
533  unsigned int m_BSplineMaxIterations;
534  double m_BSplineControlPointPixelSpacing;
535 
536  typename BSplineTransformType::Pointer m_BSplineTransform;
537  MetricMethodEnumType m_BSplineMetricMethodEnum;
538  InterpolationMethodEnumType m_BSplineInterpolationMethodEnum;
539 
540  double m_BSplineMetricValue;
541 
542 };
543 
544 }
545 
546 #ifndef ITK_MANUAL_INSTANTIATION
547 #include "itkImageToImageRegistrationHelper.txx"
548 #endif
549 
550 #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)
ImageToImageRegistrationMethod< TImage > RegistrationMethodType
void LoadMovingImage(const std::string filename)
InitialRegistrationMethodType::TransformType InitialTransformType
TImage::ConstPointer ResampleImage(InterpolationMethodEnumType interp=OptimizedRegistrationMethodType ::LINEAR_INTERPOLATION, const TImage *movingImage=nullptr, const MatrixTransformType *matrixTransform=nullptr, const BSplineTransformType *bsplineTransform=nullptr, PixelType defaultPixelValue=0)
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
void PrintSelf(std::ostream &os, Indent indent) const override
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 PrintSelfHelper(std::ostream &os, Indent indent, const std::string basename, MetricMethodEnumType metric, InterpolationMethodEnumType interpolation) const
InitialImageToImageRegistrationMethod< TImage > InitialRegistrationMethodType