ITK  5.2.0
Insight Toolkit
itkMattesMutualInformationImageToImageMetric.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 <mutex>
28 
29 
30 namespace itk
31 {
115 template <typename TFixedImage, typename TMovingImage>
117  : public ImageToImageMetric<TFixedImage, TMovingImage>
118 {
119 public:
120  ITK_DISALLOW_COPY_AND_MOVE(MattesMutualInformationImageToImageMetric);
121 
127 
129  itkNewMacro(Self);
130 
133 
135  using TransformType = typename Superclass::TransformType;
136  using TransformPointer = typename Superclass::TransformPointer;
137  using TransformJacobianType = typename Superclass::TransformJacobianType;
138  using InterpolatorType = typename Superclass::InterpolatorType;
139  using MeasureType = typename Superclass::MeasureType;
140  using DerivativeType = typename Superclass::DerivativeType;
141  using ParametersType = typename Superclass::ParametersType;
142  using FixedImageType = typename Superclass::FixedImageType;
143  using MovingImageType = typename Superclass::MovingImageType;
144  using MovingImagePointType = typename Superclass::MovingImagePointType;
145  using FixedImageConstPointer = typename Superclass::FixedImageConstPointer;
146  using MovingImageConstPointer = typename Superclass::MovingImageConstPointer;
147  using BSplineTransformWeightsType = typename Superclass::BSplineTransformWeightsType;
148  using BSplineTransformIndexArrayType = typename Superclass::BSplineTransformIndexArrayType;
149 
150  using CoordinateRepresentationType = typename Superclass::CoordinateRepresentationType;
151  using FixedImageSampleContainer = typename Superclass::FixedImageSampleContainer;
152  using ImageDerivativesType = typename Superclass::ImageDerivativesType;
153  using WeightsValueType = typename Superclass::WeightsValueType;
155 
157 
159  static constexpr unsigned int MovingImageDimension = MovingImageType::ImageDimension;
160 
168  void
169  Initialize() override;
170 
173  GetValue(const ParametersType & parameters) const override;
174 
176  void
177  GetDerivative(const ParametersType & parameters, DerivativeType & derivative) const override;
178 
180  void
181  GetValueAndDerivative(const ParametersType & parameters,
182  MeasureType & value,
183  DerivativeType & derivative) const override;
184 
191  itkSetClampMacro(NumberOfHistogramBins, SizeValueType, 5, NumericTraits<SizeValueType>::max());
192  itkGetConstReferenceMacro(NumberOfHistogramBins, SizeValueType);
194 
219  itkSetMacro(UseExplicitPDFDerivatives, bool);
220  itkGetConstReferenceMacro(UseExplicitPDFDerivatives, bool);
221  itkBooleanMacro(UseExplicitPDFDerivatives);
223 
225  using PDFValueType = double; // NOTE: floating point precision is not as stable. Double precision proves faster and
226  // more robust in real-world testing.
227 
231 
236  const typename JointPDFType::Pointer
237  GetJointPDF() const
238  {
239  if (this->m_MMIMetricPerThreadVariables == nullptr)
240  {
241  return JointPDFType::Pointer(nullptr);
242  }
243  return this->m_MMIMetricPerThreadVariables[0].JointPDF;
244  }
246 
253  const typename JointPDFDerivativesType::Pointer
255  {
256  if (this->m_MMIMetricPerThreadVariables == nullptr)
257  {
258  return JointPDFDerivativesType::Pointer(nullptr);
259  }
260  return this->m_MMIMetricPerThreadVariables[0].JointPDFDerivatives;
261  }
263 
264 protected:
267  void
268  PrintSelf(std::ostream & os, Indent indent) const override;
269 
270 private:
279 
283 
285  void
286  ComputeFixedImageParzenWindowIndices(FixedImageSampleContainer & samples);
287 
289  void
290  ComputePDFDerivatives(ThreadIdType threadId,
291  unsigned int sampleNumber,
292  int pdfMovingIndex,
293  const ImageDerivativesType & movingImageGradientValue,
294  PDFValueType cubicBSplineDerivativeValue) const;
295 
296  void
297  GetValueThreadPreProcess(ThreadIdType threadId, bool withinSampleThread) const override;
298  void
299  GetValueThreadPostProcess(ThreadIdType threadId, bool withinSampleThread) const override;
300  // NOTE: The signature in base class requires that movingImageValue is of type double
301  bool
302  GetValueThreadProcessSample(ThreadIdType threadId,
303  SizeValueType fixedImageSample,
304  const MovingImagePointType & mappedPoint,
305  double movingImageValue) const override;
306 
307  void
308  GetValueAndDerivativeThreadPreProcess(ThreadIdType threadId, bool withinSampleThread) const override;
309  void
310  GetValueAndDerivativeThreadPostProcess(ThreadIdType threadId, bool withinSampleThread) const override;
311  // NOTE: The signature in base class requires that movingImageValue is of type double
312  bool
313  GetValueAndDerivativeThreadProcessSample(ThreadIdType threadId,
314  SizeValueType fixedImageSample,
315  const MovingImagePointType & mappedPoint,
316  double movingImageValue,
317  const ImageDerivativesType & movingImageGradientValue) const override;
318 
320  SizeValueType m_NumberOfHistogramBins{ 50 };
321  PDFValueType m_MovingImageNormalizedMin{ 0.0 };
322  PDFValueType m_FixedImageNormalizedMin{ 0.0 };
323  PDFValueType m_FixedImageTrueMin{ 0.0 };
324  PDFValueType m_FixedImageTrueMax{ 0.0 };
325  PDFValueType m_MovingImageTrueMin{ 0.0 };
326  PDFValueType m_MovingImageTrueMax{ 0.0 };
327  PDFValueType m_FixedImageBinSize{ 0.0 };
328  PDFValueType m_MovingImageBinSize{ 0.0 };
329 
333 
337 
339 
341  using MarginalPDFType = std::vector<PDFValueType>;
343 
345  {
348 
350 
353 
357 
359 
361  };
362 
363 #if !defined(ITK_WRAPPING_PARSER)
364  itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, MMIMetricPerThreadStruct, PaddedMMIMetricPerThreadStruct);
365  itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedMMIMetricPerThreadStruct, AlignedMMIMetricPerThreadStruct);
366  // Due to a bug in older version of Visual Studio where std::vector resize
367  // uses a value instead of a const reference, this must be a pointer.
368  // See
369  // http://thetweaker.wordpress.com/2010/05/05/stdvector-of-aligned-elements/
370  // http://connect.microsoft.com/VisualStudio/feedback/details/692988
371  mutable AlignedMMIMetricPerThreadStruct * m_MMIMetricPerThreadVariables;
372 #endif
373 
374  bool m_UseExplicitPDFDerivatives{ true };
375  mutable bool m_ImplicitDerivativesSecondPass{ false };
376 };
377 } // end namespace itk
378 
379 #ifndef ITK_MANUAL_INSTANTIATION
380 # include "itkMattesMutualInformationImageToImageMetric.hxx"
381 #endif
382 
383 #endif
itk::ImageToImageMetric::FixedImageConstPointer
typename FixedImageType::ConstPointer FixedImageConstPointer
Definition: itkImageToImageMetric.h:77
itk::ImageToImageMetric
Computes similarity between regions of two images.
Definition: itkImageToImageMetric.h:52
itk::BSplineKernelFunction
BSpline kernel used for density estimation and nonparametric regression.
Definition: itkBSplineKernelFunction.h:43
itk::SingleValuedCostFunction::MeasureType
double MeasureType
Definition: itkSingleValuedCostFunction.h:50
itk::OptimizerParameters< TInternalComputationValueType >
itk::ImageToImageMetric::WeightsValueType
typename BSplineTransformWeightsType::ValueType WeightsValueType
Definition: itkImageToImageMetric.h:450
itk::MattesMutualInformationImageToImageMetric::m_CubicBSplineKernel
CubicBSplineFunctionType::Pointer m_CubicBSplineKernel
Definition: itkMattesMutualInformationImageToImageMetric.h:331
itk::MattesMutualInformationImageToImageMetric::MMIMetricPerThreadStruct::JointPDF
JointPDFType::Pointer JointPDF
Definition: itkMattesMutualInformationImageToImageMetric.h:355
itk::MattesMutualInformationImageToImageMetric::GetJointPDFDerivatives
const JointPDFDerivativesType::Pointer GetJointPDFDerivatives() const
Definition: itkMattesMutualInformationImageToImageMetric.h:254
itk::MattesMutualInformationImageToImageMetric::MarginalPDFType
std::vector< PDFValueType > MarginalPDFType
Definition: itkMattesMutualInformationImageToImageMetric.h:341
itk::MattesMutualInformationImageToImageMetric::JointPDFValueType
JointPDFType::PixelType JointPDFValueType
Definition: itkMattesMutualInformationImageToImageMetric.h:272
itk::MattesMutualInformationImageToImageMetric::m_PRatioArray
PRatioArrayType m_PRatioArray
Definition: itkMattesMutualInformationImageToImageMetric.h:338
itk::MattesMutualInformationImageToImageMetric::MMIMetricPerThreadStruct::JointPDFStartBin
int JointPDFStartBin
Definition: itkMattesMutualInformationImageToImageMetric.h:346
itk::MattesMutualInformationImageToImageMetric::MMIMetricPerThreadStruct::FixedImageMarginalPDF
MarginalPDFType FixedImageMarginalPDF
Definition: itkMattesMutualInformationImageToImageMetric.h:360
itkPoint.h
itk::ImageToImageMetric::TransformJacobianType
typename TransformType::JacobianType TransformJacobianType
Definition: itkImageToImageMetric.h:91
itk::MattesMutualInformationImageToImageMetric::JointPDFDerivativesRegionType
JointPDFDerivativesType::RegionType JointPDFDerivativesRegionType
Definition: itkMattesMutualInformationImageToImageMetric.h:277
itk::ImageToImageMetric::MovingImagePointType
typename TransformType::OutputPointType MovingImagePointType
Definition: itkImageToImageMetric.h:98
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::MattesMutualInformationImageToImageMetric::OffsetValueType
typename FixedImageType::OffsetValueType OffsetValueType
Definition: itkMattesMutualInformationImageToImageMetric.h:156
itk::ImageToImageMetric::FixedImageType
TFixedImage FixedImageType
Definition: itkImageToImageMetric.h:75
itk::MattesMutualInformationImageToImageMetric::MMIMetricPerThreadStruct::JointPDFDerivatives
JointPDFDerivativesType::Pointer JointPDFDerivatives
Definition: itkMattesMutualInformationImageToImageMetric.h:356
itk::MattesMutualInformationImageToImageMetric::MMIMetricPerThreadStruct::JointPDFSum
PDFValueType JointPDFSum
Definition: itkMattesMutualInformationImageToImageMetric.h:349
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ImageToImageMetric::IndexValueType
typename BSplineTransformIndexArrayType::ValueType IndexValueType
Definition: itkImageToImageMetric.h:454
itk::MattesMutualInformationImageToImageMetric::JointPDFRegionType
JointPDFType::RegionType JointPDFRegionType
Definition: itkMattesMutualInformationImageToImageMetric.h:273
itk::MattesMutualInformationImageToImageMetric::JointPDFSizeType
JointPDFType::SizeType JointPDFSizeType
Definition: itkMattesMutualInformationImageToImageMetric.h:274
itk::MattesMutualInformationImageToImageMetric::JointPDFDerivativesSizeType
JointPDFDerivativesType::SizeType JointPDFDerivativesSizeType
Definition: itkMattesMutualInformationImageToImageMetric.h:278
itk::ThreadIdType
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itkImageToImageMetric.h
itk::ImageToImageMetric::MovingImageConstPointer
typename MovingImageType::ConstPointer MovingImageConstPointer
Definition: itkImageToImageMetric.h:72
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::MattesMutualInformationImageToImageMetric::m_MMIMetricPerThreadVariables
AlignedMMIMetricPerThreadStruct * m_MMIMetricPerThreadVariables
Definition: itkMattesMutualInformationImageToImageMetric.h:371
itk::ImageToImageMetric::FixedImageSampleContainer
std::vector< FixedImageSamplePoint > FixedImageSampleContainer
Definition: itkImageToImageMetric.h:380
itk::MattesMutualInformationImageToImageMetric::JointPDFIndexType
JointPDFType::IndexType JointPDFIndexType
Definition: itkMattesMutualInformationImageToImageMetric.h:271
itkIndex.h
itk::MattesMutualInformationImageToImageMetric::MMIMetricPerThreadStruct::JointPDFEndBin
int JointPDFEndBin
Definition: itkMattesMutualInformationImageToImageMetric.h:347
itk::Image::PixelType
TPixel PixelType
Definition: itkImage.h:106
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::ImageToImageMetric::TransformPointer
typename TransformType::Pointer TransformPointer
Definition: itkImageToImageMetric.h:87
itk::MattesMutualInformationImageToImageMetric::MMIMetricPerThreadStruct::MetricDerivative
DerivativeType MetricDerivative
Definition: itkMattesMutualInformationImageToImageMetric.h:352
itk::MattesMutualInformationImageToImageMetric::JointPDFDerivativesValueType
JointPDFDerivativesType::PixelType JointPDFDerivativesValueType
Definition: itkMattesMutualInformationImageToImageMetric.h:276
itkArray2D.h
itk::MattesMutualInformationImageToImageMetric::MMIMetricPerThreadStruct::Jacobian
TransformType::JacobianType Jacobian
Definition: itkMattesMutualInformationImageToImageMetric.h:358
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ImageToImageMetric::MovingImageType
TMovingImage MovingImageType
Definition: itkImageToImageMetric.h:70
itk::BSplineDerivativeKernelFunction
Derivative of a BSpline kernel used for density estimation and nonparametric regression.
Definition: itkBSplineDerivativeKernelFunction.h:43
itk::MattesMutualInformationImageToImageMetric::m_MovingImageMarginalPDF
MarginalPDFType m_MovingImageMarginalPDF
Definition: itkMattesMutualInformationImageToImageMetric.h:342
itk::OffsetValueType
signed long OffsetValueType
Definition: itkIntTypes.h:94
itk::IndexValueType
signed long IndexValueType
Definition: itkIntTypes.h:90
itk::Array
Array class with size defined at construction time.
Definition: itkArray.h:47
itk::MattesMutualInformationImageToImageMetric::m_CubicBSplineDerivativeKernel
CubicBSplineDerivativeFunctionType::Pointer m_CubicBSplineDerivativeKernel
Definition: itkMattesMutualInformationImageToImageMetric.h:332
itk::MattesMutualInformationImageToImageMetric::MMIMetricPerThreadStruct
Definition: itkMattesMutualInformationImageToImageMetric.h:344
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86
itk::Transform
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:82
itk::MattesMutualInformationImageToImageMetric::PRatioType
PDFValueType PRatioType
Definition: itkMattesMutualInformationImageToImageMetric.h:335
itk::Array2D< PRatioType >
itk::MattesMutualInformationImageToImageMetric::GetJointPDF
const JointPDFType::Pointer GetJointPDF() const
Definition: itkMattesMutualInformationImageToImageMetric.h:237
itk::ImageToImageMetric::CoordinateRepresentationType
typename Superclass::ParametersValueType CoordinateRepresentationType
Definition: itkImageToImageMetric.h:64
itk::MattesMutualInformationImageToImageMetric::PDFValueType
double PDFValueType
Definition: itkMattesMutualInformationImageToImageMetric.h:225
itk::ImageToImageMetric::BSplineTransformWeightsType
typename BSplineTransformType::WeightsType BSplineTransformWeightsType
Definition: itkImageToImageMetric.h:449
itk::ImageToImageMetric::BSplineTransformIndexArrayType
typename BSplineTransformType::ParameterIndexArrayType BSplineTransformIndexArrayType
Definition: itkImageToImageMetric.h:453
itk::InterpolateImageFunction
Base class for all image interpolators.
Definition: itkInterpolateImageFunction.h:45
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itkBSplineDerivativeKernelFunction.h
itk::MattesMutualInformationImageToImageMetric::JointPDFDerivativesIndexType
JointPDFDerivativesType::IndexType JointPDFDerivativesIndexType
Definition: itkMattesMutualInformationImageToImageMetric.h:275
itk::MattesMutualInformationImageToImageMetric
Computes the mutual information between two images to be registered using the method of Mattes et al.
Definition: itkMattesMutualInformationImageToImageMetric.h:116