ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkMattesMutualInformationImageToImageMetricv4.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkMattesMutualInformationImageToImageMetricv4_h
19 #define __itkMattesMutualInformationImageToImageMetricv4_h
20 
23 #include "itkPoint.h"
24 #include "itkIndex.h"
26 #include "itkArray2D.h"
27 
28 namespace itk
29 {
30 
95 template <class TFixedImage, class TMovingImage, class TVirtualImage = TFixedImage >
97 public ImageToImageMetricv4<TFixedImage, TMovingImage, TVirtualImage>
98 {
99 public:
105 
107  itkNewMacro(Self);
108 
111 
113  typedef typename Superclass::MeasureType MeasureType;
114  typedef typename Superclass::DerivativeType DerivativeType;
115  typedef typename DerivativeType::ValueType DerivativeValueType;
116 
117  typedef typename Superclass::FixedImageType FixedImageType;
118  typedef typename Superclass::FixedImagePointType FixedImagePointType;
119  typedef typename Superclass::FixedImageIndexType FixedImageIndexType;
120  typedef typename Superclass::FixedImagePixelType FixedImagePixelType;
121  typedef typename Superclass::FixedImageGradientType FixedImageGradientType;
122 
123  typedef typename Superclass::MovingImagePointType MovingImagePointType;
124  typedef typename Superclass::MovingImagePixelType MovingImagePixelType;
125  typedef typename Superclass::MovingImageGradientType MovingImageGradientType;
126 
127  typedef typename Superclass::MovingTransformType MovingTransformType;
128  typedef typename Superclass::JacobianType JacobianType;
129  typedef typename Superclass::VirtualImageType VirtualImageType;
130  typedef typename Superclass::VirtualIndexType VirtualIndexType;
131  typedef typename Superclass::VirtualPointType VirtualPointType;
132  typedef typename Superclass::VirtualPointSetType VirtualPointSetType;
133 
135  typedef typename Superclass::FixedSampledPointSetPointer FixedSampledPointSetPointer;
136 
137  /* Image dimension accessors */
138  itkStaticConstMacro(VirtualImageDimension, ImageDimensionType, ::itk::GetImageDimension<TVirtualImage>::ImageDimension);
139  itkStaticConstMacro(FixedImageDimension, ImageDimensionType, ::itk::GetImageDimension<TFixedImage>::ImageDimension);
140  itkStaticConstMacro(MovingImageDimension, ImageDimensionType, ::itk::GetImageDimension<TMovingImage>::ImageDimension);
141 
147  itkSetClampMacro( NumberOfHistogramBins, SizeValueType, 5, NumericTraits<SizeValueType>::max() );
148  itkGetConstReferenceMacro(NumberOfHistogramBins, SizeValueType);
150 
151  virtual void Initialize(void) throw ( itk::ExceptionObject );
152 
153  virtual MeasureType GetValue() const;
154 
158  virtual void GetValueAndDerivative( MeasureType & value, DerivativeType & derivative ) const;
159 
161  //NOTE: floating point precision is not as stable.
162  // Double precision proves faster and more robust in real-world testing.
163  typedef double PDFValueType;
164 
166  typedef Image<PDFValueType, 2> JointPDFType;
167  typedef Image<PDFValueType, 3> JointPDFDerivativesType;
168 
173  const typename JointPDFType::Pointer GetJointPDF () const
174  {
175  if( this->m_ThreaderJointPDF.size() == 0 )
176  {
177  return JointPDFType::Pointer(NULL);
178  }
179  return this->m_ThreaderJointPDF[0];
180  }
182 
189  const typename JointPDFDerivativesType::Pointer GetJointPDFDerivatives () const
190  {
191  if( this->m_ThreaderJointPDFDerivatives.size() == 0 )
192  {
194  }
195  return this->m_ThreaderJointPDFDerivatives[0];
196  }
198 
199 
200 protected:
203 
205  friend class MattesMutualInformationImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedIndexedContainerPartitioner, Superclass, Self >;
206  typedef MattesMutualInformationImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedImageRegionPartitioner< Superclass::VirtualImageDimension >, Superclass, Self >
208  typedef MattesMutualInformationImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedIndexedContainerPartitioner, Superclass, Self >
210 
211  void PrintSelf(std::ostream& os, Indent indent) const;
212 
221 
225 
228  virtual void GetValueCommonAfterThreadedExecution();
229 
230  OffsetValueType ComputeSingleFixedImageParzenWindowIndex( const FixedImagePixelType & value ) const;
231 
233  SizeValueType m_NumberOfHistogramBins;
234  PDFValueType m_MovingImageNormalizedMin;
235  PDFValueType m_FixedImageNormalizedMin;
236  PDFValueType m_FixedImageTrueMin;
237  PDFValueType m_FixedImageTrueMax;
238  PDFValueType m_MovingImageTrueMin;
239  PDFValueType m_MovingImageTrueMax;
240  PDFValueType m_FixedImageBinSize;
241  PDFValueType m_MovingImageBinSize;
242 
244  typename CubicBSplineFunctionType::Pointer m_CubicBSplineKernel;
245  typename CubicBSplineDerivativeFunctionType::Pointer m_CubicBSplineDerivativeKernel;
246 
249  typedef std::vector<PRatioType> PRatioArrayType;
250 
251  mutable PRatioArrayType m_PRatioArray;
252 
255  mutable std::vector<OffsetValueType> m_JointPdfIndex1DArray;
256 
258  mutable std::vector<PDFValueType> m_MovingImageMarginalPDF;
259  mutable std::vector<std::vector<PDFValueType> > m_ThreaderFixedImageMarginalPDF;
260 
262  typename std::vector<JointPDFType::Pointer> m_ThreaderJointPDF;
263  typename std::vector<JointPDFDerivativesType::Pointer> m_ThreaderJointPDFDerivatives;
264 
265  std::vector<int> m_ThreaderJointPDFStartBin;
266  std::vector<int> m_ThreaderJointPDFEndBin;
267 
268  mutable std::vector<PDFValueType> m_ThreaderJointPDFSum;
269 
272  mutable std::vector<DerivativeType> m_LocalDerivativeByParzenBin;
273 
274 private:
275  MattesMutualInformationImageToImageMetricv4(const Self &); //purposely not implemented
276  void operator = (const Self &); //purposely not implemented
277 
279  virtual void ComputeResults( void ) const;
280 
282  mutable bool m_ComputeDerivative;
283 
284 };
285 
286 } // end namespace itk
287 
288 #ifndef ITK_MANUAL_INSTANTIATION
289 #include "itkMattesMutualInformationImageToImageMetricv4.hxx"
290 #endif
291 
292 #endif
293