ITK  4.4.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 
185  itkSetClampMacro( NumberOfHistogramBins, SizeValueType,
186  5, NumericTraits<SizeValueType>::max() );
187  itkGetConstReferenceMacro(NumberOfHistogramBins, SizeValueType);
189 
214  itkSetMacro(UseExplicitPDFDerivatives, bool);
215  itkGetConstReferenceMacro(UseExplicitPDFDerivatives, bool);
216  itkBooleanMacro(UseExplicitPDFDerivatives);
218 
220  typedef double PDFValueType; //NOTE: floating point precision is not as stable. Double precision proves faster and more robust in real-world testing.
221 
223  typedef Image<PDFValueType, 2> JointPDFType;
224  typedef Image<PDFValueType, 3> JointPDFDerivativesType;
225 
230  const typename JointPDFType::Pointer GetJointPDF () const
231  {
232  if( this->m_PerThread == NULL )
233  {
234  return JointPDFType::Pointer(NULL);
235  }
236  return this->m_PerThread[0].JointPDF;
237  }
239 
246  const typename JointPDFDerivativesType::Pointer GetJointPDFDerivatives () const
247  {
248  if( this->m_PerThread == NULL )
249  {
251  }
252  return this->m_PerThread[0].JointPDFDerivatives;
253  }
255 
256 protected:
257 
260  void PrintSelf(std::ostream & os, Indent indent) const;
261 
262 private:
263 
264  // purposely not implemented
266  // purposely not implemented
267  void operator=(const Self &);
268 
277 
281 
283  void ComputeFixedImageParzenWindowIndices( FixedImageSampleContainer & samples);
284 
286  void ComputePDFDerivatives(ThreadIdType threadID, unsigned int sampleNumber, int movingImageParzenWindowIndex,
288  & movingImageGradientValue,
289  PDFValueType cubicBSplineDerivativeValue) const;
290 
291  virtual void GetValueThreadPreProcess(ThreadIdType threadID, bool withinSampleThread) const;
292  virtual void GetValueThreadPostProcess(ThreadIdType threadID, bool withinSampleThread) const;
293  //NOTE: The signature in base class requires that movingImageValue is of type double
294  virtual bool GetValueThreadProcessSample(ThreadIdType threadID, SizeValueType fixedImageSample,
295  const MovingImagePointType & mappedPoint,
296  double movingImageValue) const;
297 
298  virtual void GetValueAndDerivativeThreadPreProcess( ThreadIdType threadID, bool withinSampleThread) const;
299  virtual void GetValueAndDerivativeThreadPostProcess( ThreadIdType threadID, bool withinSampleThread) const;
300  //NOTE: The signature in base class requires that movingImageValue is of type double
301  virtual bool GetValueAndDerivativeThreadProcessSample(ThreadIdType threadID, SizeValueType fixedImageSample,
302  const MovingImagePointType & mappedPoint,
303  double movingImageValue, const ImageDerivativesType &
304  movingImageGradientValue) const;
305 
316 
320 
324 
326 
328  mutable std::vector<PDFValueType> m_MovingImageMarginalPDF;
329 
330  struct PerThreadS
331  {
334 
336 
339 
340  std::vector<PDFValueType> FixedImageMarginalPDF;
341 
345 
347  };
348 
349  itkAlignedTypedef( ITK_CACHE_LINE_ALIGNMENT, PerThreadS, AlignedPerThreadType );
350  AlignedPerThreadType *m_PerThread;
351 
354 };
355 } // end namespace itk
356 
357 #ifndef ITK_MANUAL_INSTANTIATION
358 #include "itkMattesMutualInformationImageToImageMetric.hxx"
359 #endif
360 
361 #endif
362