NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
itkCRImageToImageMetric.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 itkCRImageToImageMetric_h
16 #define itkCRImageToImageMetric_h
17 
19 
20 namespace itk
21 {
35 template < class TFixedImage, class TMovingImage >
36 class ITK_EXPORT CRImageToImageMetric :
37  public FiniteDifferenceGradientSimilarityMeasure< TFixedImage, TMovingImage>
38 {
39 public:
40 
44  typedef SmartPointer<Self> Pointer;
45  typedef SmartPointer<const Self> ConstPointer;
49  typedef std::multimap<FixedImagePixelType, MovingImagePixelType> MapType;
50  typedef typename MapType::iterator MapIterator;
51 
53  itkNewMacro(Self);
54 
57 
59  bool ShouldBeMaximized() { return true; };
60 
61 protected:
62 
64  virtual ~CRImageToImageMetric() {};
65 
70  {
71  this->m_NumberCounted = 0;
72  this->m_MovingSum = 0;
73  this->m_Map.clear();
74  }
75 
80  FixedImagePixelType fixedValue,
81  MovingImagePixelType movingValue)
82  {
83  this->m_NumberCounted++;
84  this->m_MovingSum += movingValue;
85  this->m_Map.insert(std::pair<FixedImagePixelType, MovingImagePixelType>(fixedValue, movingValue));
86  }
87 
91  MeasureType FinalizeCostFunction()
92  {
93  MeasureType measure = 0;
94 
95  double totalMean = 0;
96  double totalSigmaSquared = 0;
97 
98  double conditionalNumber = 0;
99  double conditionalSum = 0;
100  double conditionalMean = 0;
101  double conditionalSigmaSquared = 0;
102 
103  FixedImagePixelType fixedValue;
104  MovingImagePixelType movingValue;
105 
106  MapIterator mapIterator;
107 
108  totalMean = this->m_MovingSum / (double)this->m_NumberCounted;
109 
110  mapIterator = this->m_Map.begin();
111  while(mapIterator != this->m_Map.end())
112  {
113  fixedValue = (*mapIterator).first;
114 
115  conditionalNumber = 0;
116  conditionalSum = 0;
117  conditionalSigmaSquared = 0;
118 
119  while( (mapIterator != this->m_Map.end()) && ((*mapIterator).first == fixedValue) )
120  {
121  movingValue = (*mapIterator).second;
122 
123  conditionalSum += movingValue;
124  conditionalSigmaSquared += movingValue*movingValue;
125  totalSigmaSquared += movingValue*movingValue;
126  mapIterator++;
127  conditionalNumber++;
128  }
129 
130  conditionalMean = conditionalSum / conditionalNumber;
131 
132  conditionalSigmaSquared = (conditionalSigmaSquared / conditionalNumber) - (conditionalMean*conditionalMean);
133 
134  measure += (conditionalNumber * conditionalSigmaSquared);
135 
136  }
137 
138  totalSigmaSquared = (totalSigmaSquared / (double)this->m_NumberCounted) - totalMean;
139 
140  if (totalSigmaSquared == 0)
141  {
142  measure = 0;
143  }
144  else
145  {
146  measure /= ((double)this->m_NumberCounted * totalSigmaSquared);
147  }
148 
149  return 1.0-measure;
150  }
151 
152 private:
153  CRImageToImageMetric(const Self&); // purposefully not implemented
154  void operator=(const Self&); // purposefully not implemented
155 
156  unsigned long int m_NumberCounted;
157  double m_MovingSum;
158  MapType m_Map;
159 
160 };
161 
162 } // end namespace itk
163 
164 #endif
165 
166 
167 
void ResetCostFunction()
Definition: itkCRImageToImageMetric.h:69
Implements Correlation Ratio (Fixed | Moving), without a histogram.
Definition: itkCRImageToImageMetric.h:36
Abstract base class, implementing TemplateMethod [2] for similarity measures.
Definition: itkSimilarityMeasure.h:56
MapType::iterator MapIterator
Definition: itkCRImageToImageMetric.h:50
SmartPointer< const Self > ConstPointer
Definition: itkCRImageToImageMetric.h:45
bool ShouldBeMaximized()
Definition: itkCRImageToImageMetric.h:59
Superclass::MeasureType MeasureType
Definition: itkCRImageToImageMetric.h:48
Definition: niftkITKAffineResampleImage.cxx:74
Superclass::MovingImageType::PixelType MovingImagePixelType
Definition: itkCRImageToImageMetric.h:47
void AggregateCostFunctionPair(FixedImagePixelType fixedValue, MovingImagePixelType movingValue)
Definition: itkCRImageToImageMetric.h:79
std::multimap< FixedImagePixelType, MovingImagePixelType > MapType
Definition: itkCRImageToImageMetric.h:49
Superclass::FixedImageType::PixelType FixedImagePixelType
Definition: itkCRImageToImageMetric.h:46
SimilarityMeasure< TFixedImage, TMovingImage > Superclass
Definition: itkCRImageToImageMetric.h:43
float PixelType
Definition: niftkBreastDCEandADC.cxx:88
AbstractBase class, just to implement the finite difference gradient method.
Definition: itkFiniteDifferenceGradientSimilarityMeasure.h:32
SmartPointer< Self > Pointer
Definition: itkCRImageToImageMetric.h:44
CRImageToImageMetric Self
Definition: itkCRImageToImageMetric.h:42
Superclass::MeasureType MeasureType
Definition: itkSimilarityMeasure.h:80
CRImageToImageMetric()
Definition: itkCRImageToImageMetric.h:63
MeasureType FinalizeCostFunction()
Definition: itkCRImageToImageMetric.h:91
virtual ~CRImageToImageMetric()
Definition: itkCRImageToImageMetric.h:64