NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
itkBlockMatchingMethod.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 #ifndef itkBlockMatchingMethod_h
16 #define itkBlockMatchingMethod_h
17 
18 
20 #include <itkResampleImageFilter.h>
21 #include <itkArray.h>
22 #include <itkPointSet.h>
23 #include <itkRegionOfInterestImageFilter.h>
24 #include <itkNearestNeighborInterpolateImageFunction.h>
25 #include <itkSimilarityMeasure.h>
26 #include <itkDefaultStaticMeshTraits.h>
28 #include <itkCovarianceSampleFilter.h>
29 #include <itkImageToListSampleAdaptor.h>
30 #include <itkGradientMagnitudeImageFilter.h>
31 #include <itkMinimumMaximumImageCalculator.h>
32 
33 namespace itk
34 {
66 template <typename TImageType, class TScalarType>
67 class ITK_EXPORT BlockMatchingMethod
68 : public MaskedImageRegistrationMethod<TImageType>
69 {
70 public:
71 
75  typedef SmartPointer<Self> Pointer;
76  typedef SmartPointer<const Self> ConstPointer;
77 
79  itkNewMacro(Self);
80 
83 
85  itkStaticConstMacro(Dimension, unsigned int, TImageType::ImageDimension);
86 
88  typedef TImageType ImageType;
91  typedef typename ImageType::SpacingType ImageSpacingType;
95  typedef typename ResampleFilterType::Pointer ResampleFilterPointer;
96  typedef RegionOfInterestImageFilter<TImageType, TImageType> RegionOfInterestFilterType;
97  typedef typename RegionOfInterestFilterType::Pointer RegionOfInterestFilterPointer;
98 
99  // We either calculate the variance, based on the image, which will be whatever scalar type is passed in as template parameter
100  typedef itk::Statistics::ImageToListSampleAdaptor< ImageType > ImageTypeListAdaptorType;
101  typedef typename ImageTypeListAdaptorType::Pointer ImageTypeListAdaptorPointer;
102  typedef itk::Statistics::CovarianceSampleFilter< ImageTypeListAdaptorType > ImageTypeCovarianceSampleFilterType;
103  typedef typename ImageTypeCovarianceSampleFilterType::Pointer ImageTypeCovarianceSampleFilterPointer;
104 
105  // Or we take the gradient magnitude image, so we should do it as a float.
107  typedef GradientMagnitudeImageFilter<TImageType, GradientImageType> GradientMagnitudeFilterType;
108  typedef typename GradientMagnitudeFilterType::Pointer GradientMagnitudeFilterPointer;
109  typedef itk::Statistics::ImageToListSampleAdaptor< GradientImageType > GradientImageTypeListAdaptorType;
110  typedef typename GradientImageTypeListAdaptorType::Pointer GradientImageTypeListAdaptorPointer;
111  typedef itk::Statistics::CovarianceSampleFilter< GradientImageTypeListAdaptorType > GradientImageTypeCovarianceSampleFilterType;
112  typedef typename GradientImageTypeCovarianceSampleFilterType::Pointer GradientImageTypeCovarianceSampleFilterPointer;
113 
115  typedef SimilarityMeasureType* SimilarityMeasurePointer;
116  typedef NearestNeighborInterpolateImageFunction< TImageType,
117  TScalarType> DummyInterpolatorType;
118  typedef typename DummyInterpolatorType::Pointer DummyInterpolatorPointer;
120  typedef PointSet< TScalarType,
121  TImageType::ImageDimension,
122  DefaultStaticMeshTraits
123  <
124  TScalarType,
125  TImageType::ImageDimension,
126  TImageType::ImageDimension,
127  TScalarType,
128  TScalarType
129  >
131  typedef typename PointSetType::PointType PointType;
132  typedef typename PointSetType::PointsContainer::ConstIterator PointIterator;
133  typedef typename PointSetType::Pointer PointSetPointer;
134  typedef typename PointSetType::PointsContainer PointsContainerType;
135  typedef typename PointsContainerType::Pointer PointsContainerPointer;
137  PointSetType> PointSetMetricType;
140  typedef TransformType* TransformPointer;
141  typedef MinimumMaximumImageCalculator<TImageType> MinimumMaximumImageCalculatorType;
142  typedef typename MinimumMaximumImageCalculatorType::Pointer MinimumMaximumImageCalculatorPointer;
143 
145  itkSetObjectMacro(PointSetMetric, PointSetMetricType);
146  itkGetObjectMacro(PointSetMetric, PointSetMetricType);
147 
149  itkSetMacro(MaximumNumberOfIterationsRoundMainLoop, unsigned int);
150  itkGetMacro(MaximumNumberOfIterationsRoundMainLoop, unsigned int);
151 
167  void SetBlockParameters(
168  double blockSize,
169  double blockHalfWidth,
170  double blockSpacing,
171  double blockSubSampling);
172 
176  itkGetMacro(BlockSize, double);
177 
181  itkGetMacro(BlockHalfWidth, double);
182 
186  itkGetMacro(BlockSpacing, double);
187 
191  itkGetMacro(BlockSubSampling, double);
192 
194  itkSetMacro(TransformedMovingImageFileName, std::string);
195  itkGetMacro(TransformedMovingImageFileName, std::string);
196 
198  itkSetMacro(TransformedMovingImageFileExt, std::string);
199  itkGetMacro(TransformedMovingImageFileExt, std::string);
200 
202  itkSetMacro(WriteTransformedMovingImage, bool);
203  itkGetMacro(WriteTransformedMovingImage, bool);
204 
209  itkSetMacro(Epsilon, double);
210  itkGetMacro(Epsilon, double);
211 
216  itkSetMacro(ParameterReductionFactor, double);
217  itkGetMacro(ParameterReductionFactor, double);
218 
220  itkSetMacro(MinimumBlockSize, double);
221  itkGetMacro(MinimumBlockSize, double);
222 
231  itkSetMacro(PercentageOfPointsToKeep, int);
232  itkGetMacro(PercentageOfPointsToKeep, int);
233 
241  itkSetMacro(PercentageOfPointsInLeastTrimmedSquares, int);
242  itkGetMacro(PercentageOfPointsInLeastTrimmedSquares, int);
243 
248  itkSetMacro(UseGradientMagnitudeVariance, bool);
249  itkGetMacro(UseGradientMagnitudeVariance, bool);
250 
252  itkSetMacro(ScaleByMillimetres, bool);
253  itkGetMacro(ScaleByMillimetres, bool);
254 
256  itkSetMacro(PointSetFileNameWithoutExtension, std::string);
257  itkGetMacro(PointSetFileNameWithoutExtension, std::string);
258 
260  itkSetMacro(WritePointSet, bool);
261  itkGetMacro(WritePointSet, bool);
262 
264  itkSetMacro(NoZero, bool);
265  itkGetMacro(NoZero, bool);
266 
268  itkSetMacro(TransformedMovingImagePadValue, ImagePixelType);
269  itkGetMacro(TransformedMovingImagePadValue, ImagePixelType);
270 
271 protected:
272 
274  virtual ~BlockMatchingMethod() {};
275  void PrintSelf(std::ostream& os, Indent indent) const;
276 
278  virtual void Initialize() throw (ExceptionObject);
279 
281  virtual void DoRegistration() throw (ExceptionObject);
282 
284  virtual void WritePointSet(const PointsContainerPointer& fixedPointContainer,
285  const PointsContainerPointer& movingPointContainer);
286 
288  virtual void GetPointCorrespondencies2D(
289  ImageSizeType& size,
290  ImageSizeType& bigN,
291  ImageSizeType& bigOmega,
292  ImageSizeType& bigDeltaOne,
293  ImageSizeType& bigDeltaTwo,
294  PointsContainerPointer& fixedPointContainer,
295  PointsContainerPointer& movingPointContainer
296  );
297 
299  virtual void GetPointCorrespondencies3D(
300  ImageSizeType& size,
301  ImageSizeType& bigN,
302  ImageSizeType& bigOmega,
303  ImageSizeType& bigDeltaOne,
304  ImageSizeType& bigDeltaTwo,
305  PointsContainerPointer& fixedPointContainer,
306  PointsContainerPointer& movingPointContainer
307  );
308 
310  virtual bool CheckEpsilon(ParametersType& previousParameters, ParametersType& currentParameters);
311 
313  virtual double CheckSinglePoint(ParametersType& previousParameters, ParametersType& currentParameters, ImageIndexType& index);
314 
316  virtual void TrimPoints(const TransformType* transform,
317  const PointsContainerType* fixedPoints,
318  const PointsContainerType* movingPoints,
319  PointsContainerType* trimmedFixedPoints,
320  PointsContainerType* trimmedMovingPoints);
321 
327  {
328  public:
329  VarianceHeapDataType(const TScalarType& aKey, const ImageIndexType& anIndex)
330  {
331  this->key = aKey;
332  this->index = anIndex;
333  }
334 
335  void operator=(const VarianceHeapDataType& another)
336  {
337  this->key = another.key;
338  this->index = another.index;
339  }
340 
341  friend bool operator<(
342  const VarianceHeapDataType& x, const VarianceHeapDataType& y)
343  {
344  if(x.GetKey() < y.GetKey())
345  return true;
346  else
347  return false;
348  }
349 
350  void SetKey(const TScalarType& aKey) { this->key = aKey; }
351  TScalarType GetKey() const { return this->key; }
352 
353  void SetIndex(const ImageIndexType& anIndex) { this->index = anIndex; }
354  ImageIndexType GetIndex() const { return this->index; }
355 
356  private:
357  TScalarType key;
358  ImageIndexType index;
359  };
360 
361  typedef std::priority_queue<VarianceHeapDataType> VarianceHeap;
362 
368  {
369 
370  public:
371  ResidualHeapDataType(const TScalarType& aResidual, const PointType& aFixedPoint, const PointType& aMovingPoint)
372  {
373  this->residual = aResidual;
374  this->fixed = aFixedPoint;
375  this->moving = aMovingPoint;
376  }
377 
378  void operator=(const ResidualHeapDataType& another)
379  {
380  this->residual = another.residual;
381  this->fixed = another.fixed;
382  this->moving = another.moving;
383  }
384 
385  friend bool operator<(
387  {
388  if(y.GetResidual() < x.GetResidual())
389  return true;
390  else
391  return false;
392  }
393 
394  void SetResidual(const TScalarType& aResidual) { this->residual = aResidual; }
395  TScalarType GetResidual() const { return this->residual; }
396 
397  void SetFixed(const PointType& aFixedPoint) { this->fixed = aFixedPoint; }
398  PointType GetFixed() const { return this->fixed; }
399 
400  void SetMoving(const PointType& aMovingPoint) { this->moving = aMovingPoint; }
401  PointType GetMoving() const { return this->moving; }
402 
403  private:
404  TScalarType residual;
405  PointType fixed;
406  PointType moving;
407  };
408 
409  typedef std::priority_queue<ResidualHeapDataType> ResidualHeap;
410 
411 private:
412 
413  BlockMatchingMethod(const Self&); // purposely not implemented
414  void operator=(const Self&); // purposely not implemented
415 
416  ResampleFilterPointer m_MovingImageResampler;
417 
418  RegionOfInterestFilterPointer m_FixedImageRegionFilter;
419 
420  ImageTypeListAdaptorPointer m_FixedImageListAdaptor;
421  ImageTypeCovarianceSampleFilterPointer m_FixedImageCovarianceSampleFilter;
422 
423  GradientMagnitudeFilterPointer m_GradientMagnitudeImageFilter;
424  GradientImageTypeListAdaptorPointer m_GradientMagnitudeListAdaptor;
425  GradientImageTypeCovarianceSampleFilterPointer m_GradientMagnitudeCovarianceSampleFilter;
426 
427  DummyInterpolatorPointer m_DummyInterpolator;
428 
429  PointSetPointer m_FixedPointSet;
430  PointsContainerPointer m_FixedPointSetContainer;
431 
432  PointSetPointer m_MovingPointSet;
433  PointsContainerPointer m_MovingPointSetContainer;
434 
435  PointSetMetricPointer m_PointSetMetric;
436 
437  unsigned int m_MaximumNumberOfIterationsRoundMainLoop;
438 
439  double m_BlockSize;
440 
441  double m_BlockHalfWidth;
442 
443  double m_BlockSpacing;
444 
445  double m_BlockSubSampling;
446 
447  double m_Epsilon;
448 
449  double m_ParameterReductionFactor;
450 
451  double m_MinimumBlockSize;
452 
453  int m_PercentageOfPointsToKeep;
454 
455  int m_PercentageOfPointsInLeastTrimmedSquares;
456 
457  std::string m_TransformedMovingImageFileName;
458 
459  std::string m_TransformedMovingImageFileExt;
460 
461  bool m_WriteTransformedMovingImage;
462 
463  std::string m_PointSetFileNameWithoutExtension;
464 
465  bool m_WritePointSet;
466 
467  bool m_ScaleByMillimetres;
468 
469  bool m_UseGradientMagnitudeVariance;
470 
471  bool m_NoZero;
472 
473  ImagePixelType m_TransformedMovingImagePadValue;
474 
475  MinimumMaximumImageCalculatorPointer m_MinMaxCalculator;
476 };
477 
478 } // end namespace itk
479 
480 #ifndef ITK_MANUAL_INSTANTIATION
481 #include "itkBlockMatchingMethod.txx"
482 #endif
483 
484 #endif
485 
486 
487 
PointSet< TScalarType, TImageType::ImageDimension, DefaultStaticMeshTraits< TScalarType, TImageType::ImageDimension, TImageType::ImageDimension, TScalarType, TScalarType > > PointSetType
Definition: itkBlockMatchingMethod.h:130
PointSetType::Pointer PointSetPointer
Definition: itkBlockMatchingMethod.h:133
VarianceHeapDataType(const TScalarType &aKey, const ImageIndexType &anIndex)
Definition: itkBlockMatchingMethod.h:329
TScalarType GetKey() const
Definition: itkBlockMatchingMethod.h:351
itk::Statistics::ImageToListSampleAdaptor< ImageType > ImageTypeListAdaptorType
Definition: itkBlockMatchingMethod.h:100
friend bool operator<(const VarianceHeapDataType &x, const VarianceHeapDataType &y)
Definition: itkBlockMatchingMethod.h:341
GradientImageTypeCovarianceSampleFilterType::Pointer GradientImageTypeCovarianceSampleFilterPointer
Definition: itkBlockMatchingMethod.h:112
Superclass::ParametersType ParametersType
Definition: itkSingleResolutionImageRegistrationMethod.h:52
Abstract base class, implementing TemplateMethod [2] for similarity measures.
Definition: itkSimilarityMeasure.h:56
Base class for NifTK Image Registration Methods employing a binary mask.
Definition: itkMaskedImageRegistrationMethod.h:55
ImageType::SizeType SizeType
Definition: niftkMakeLapUSProbeBasicModel.cxx:31
void operator=(const ResidualHeapDataType &another)
Definition: itkBlockMatchingMethod.h:378
std::priority_queue< VarianceHeapDataType > VarianceHeap
Definition: itkBlockMatchingMethod.h:361
ImageTypeListAdaptorType::Pointer ImageTypeListAdaptorPointer
Definition: itkBlockMatchingMethod.h:101
ImageTypeCovarianceSampleFilterType::Pointer ImageTypeCovarianceSampleFilterPointer
Definition: itkBlockMatchingMethod.h:103
SimilarityMeasure< TImageType, TImageType > SimilarityMeasureType
Definition: itkBlockMatchingMethod.h:114
SmartPointer< Self > Pointer
Definition: itkPointSetToPointSetSingleValuedMetric.h:49
ImageType::SpacingType ImageSpacingType
Definition: itkBlockMatchingMethod.h:91
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1236
MinimumMaximumImageCalculatorType::Pointer MinimumMaximumImageCalculatorPointer
Definition: itkBlockMatchingMethod.h:142
PointSetType::PointsContainer PointsContainerType
Definition: itkBlockMatchingMethod.h:134
Definition: niftkITKAffineResampleImage.cxx:74
ImageType::IndexType IndexType
Definition: niftkMakeLapUSProbeBasicModel.cxx:32
RegionOfInterestFilterType::Pointer RegionOfInterestFilterPointer
Definition: itkBlockMatchingMethod.h:97
void SetKey(const TScalarType &aKey)
Definition: itkBlockMatchingMethod.h:350
NearestNeighborInterpolateImageFunction< TImageType, TScalarType > DummyInterpolatorType
Definition: itkBlockMatchingMethod.h:117
ImageType::PixelType ImagePixelType
Definition: itkBlockMatchingMethod.h:90
GLuint GLenum GLenum transform
Definition: glew.h:12775
GradientMagnitudeImageFilter< TImageType, GradientImageType > GradientMagnitudeFilterType
Definition: itkBlockMatchingMethod.h:107
RegionOfInterestImageFilter< TImageType, TImageType > RegionOfInterestFilterType
Definition: itkBlockMatchingMethod.h:96
PointType GetMoving() const
Definition: itkBlockMatchingMethod.h:401
Image< float, TImageType::ImageDimension > GradientImageType
Definition: itkBlockMatchingMethod.h:106
TransformType * TransformPointer
Definition: itkBlockMatchingMethod.h:140
virtual ~BlockMatchingMethod()
Definition: itkBlockMatchingMethod.h:274
Superclass::TransformType TransformType
Definition: itkBlockMatchingMethod.h:139
itk::Statistics::CovarianceSampleFilter< ImageTypeListAdaptorType > ImageTypeCovarianceSampleFilterType
Definition: itkBlockMatchingMethod.h:102
SmartPointer< const Self > ConstPointer
Definition: itkBlockMatchingMethod.h:76
float PixelType
Definition: niftkBreastDCEandADC.cxx:88
PointSetType::PointsContainer::ConstIterator PointIterator
Definition: itkBlockMatchingMethod.h:132
ImageIndexType GetIndex() const
Definition: itkBlockMatchingMethod.h:354
Superclass::TransformType TransformType
Definition: itkMaskedImageRegistrationMethod.h:129
TImageType ImageType
Definition: itkBlockMatchingMethod.h:88
ImageType::RegionType RegionType
Definition: niftkMakeLapUSProbeBasicModel.cxx:30
TScalarType GetResidual() const
Definition: itkBlockMatchingMethod.h:395
std::priority_queue< ResidualHeapDataType > ResidualHeap
Definition: itkBlockMatchingMethod.h:409
void SetResidual(const TScalarType &aResidual)
Definition: itkBlockMatchingMethod.h:394
Computes similarity between two point sets, but sums it up to a single value.
Definition: itkPointSetToPointSetSingleValuedMetric.h:42
ResampleFilterType::Pointer ResampleFilterPointer
Definition: itkBlockMatchingMethod.h:95
friend bool operator<(const ResidualHeapDataType &x, const ResidualHeapDataType &y)
Definition: itkBlockMatchingMethod.h:385
GLuint index
Definition: glew.h:1798
ImageType::SizeType ImageSizeType
Definition: itkBlockMatchingMethod.h:89
PointSetType::PointType PointType
Definition: itkBlockMatchingMethod.h:131
DummyInterpolatorType::Pointer DummyInterpolatorPointer
Definition: itkBlockMatchingMethod.h:118
GradientImageTypeListAdaptorType::Pointer GradientImageTypeListAdaptorPointer
Definition: itkBlockMatchingMethod.h:110
GLint GLint GLint GLint GLint x
Definition: glew.h:1236
Superclass::ParametersType ParametersType
Definition: itkBlockMatchingMethod.h:119
Initial implementation of Seb Ourselin's block matching algorithm.
Definition: itkBlockMatchingMethod.h:67
void SetIndex(const ImageIndexType &anIndex)
Definition: itkBlockMatchingMethod.h:353
GLsizeiptr size
Definition: glew.h:1665
ImageType::RegionType ImageRegionType
Definition: itkBlockMatchingMethod.h:92
Simultaneous itk::Image and itk::Array (and hence vnl_vector) class.
void SetMoving(const PointType &aMovingPoint)
Definition: itkBlockMatchingMethod.h:400
const unsigned int Dimension
Definition: niftkBreastDCEandADC.cxx:89
itk::Statistics::ImageToListSampleAdaptor< GradientImageType > GradientImageTypeListAdaptorType
Definition: itkBlockMatchingMethod.h:109
ResampleImageFilter< TImageType, TImageType > ResampleFilterType
Definition: itkBlockMatchingMethod.h:94
Resample an image via a coordinate transform.
void operator=(const VarianceHeapDataType &another)
Definition: itkBlockMatchingMethod.h:335
ImageType::IndexType ImageIndexType
Definition: itkBlockMatchingMethod.h:93
GradientMagnitudeFilterType::Pointer GradientMagnitudeFilterPointer
Definition: itkBlockMatchingMethod.h:108
PointType GetFixed() const
Definition: itkBlockMatchingMethod.h:398
PointSetToPointSetSingleValuedMetric< PointSetType, PointSetType > PointSetMetricType
Definition: itkBlockMatchingMethod.h:137
PointsContainerType::Pointer PointsContainerPointer
Definition: itkBlockMatchingMethod.h:135
BlockMatchingMethod Self
Definition: itkBlockMatchingMethod.h:73
So we can have an ordered list of points, based on the residual between transformed fixed and moving...
Definition: itkBlockMatchingMethod.h:367
MinimumMaximumImageCalculator< TImageType > MinimumMaximumImageCalculatorType
Definition: itkBlockMatchingMethod.h:141
ResidualHeapDataType(const TScalarType &aResidual, const PointType &aFixedPoint, const PointType &aMovingPoint)
Definition: itkBlockMatchingMethod.h:371
MaskedImageRegistrationMethod< TImageType > Superclass
Definition: itkBlockMatchingMethod.h:74
GLsizei const GLcharARB ** string
Definition: glew.h:5194
SmartPointer< Self > Pointer
Definition: itkBlockMatchingMethod.h:75
itk::Statistics::CovarianceSampleFilter< GradientImageTypeListAdaptorType > GradientImageTypeCovarianceSampleFilterType
Definition: itkBlockMatchingMethod.h:111
void SetFixed(const PointType &aFixedPoint)
Definition: itkBlockMatchingMethod.h:397
SimilarityMeasureType * SimilarityMeasurePointer
Definition: itkBlockMatchingMethod.h:115
PointSetMetricType::Pointer PointSetMetricPointer
Definition: itkBlockMatchingMethod.h:138
So we can have an ordered list of indexes, based on variance of a block.
Definition: itkBlockMatchingMethod.h:326