ITK  4.5.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 <typename TFixedImage, typename TMovingImage>
115  public ImageToImageMetric<TFixedImage, TMovingImage>
116 {
117 public:
118 
124 
126  itkNewMacro(Self);
127 
131 
133  typedef typename Superclass::TransformType TransformType;
147 
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_MMIMetricPerThreadVariables == NULL )
233  {
234  return JointPDFType::Pointer(NULL);
235  }
236  return this->m_MMIMetricPerThreadVariables[0].JointPDF;
237  }
239 
247  {
248  if( this->m_MMIMetricPerThreadVariables == NULL )
249  {
251  }
252  return this->m_MMIMetricPerThreadVariables[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 
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  typedef std::vector< PDFValueType > MarginalPDFType;
330 
332  {
335 
337 
340 
344 
346 
348  };
349 
350 #if !defined(__GCCXML__)
351  itkPadStruct( ITK_CACHE_LINE_ALIGNMENT, MMIMetricPerThreadStruct,
352  PaddedMMIMetricPerThreadStruct);
353  itkAlignedTypedef( ITK_CACHE_LINE_ALIGNMENT, PaddedMMIMetricPerThreadStruct,
354  AlignedMMIMetricPerThreadStruct );
355  // Due to a bug in older version of Visual Studio where std::vector resize
356  // uses a value instead of a const reference, this must be a pointer.
357  // See
358  // http://thetweaker.wordpress.com/2010/05/05/stdvector-of-aligned-elements/
359  // http://connect.microsoft.com/VisualStudio/feedback/details/692988
360  mutable AlignedMMIMetricPerThreadStruct * m_MMIMetricPerThreadVariables;
361 #endif
362 
365 };
366 } // end namespace itk
367 
368 #ifndef ITK_MANUAL_INSTANTIATION
369 #include "itkMattesMutualInformationImageToImageMetric.hxx"
370 #endif
371 
372 #endif
Array class with size defined at construction time.
Definition: itkArray.h:50
Superclass::RegionType RegionType
Definition: itkImage.h:140
itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedMMIMetricPerThreadStruct, AlignedMMIMetricPerThreadStruct)
Light weight base class for most itk classes.
const JointPDFDerivativesType::Pointer GetJointPDFDerivatives() const
BSplineTransformType::WeightsType BSplineTransformWeightsType
SmartPointer< Self > Pointer
Definition: itkImage.h:81
Superclass::ParametersValueType CoordinateRepresentationType
Represent the size (bounds) of a n-dimensional image.
Definition: itkSize.h:52
signed long OffsetValueType
Definition: itkIntTypes.h:154
MeasureType GetValue(const ParametersType &parameters) const
TransformType::Pointer TransformPointer
CovariantVector< double, itkGetStaticConstMacro(MovingImageDimension) > ImageDerivativesType
Superclass::DerivativeType DerivativeType
MovingImageType::ConstPointer MovingImageConstPointer
void ComputePDFDerivatives(ThreadIdType threadID, unsigned int sampleNumber, int movingImageParzenWindowIndex, const ImageDerivativesType &movingImageGradientValue, PDFValueType cubicBSplineDerivativeValue) const
TransformType::OutputPointType MovingImagePointType
CubicBSplineDerivativeFunctionType::Pointer m_CubicBSplineDerivativeKernel
unsigned long SizeValueType
Definition: itkIntTypes.h:143
virtual void GetValueAndDerivativeThreadPostProcess(ThreadIdType threadID, bool withinSampleThread) const
TPixel PixelType
Definition: itkImage.h:89
Derivative of a BSpline kernel used for density estimation and nonparameteric regression.
virtual void GetValueThreadPreProcess(ThreadIdType threadID, bool withinSampleThread) const
BSpline kernel used for density estimation and nonparameteric regression.
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:82
Superclass::ParametersType ParametersType
Superclass::IndexType IndexType
Definition: itkImage.h:122
Standard exception handling object.
void GetDerivative(const ParametersType &parameters, DerivativeType &Derivative) const
BSplineTransformIndexArrayType::ValueType IndexValueType
void ComputeFixedImageParzenWindowIndices(FixedImageSampleContainer &samples)
std::vector< FixedImageSamplePoint > FixedImageSampleContainer
Superclass::ParametersType ParametersType
TransformType::JacobianType TransformJacobianType
Computes the mutual information between two images to be registered using the method of Mattes et al...
BSplineTransformWeightsType::ValueType WeightsValueType
virtual void GetValueAndDerivativeThreadPreProcess(ThreadIdType threadID, bool withinSampleThread) const
InterpolateImageFunction< MovingImageType, CoordinateRepresentationType > InterpolatorType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
FixedImageType::ConstPointer FixedImageConstPointer
virtual bool GetValueThreadProcessSample(ThreadIdType threadID, SizeValueType fixedImageSample, const MovingImagePointType &mappedPoint, double movingImageValue) const
#define NULL
BSplineDerivativeKernelFunction< 3, PDFValueType > CubicBSplineDerivativeFunctionType
virtual bool GetValueAndDerivativeThreadProcessSample(ThreadIdType threadID, SizeValueType fixedImageSample, const MovingImagePointType &mappedPoint, double movingImageValue, const ImageDerivativesType &movingImageGradientValue) const
virtual void GetValueThreadPostProcess(ThreadIdType threadID, bool withinSampleThread) const
Define additional traits for native types such as int or float.
Superclass::MeasureType MeasureType
Computes similarity between regions of two images.
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:51
A templated class holding a n-Dimensional covariant vector.
Templated n-dimensional image class.
Definition: itkImage.h:75
itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, MMIMetricPerThreadStruct, PaddedMMIMetricPerThreadStruct)
void PrintSelf(std::ostream &os, Indent indent) const
void GetValueAndDerivative(const ParametersType &parameters, MeasureType &Value, DerivativeType &Derivative) const
unsigned int ThreadIdType
Definition: itkIntTypes.h:159
BSplineTransformType::ParameterIndexArrayType BSplineTransformIndexArrayType