ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkMattesMutualInformationImageToImageMetric.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 __itkMattesMutualInformationImageToImageMetric_h
19 #define __itkMattesMutualInformationImageToImageMetric_h
20 
21 #include "itkImageToImageMetric.h"
22 #include "itkPoint.h"
23 #include "itkIndex.h"
25 #include "itkArray2D.h"
26 
27 #include "itkSimpleFastMutexLock.h"
28 
29 
30 namespace itk
31 {
113 template <class TFixedImage, class TMovingImage>
115  public ImageToImageMetric<TFixedImage, TMovingImage>
116 {
117 public:
118 
124 
126  itkNewMacro(Self);
127 
131 
133  typedef typename Superclass::TransformType TransformType;
134  typedef typename Superclass::TransformPointer TransformPointer;
135  typedef typename Superclass::TransformJacobianType TransformJacobianType;
136  typedef typename Superclass::InterpolatorType InterpolatorType;
137  typedef typename Superclass::MeasureType MeasureType;
138  typedef typename Superclass::DerivativeType DerivativeType;
139  typedef typename Superclass::ParametersType ParametersType;
140  typedef typename Superclass::FixedImageType FixedImageType;
141  typedef typename Superclass::MovingImageType MovingImageType;
142  typedef typename Superclass::MovingImagePointType MovingImagePointType;
143  typedef typename Superclass::FixedImageConstPointer FixedImageConstPointer;
144  typedef typename Superclass::MovingImageConstPointer MovingImageConstPointer;
145  typedef typename Superclass::BSplineTransformWeightsType BSplineTransformWeightsType;
146  typedef typename Superclass::BSplineTransformIndexArrayType BSplineTransformIndexArrayType;
147 
148  typedef typename Superclass::CoordinateRepresentationType CoordinateRepresentationType;
149  typedef typename Superclass::FixedImageSampleContainer FixedImageSampleContainer;
150  typedef typename Superclass::ImageDerivativesType ImageDerivativesType;
151  typedef typename Superclass::WeightsValueType WeightsValueType;
153 
155 
157  itkStaticConstMacro(MovingImageDimension, unsigned int,
158  MovingImageType::ImageDimension);
159 
167  virtual void Initialize(void)
168  throw ( ExceptionObject );
169 
171  MeasureType GetValue(const ParametersType & parameters) const;
172 
174  void GetDerivative(const ParametersType & parameters, DerivativeType & Derivative) const;
175 
177  void GetValueAndDerivative(const ParametersType & parameters, MeasureType & Value, DerivativeType & Derivative) const;
178 
184  itkSetClampMacro( NumberOfHistogramBins, SizeValueType,
185  5, NumericTraits<SizeValueType>::max() );
186  itkGetConstReferenceMacro(NumberOfHistogramBins, SizeValueType);
188 
213  itkSetMacro(UseExplicitPDFDerivatives, bool);
214  itkGetConstReferenceMacro(UseExplicitPDFDerivatives, bool);
215  itkBooleanMacro(UseExplicitPDFDerivatives);
217 
219  typedef double PDFValueType; //NOTE: floating point precision is not as stable. Double precision proves faster and more robust in real-world testing.
220 
222  typedef Image<PDFValueType, 2> JointPDFType;
223  typedef Image<PDFValueType, 3> JointPDFDerivativesType;
224 
229  const typename JointPDFType::Pointer GetJointPDF () const
230  {
231  if( this->m_ThreaderJointPDF.size() == 0 )
232  {
233  return JointPDFType::Pointer(NULL);
234  }
235  return this->m_ThreaderJointPDF[0];
236  }
238 
245  const typename JointPDFDerivativesType::Pointer GetJointPDFDerivatives () const
246  {
247  if( this->m_ThreaderJointPDFDerivatives.size() == 0 )
248  {
250  }
251  return this->m_ThreaderJointPDFDerivatives[0];
252  }
253 protected:
255 
258  void PrintSelf(std::ostream & os, Indent indent) const;
259 
260 private:
261 
262  // purposely not implemented
264  // purposely not implemented
265  void operator=(const Self &);
266 
275 
279 
281  void ComputeFixedImageParzenWindowIndices( FixedImageSampleContainer & samples);
282 
284  void ComputePDFDerivatives(ThreadIdType threadID, unsigned int sampleNumber, int movingImageParzenWindowIndex,
286  & movingImageGradientValue,
287  PDFValueType cubicBSplineDerivativeValue) const;
288 
289  virtual void GetValueThreadPreProcess(ThreadIdType threadID, bool withinSampleThread) const;
290  virtual void GetValueThreadPostProcess(ThreadIdType threadID, bool withinSampleThread) const;
291  //NOTE: The signature in base class requires that movingImageValue is of type double
292  virtual bool GetValueThreadProcessSample(ThreadIdType threadID, SizeValueType fixedImageSample,
293  const MovingImagePointType & mappedPoint,
294  double movingImageValue) const;
295 
296  virtual void GetValueAndDerivativeThreadPreProcess( ThreadIdType threadID, bool withinSampleThread) const;
297  virtual void GetValueAndDerivativeThreadPostProcess( ThreadIdType threadID, bool withinSampleThread) const;
298  //NOTE: The signature in base class requires that movingImageValue is of type double
299  virtual bool GetValueAndDerivativeThreadProcessSample(ThreadIdType threadID, SizeValueType fixedImageSample,
300  const MovingImagePointType & mappedPoint,
301  double movingImageValue, const ImageDerivativesType &
302  movingImageGradientValue) const;
303 
314 
318 
322 
324 
326  mutable std::vector<DerivativeType> m_ThreaderMetricDerivative;
327 
329  mutable std::vector<PDFValueType> m_MovingImageMarginalPDF;
330  mutable std::vector<std::vector<PDFValueType> > m_ThreaderFixedImageMarginalPDF;
331 
333  typename std::vector<JointPDFType::Pointer> m_ThreaderJointPDF;
334  typename std::vector<JointPDFDerivativesType::Pointer> m_ThreaderJointPDFDerivatives;
335 
336  std::vector<int> m_ThreaderJointPDFStartBin;
337  std::vector<int> m_ThreaderJointPDFEndBin;
338 
339  mutable std::vector<PDFValueType> m_ThreaderJointPDFSum;
340 
343 };
344 } // end namespace itk
345 
346 #ifndef ITK_MANUAL_INSTANTIATION
347 #include "itkMattesMutualInformationImageToImageMetric.hxx"
348 #endif
349 
350 #endif
351