NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
itkNCCImageToImageMetric.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 itkNCCImageToImageMetric_h
16 #define itkNCCImageToImageMetric_h
17 
19 
20 namespace itk
21 {
28 template < class TFixedImage, class TMovingImage >
29 class ITK_EXPORT NCCImageToImageMetric :
30  public FiniteDifferenceGradientSimilarityMeasure< TFixedImage, TMovingImage>
31 {
32 public:
33 
37  typedef SmartPointer<Self> Pointer;
38  typedef SmartPointer<const Self> ConstPointer;
42 
44  itkNewMacro(Self);
45 
48 
50  bool ShouldBeMaximized() { return true; };
51 
52 protected:
53 
55  virtual ~NCCImageToImageMetric() {};
56 
61  {
62  m_numberCounted = 0;
63  m_sf = 0;
64  m_sm = 0;
65  m_sff = 0;
66  m_smm = 0;
67  m_sfm = 0;
68  }
69 
74  FixedImagePixelType fixedValue,
75  MovingImagePixelType movingValue)
76  {
77  m_numberCounted++;
78  m_sf += fixedValue;
79  m_sm += movingValue;
80  m_sff += (fixedValue*fixedValue);
81  m_smm += (movingValue*movingValue);
82  m_sfm += (fixedValue*movingValue);
83  }
84 
86  FixedImagePixelType fixedValue,
87  MovingImagePixelType movingValue, double weight)
88  {
89  m_numberCounted += weight;
90  m_sf += fixedValue*weight;
91  m_sm += movingValue*weight;
92  m_sff += (fixedValue*fixedValue)*weight;
93  m_smm += (movingValue*movingValue)*weight;
94  m_sfm += (fixedValue*movingValue)*weight;
95  }
96 
100  MeasureType FinalizeCostFunction()
101  {
102  double denom;
103  double measure = 0;
104 
105  if (m_numberCounted > 0)
106  {
107  m_sff -= (m_sf * m_sf / m_numberCounted);
108  m_smm -= (m_sm * m_sm / m_numberCounted);
109  m_sfm -= (m_sf * m_sm / m_numberCounted);
110  denom = 1 * vcl_sqrt(m_sff * m_smm);
111  if ( denom != 0. )
112  {
113  measure = m_sfm / denom;
114  }
115  }
116  return measure*measure;
117  }
118 
119 private:
120  NCCImageToImageMetric(const Self&); // purposefully not implemented
121  void operator=(const Self&); // purposefully not implemented
122 
123  double m_numberCounted;
124  double m_sf;
125  double m_sm;
126  double m_sff;
127  double m_smm;
128  double m_sfm;
129 };
130 
131 } // end namespace itk
132 
133 #endif
134 
135 
136 
Implements Normalized Cross Correlation similarity measure.
Definition: itkNCCImageToImageMetric.h:29
Superclass::MeasureType MeasureType
Definition: itkNCCImageToImageMetric.h:41
Superclass::FixedImageType::PixelType FixedImagePixelType
Definition: itkNCCImageToImageMetric.h:39
SmartPointer< Self > Pointer
Definition: itkNCCImageToImageMetric.h:37
Abstract base class, implementing TemplateMethod [2] for similarity measures.
Definition: itkSimilarityMeasure.h:56
NCCImageToImageMetric Self
Definition: itkNCCImageToImageMetric.h:35
Definition: niftkITKAffineResampleImage.cxx:74
GLuint GLuint GLfloat weight
Definition: glew.h:11786
bool ShouldBeMaximized()
Definition: itkNCCImageToImageMetric.h:50
void ResetCostFunction()
Definition: itkNCCImageToImageMetric.h:60
virtual void AggregateCostFunctionPairWithWeighting(FixedImagePixelType fixedValue, MovingImagePixelType movingValue, double weight)
Definition: itkNCCImageToImageMetric.h:85
MeasureType FinalizeCostFunction()
Definition: itkNCCImageToImageMetric.h:100
void AggregateCostFunctionPair(FixedImagePixelType fixedValue, MovingImagePixelType movingValue)
Definition: itkNCCImageToImageMetric.h:73
float PixelType
Definition: niftkBreastDCEandADC.cxx:88
SmartPointer< const Self > ConstPointer
Definition: itkNCCImageToImageMetric.h:38
AbstractBase class, just to implement the finite difference gradient method.
Definition: itkFiniteDifferenceGradientSimilarityMeasure.h:32
NCCImageToImageMetric()
Definition: itkNCCImageToImageMetric.h:54
SimilarityMeasure< TFixedImage, TMovingImage > Superclass
Definition: itkNCCImageToImageMetric.h:36
Superclass::MovingImageType::PixelType MovingImagePixelType
Definition: itkNCCImageToImageMetric.h:40
Superclass::MeasureType MeasureType
Definition: itkSimilarityMeasure.h:80
virtual ~NCCImageToImageMetric()
Definition: itkNCCImageToImageMetric.h:55