itkMattesMutualInformationImageToImageMetric.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkMattesMutualInformationImageToImageMetric_h
00018 #define __itkMattesMutualInformationImageToImageMetric_h
00019
00020
00021
00022
00023 #include "itkConfigure.h"
00024
00025 #ifdef ITK_USE_OPTIMIZED_REGISTRATION_METHODS
00026 #include "itkOptMattesMutualInformationImageToImageMetric.h"
00027 #else
00028
00029 #include "itkImageToImageMetric.h"
00030 #include "itkCovariantVector.h"
00031 #include "itkPoint.h"
00032 #include "itkIndex.h"
00033 #include "itkBSplineKernelFunction.h"
00034 #include "itkBSplineDerivativeKernelFunction.h"
00035 #include "itkCentralDifferenceImageFunction.h"
00036 #include "itkBSplineInterpolateImageFunction.h"
00037 #include "itkBSplineDeformableTransform.h"
00038 #include "itkArray2D.h"
00039
00040 namespace itk
00041 {
00042
00124 template <class TFixedImage,class TMovingImage >
00125 class ITK_EXPORT MattesMutualInformationImageToImageMetric :
00126 public ImageToImageMetric< TFixedImage, TMovingImage >
00127 {
00128 public:
00129
00131 typedef MattesMutualInformationImageToImageMetric Self;
00132 typedef ImageToImageMetric< TFixedImage, TMovingImage > Superclass;
00133 typedef SmartPointer<Self> Pointer;
00134 typedef SmartPointer<const Self> ConstPointer;
00135
00137 itkNewMacro(Self);
00138
00140 itkTypeMacro(MattesMutualInformationImageToImageMetric, ImageToImageMetric);
00141
00143 typedef typename Superclass::TransformType TransformType;
00144 typedef typename Superclass::TransformPointer TransformPointer;
00145 typedef typename Superclass::TransformJacobianType TransformJacobianType;
00146 typedef typename Superclass::InterpolatorType InterpolatorType;
00147 typedef typename Superclass::MeasureType MeasureType;
00148 typedef typename Superclass::DerivativeType DerivativeType;
00149 typedef typename Superclass::ParametersType ParametersType;
00150 typedef typename Superclass::FixedImageType FixedImageType;
00151 typedef typename Superclass::MovingImageType MovingImageType;
00152 typedef typename Superclass::FixedImageConstPointer FixedImageConstPointer;
00153 typedef typename Superclass::MovingImageConstPointer MovingImageCosntPointer;
00154 typedef typename Superclass::InputPointType InputPointType;
00155 typedef typename Superclass::OutputPointType OutputPointType;
00156
00157 typedef typename Superclass::CoordinateRepresentationType
00158 CoordinateRepresentationType;
00159
00161 typedef typename FixedImageType::IndexType FixedImageIndexType;
00162 typedef typename FixedImageIndexType::IndexValueType FixedImageIndexValueType;
00163 typedef typename MovingImageType::IndexType MovingImageIndexType;
00164 typedef typename TransformType::InputPointType FixedImagePointType;
00165 typedef typename TransformType::OutputPointType MovingImagePointType;
00166
00168 itkStaticConstMacro( MovingImageDimension, unsigned int,
00169 MovingImageType::ImageDimension );
00170
00178 virtual void Initialize(void) throw ( ExceptionObject );
00179
00181 void GetDerivative( const ParametersType& parameters,
00182 DerivativeType & Derivative ) const;
00183
00185 MeasureType GetValue( const ParametersType& parameters ) const;
00186
00188 void GetValueAndDerivative( const ParametersType& parameters,
00189 MeasureType& Value,
00190 DerivativeType& Derivative ) const;
00191
00193 itkSetClampMacro( NumberOfSpatialSamples, unsigned long,
00194 1, NumericTraits<unsigned long>::max() );
00195 itkGetConstReferenceMacro( NumberOfSpatialSamples, unsigned long);
00197
00199 itkSetClampMacro( NumberOfHistogramBins, unsigned long,
00200 1, NumericTraits<unsigned long>::max() );
00201 itkGetConstReferenceMacro( NumberOfHistogramBins, unsigned long);
00203
00213 void ReinitializeSeed();
00214 void ReinitializeSeed(int);
00216
00219 itkSetMacro(UseAllPixels,bool);
00220 itkGetConstReferenceMacro(UseAllPixels,bool);
00221 itkBooleanMacro(UseAllPixels);
00223
00248 itkSetMacro(UseExplicitPDFDerivatives,bool);
00249 itkGetConstReferenceMacro(UseExplicitPDFDerivatives,bool);
00250 itkBooleanMacro(UseExplicitPDFDerivatives);
00252
00269 itkSetMacro(UseCachingOfBSplineWeights,bool);
00270 itkGetConstReferenceMacro(UseCachingOfBSplineWeights,bool);
00271 itkBooleanMacro(UseCachingOfBSplineWeights);
00273
00274 protected:
00275
00276 MattesMutualInformationImageToImageMetric();
00277 virtual ~MattesMutualInformationImageToImageMetric() {};
00278 void PrintSelf(std::ostream& os, Indent indent) const;
00279
00283
00284 class FixedImageSpatialSample
00285 {
00286 public:
00287 FixedImageSpatialSample():FixedImageValue(0.0)
00288 { FixedImagePointValue.Fill(0.0); }
00289 ~FixedImageSpatialSample() {};
00290
00291 FixedImagePointType FixedImagePointValue;
00292 double FixedImageValue;
00293 unsigned int FixedImageParzenWindowIndex;
00294 };
00296
00298 typedef std::vector<FixedImageSpatialSample>
00299 FixedImageSpatialSampleContainer;
00300
00302 FixedImageSpatialSampleContainer m_FixedImageSamples;
00303
00305 virtual void SampleFixedImageDomain(
00306 FixedImageSpatialSampleContainer& samples);
00307
00309 virtual void SampleFullFixedImageDomain(
00310 FixedImageSpatialSampleContainer& samples);
00311
00314 virtual void TransformPoint( unsigned int sampleNumber,
00315 const ParametersType& parameters,
00316 MovingImagePointType& mappedPoint,
00317 bool& sampleWithinSupportRegion,
00318 double& movingImageValue ) const;
00319
00320 private:
00321
00322
00323 MattesMutualInformationImageToImageMetric(const Self&);
00324
00325 void operator=(const Self&);
00326
00327
00329 typedef float PDFValueType;
00330 typedef std::vector<PDFValueType> MarginalPDFType;
00331
00333 mutable MarginalPDFType m_FixedImageMarginalPDF;
00334
00336 mutable MarginalPDFType m_MovingImageMarginalPDF;
00337
00339 typedef double PRatioType;
00340 typedef Array2D< PRatioType > PRatioArrayType;
00341 mutable PRatioArrayType m_PRatioArray;
00342
00344 mutable DerivativeType m_MetricDerivative;
00345
00347 typedef Image<PDFValueType,2> JointPDFType;
00348 typedef JointPDFType::IndexType JointPDFIndexType;
00349 typedef JointPDFType::PixelType JointPDFValueType;
00350 typedef JointPDFType::RegionType JointPDFRegionType;
00351 typedef JointPDFType::SizeType JointPDFSizeType;
00352 typedef Image<PDFValueType,3> JointPDFDerivativesType;
00353 typedef JointPDFDerivativesType::IndexType JointPDFDerivativesIndexType;
00354 typedef JointPDFDerivativesType::PixelType JointPDFDerivativesValueType;
00355 typedef JointPDFDerivativesType::RegionType JointPDFDerivativesRegionType;
00356 typedef JointPDFDerivativesType::SizeType JointPDFDerivativesSizeType;
00357
00359 typename JointPDFType::Pointer m_JointPDF;
00360 typename JointPDFDerivativesType::Pointer m_JointPDFDerivatives;
00361
00362 unsigned long m_NumberOfSpatialSamples;
00363 unsigned long m_NumberOfParameters;
00364
00366 unsigned long m_NumberOfHistogramBins;
00367 double m_MovingImageNormalizedMin;
00368 double m_FixedImageNormalizedMin;
00369 double m_MovingImageTrueMin;
00370 double m_MovingImageTrueMax;
00371 double m_FixedImageBinSize;
00372 double m_MovingImageBinSize;
00373
00375 typedef BSplineKernelFunction<3> CubicBSplineFunctionType;
00376 typedef BSplineDerivativeKernelFunction<3> CubicBSplineDerivativeFunctionType;
00377
00379 typename CubicBSplineFunctionType::Pointer m_CubicBSplineKernel;
00380 typename CubicBSplineDerivativeFunctionType::Pointer
00381 m_CubicBSplineDerivativeKernel;
00382
00384 virtual void ComputeFixedImageParzenWindowIndices(
00385 FixedImageSpatialSampleContainer& samples );
00386
00393 typedef CovariantVector< double,
00394 itkGetStaticConstMacro(MovingImageDimension) >
00395 ImageDerivativesType;
00396
00398 virtual void ComputeImageDerivatives( const MovingImagePointType& mappedPoint,
00399 ImageDerivativesType& gradient ) const;
00400
00402 bool m_InterpolatorIsBSpline;
00403
00405 typedef
00406 BSplineInterpolateImageFunction<MovingImageType,
00407 CoordinateRepresentationType>
00408 BSplineInterpolatorType;
00409
00411 typename BSplineInterpolatorType::Pointer m_BSplineInterpolator;
00412
00414 typedef CentralDifferenceImageFunction<MovingImageType,
00415 CoordinateRepresentationType>
00416 DerivativeFunctionType;
00417
00419 typename DerivativeFunctionType::Pointer m_DerivativeCalculator;
00420
00421
00423 virtual void ComputePDFDerivatives( unsigned int sampleNumber,
00424 int movingImageParzenWindowIndex,
00425 const ImageDerivativesType&
00426 movingImageGradientValue,
00427 double cubicBSplineDerivativeValue
00428 ) const;
00429
00439 bool m_TransformIsBSpline;
00440
00442 long m_NumParametersPerDim;
00443
00447 unsigned long m_NumBSplineWeights;
00448
00450 itkStaticConstMacro( FixedImageDimension, unsigned int,
00451 FixedImageType::ImageDimension );
00452
00456 enum { DeformationSplineOrder = 3 };
00457
00461 typedef BSplineDeformableTransform<
00462 CoordinateRepresentationType,
00463 ::itk::GetImageDimension<FixedImageType>::ImageDimension,
00464 DeformationSplineOrder> BSplineTransformType;
00465 typedef typename BSplineTransformType::WeightsType
00466 BSplineTransformWeightsType;
00467 typedef typename BSplineTransformType::ParameterIndexArrayType
00468 BSplineTransformIndexArrayType;
00469
00473 typename BSplineTransformType::Pointer m_BSplineTransform;
00474
00479 typedef typename BSplineTransformWeightsType::ValueType WeightsValueType;
00480 typedef Array2D<WeightsValueType> BSplineTransformWeightsArrayType;
00481 typedef typename BSplineTransformIndexArrayType::ValueType IndexValueType;
00482 typedef Array2D<IndexValueType> BSplineTransformIndicesArrayType;
00483 typedef std::vector<MovingImagePointType> MovingImagePointArrayType;
00484 typedef std::vector<bool> BooleanArrayType;
00485
00486 BSplineTransformWeightsArrayType m_BSplineTransformWeightsArray;
00487 BSplineTransformIndicesArrayType m_BSplineTransformIndicesArray;
00488 MovingImagePointArrayType m_PreTransformPointsArray;
00489 BooleanArrayType m_WithinSupportRegionArray;
00490
00491 typedef FixedArray<unsigned long,
00492 ::itk::GetImageDimension<FixedImageType>::ImageDimension>
00493 ParametersOffsetType;
00494 ParametersOffsetType m_ParametersOffset;
00495
00496 bool m_UseAllPixels;
00497
00498 virtual void PreComputeTransformValues();
00499
00500 bool m_ReseedIterator;
00501 int m_RandomSeed;
00502
00503
00504
00505 bool m_UseExplicitPDFDerivatives;
00506
00507
00508 bool m_UseCachingOfBSplineWeights;
00509 mutable BSplineTransformWeightsType m_Weights;
00510 mutable BSplineTransformIndexArrayType m_Indices;
00511
00512 };
00513
00514 }
00515
00516 #ifndef ITK_MANUAL_INSTANTIATION
00517 #include "itkMattesMutualInformationImageToImageMetric.txx"
00518 #endif
00519
00520 #endif
00521
00522 #endif
00523