ITK  4.3.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_PerThread == NULL )
232  {
233  return JointPDFType::Pointer(NULL);
234  }
235  return this->m_PerThread[0].JointPDF;
236  }
238 
245  const typename JointPDFDerivativesType::Pointer GetJointPDFDerivatives () const
246  {
247  if( this->m_PerThread == NULL )
248  {
250  }
251  return this->m_PerThread[0].JointPDFDerivatives;
252  }
254 
255 protected:
256 
259  void PrintSelf(std::ostream & os, Indent indent) const;
260 
261 private:
262 
263  // purposely not implemented
265  // purposely not implemented
266  void operator=(const Self &);
267 
276 
280 
282  void ComputeFixedImageParzenWindowIndices( FixedImageSampleContainer & samples);
283 
285  void ComputePDFDerivatives(ThreadIdType threadID, unsigned int sampleNumber, int movingImageParzenWindowIndex,
287  & movingImageGradientValue,
288  PDFValueType cubicBSplineDerivativeValue) const;
289 
290  virtual void GetValueThreadPreProcess(ThreadIdType threadID, bool withinSampleThread) const;
291  virtual void GetValueThreadPostProcess(ThreadIdType threadID, bool withinSampleThread) const;
292  //NOTE: The signature in base class requires that movingImageValue is of type double
293  virtual bool GetValueThreadProcessSample(ThreadIdType threadID, SizeValueType fixedImageSample,
294  const MovingImagePointType & mappedPoint,
295  double movingImageValue) const;
296 
297  virtual void GetValueAndDerivativeThreadPreProcess( ThreadIdType threadID, bool withinSampleThread) const;
298  virtual void GetValueAndDerivativeThreadPostProcess( ThreadIdType threadID, bool withinSampleThread) const;
299  //NOTE: The signature in base class requires that movingImageValue is of type double
300  virtual bool GetValueAndDerivativeThreadProcessSample(ThreadIdType threadID, SizeValueType fixedImageSample,
301  const MovingImagePointType & mappedPoint,
302  double movingImageValue, const ImageDerivativesType &
303  movingImageGradientValue) const;
304 
315 
319 
323 
325 
327  mutable std::vector<PDFValueType> m_MovingImageMarginalPDF;
328 
329  struct PerThreadS
330  {
333 
335 
338 
339  std::vector<PDFValueType> FixedImageMarginalPDF;
340 
344 
346  };
347 
348  itkAlignedTypedef( ITK_CACHE_LINE_ALIGNMENT, PerThreadS, AlignedPerThreadType );
349  AlignedPerThreadType *m_PerThread;
350 
353 };
354 } // end namespace itk
355 
356 #ifndef ITK_MANUAL_INSTANTIATION
357 #include "itkMattesMutualInformationImageToImageMetric.hxx"
358 #endif
359 
360 #endif
361