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 FixedImageType::OffsetValueType OffsetValueType;
00163 typedef typename FixedImageIndexType::IndexValueType FixedImageIndexValueType;
00164 typedef typename MovingImageType::IndexType MovingImageIndexType;
00165 typedef typename TransformType::InputPointType FixedImagePointType;
00166 typedef typename TransformType::OutputPointType MovingImagePointType;
00167
00169 itkStaticConstMacro( MovingImageDimension, unsigned int,
00170 MovingImageType::ImageDimension );
00171
00179 virtual void Initialize(void) throw ( ExceptionObject );
00180
00182 void GetDerivative( const ParametersType& parameters,
00183 DerivativeType & Derivative ) const;
00184
00186 MeasureType GetValue( const ParametersType& parameters ) const;
00187
00189 void GetValueAndDerivative( const ParametersType& parameters,
00190 MeasureType& Value,
00191 DerivativeType& Derivative ) const;
00192
00194 itkSetClampMacro( NumberOfSpatialSamples, unsigned long,
00195 1, NumericTraits<unsigned long>::max() );
00196 itkGetConstReferenceMacro( NumberOfSpatialSamples, unsigned long);
00198
00203 itkSetClampMacro( NumberOfHistogramBins, unsigned long,
00204 5, NumericTraits<unsigned long>::max() );
00205 itkGetConstReferenceMacro( NumberOfHistogramBins, unsigned long);
00207
00217 void ReinitializeSeed();
00218 void ReinitializeSeed(int);
00220
00223 itkSetMacro(UseAllPixels,bool);
00224 itkGetConstReferenceMacro(UseAllPixels,bool);
00225 itkBooleanMacro(UseAllPixels);
00227
00252 itkSetMacro(UseExplicitPDFDerivatives,bool);
00253 itkGetConstReferenceMacro(UseExplicitPDFDerivatives,bool);
00254 itkBooleanMacro(UseExplicitPDFDerivatives);
00256
00273 itkSetMacro(UseCachingOfBSplineWeights,bool);
00274 itkGetConstReferenceMacro(UseCachingOfBSplineWeights,bool);
00275 itkBooleanMacro(UseCachingOfBSplineWeights);
00277
00278 protected:
00279
00280 MattesMutualInformationImageToImageMetric();
00281 virtual ~MattesMutualInformationImageToImageMetric() {};
00282 void PrintSelf(std::ostream& os, Indent indent) const;
00283
00287
00288 class FixedImageSpatialSample
00289 {
00290 public:
00291 FixedImageSpatialSample():FixedImageValue(0.0)
00292 { FixedImagePointValue.Fill(0.0); }
00293 ~FixedImageSpatialSample() {};
00294
00295 FixedImagePointType FixedImagePointValue;
00296 double FixedImageValue;
00297 unsigned int FixedImageParzenWindowIndex;
00298 };
00300
00302 typedef std::vector<FixedImageSpatialSample>
00303 FixedImageSpatialSampleContainer;
00304
00306 FixedImageSpatialSampleContainer m_FixedImageSamples;
00307
00309 virtual void SampleFixedImageDomain(
00310 FixedImageSpatialSampleContainer& samples);
00311
00313 virtual void SampleFullFixedImageDomain(
00314 FixedImageSpatialSampleContainer& samples);
00315
00318 virtual void TransformPoint( unsigned int sampleNumber,
00319 const ParametersType& parameters,
00320 MovingImagePointType& mappedPoint,
00321 bool& sampleWithinSupportRegion,
00322 double& movingImageValue ) const;
00323
00324 private:
00325
00326
00327 MattesMutualInformationImageToImageMetric(const Self&);
00328
00329 void operator=(const Self&);
00330
00331
00333 typedef float PDFValueType;
00334 typedef std::vector<PDFValueType> MarginalPDFType;
00335
00337 mutable MarginalPDFType m_FixedImageMarginalPDF;
00338
00340 mutable MarginalPDFType m_MovingImageMarginalPDF;
00341
00343 typedef double PRatioType;
00344 typedef Array2D< PRatioType > PRatioArrayType;
00345 mutable PRatioArrayType m_PRatioArray;
00346
00348 mutable DerivativeType m_MetricDerivative;
00349
00351 typedef Image<PDFValueType,2> JointPDFType;
00352 typedef JointPDFType::IndexType JointPDFIndexType;
00353 typedef JointPDFType::PixelType JointPDFValueType;
00354 typedef JointPDFType::RegionType JointPDFRegionType;
00355 typedef JointPDFType::SizeType JointPDFSizeType;
00356 typedef Image<PDFValueType,3> JointPDFDerivativesType;
00357 typedef JointPDFDerivativesType::IndexType JointPDFDerivativesIndexType;
00358 typedef JointPDFDerivativesType::PixelType JointPDFDerivativesValueType;
00359 typedef JointPDFDerivativesType::RegionType JointPDFDerivativesRegionType;
00360 typedef JointPDFDerivativesType::SizeType JointPDFDerivativesSizeType;
00361
00363 typename JointPDFType::Pointer m_JointPDF;
00364 typename JointPDFDerivativesType::Pointer m_JointPDFDerivatives;
00365
00366 unsigned long m_NumberOfSpatialSamples;
00367 unsigned long m_NumberOfParameters;
00368
00370 unsigned long m_NumberOfHistogramBins;
00371 double m_MovingImageNormalizedMin;
00372 double m_FixedImageNormalizedMin;
00373 double m_MovingImageTrueMin;
00374 double m_MovingImageTrueMax;
00375 double m_FixedImageBinSize;
00376 double m_MovingImageBinSize;
00377
00379 typedef BSplineKernelFunction<3> CubicBSplineFunctionType;
00380 typedef BSplineDerivativeKernelFunction<3> CubicBSplineDerivativeFunctionType;
00381
00383 typename CubicBSplineFunctionType::Pointer m_CubicBSplineKernel;
00384 typename CubicBSplineDerivativeFunctionType::Pointer
00385 m_CubicBSplineDerivativeKernel;
00386
00388 virtual void ComputeFixedImageParzenWindowIndices(
00389 FixedImageSpatialSampleContainer& samples );
00390
00397 typedef CovariantVector< double,
00398 itkGetStaticConstMacro(MovingImageDimension) >
00399 ImageDerivativesType;
00400
00402 virtual void ComputeImageDerivatives( const MovingImagePointType& mappedPoint,
00403 ImageDerivativesType& gradient ) const;
00404
00406 bool m_InterpolatorIsBSpline;
00407
00409 typedef
00410 BSplineInterpolateImageFunction<MovingImageType,
00411 CoordinateRepresentationType>
00412 BSplineInterpolatorType;
00413
00415 typename BSplineInterpolatorType::Pointer m_BSplineInterpolator;
00416
00418 typedef CentralDifferenceImageFunction<MovingImageType,
00419 CoordinateRepresentationType>
00420 DerivativeFunctionType;
00421
00423 typename DerivativeFunctionType::Pointer m_DerivativeCalculator;
00424
00425
00427 virtual void ComputePDFDerivatives( unsigned int sampleNumber,
00428 int movingImageParzenWindowIndex,
00429 const ImageDerivativesType&
00430 movingImageGradientValue,
00431 double cubicBSplineDerivativeValue
00432 ) const;
00433
00443 bool m_TransformIsBSpline;
00444
00446 long m_NumParametersPerDim;
00447
00451 unsigned long m_NumBSplineWeights;
00452
00454 itkStaticConstMacro( FixedImageDimension, unsigned int,
00455 FixedImageType::ImageDimension );
00456
00460 enum { DeformationSplineOrder = 3 };
00461
00465 typedef BSplineDeformableTransform<
00466 CoordinateRepresentationType,
00467 ::itk::GetImageDimension<FixedImageType>::ImageDimension,
00468 DeformationSplineOrder> BSplineTransformType;
00469 typedef typename BSplineTransformType::WeightsType
00470 BSplineTransformWeightsType;
00471 typedef typename BSplineTransformType::ParameterIndexArrayType
00472 BSplineTransformIndexArrayType;
00473
00477 typename BSplineTransformType::Pointer m_BSplineTransform;
00478
00483 typedef typename BSplineTransformWeightsType::ValueType WeightsValueType;
00484 typedef Array2D<WeightsValueType> BSplineTransformWeightsArrayType;
00485 typedef typename BSplineTransformIndexArrayType::ValueType IndexValueType;
00486 typedef Array2D<IndexValueType> BSplineTransformIndicesArrayType;
00487 typedef std::vector<MovingImagePointType> MovingImagePointArrayType;
00488 typedef std::vector<bool> BooleanArrayType;
00489
00490 BSplineTransformWeightsArrayType m_BSplineTransformWeightsArray;
00491 BSplineTransformIndicesArrayType m_BSplineTransformIndicesArray;
00492 MovingImagePointArrayType m_PreTransformPointsArray;
00493 BooleanArrayType m_WithinSupportRegionArray;
00494
00495 typedef FixedArray<unsigned long,
00496 ::itk::GetImageDimension<FixedImageType>::ImageDimension>
00497 ParametersOffsetType;
00498 ParametersOffsetType m_ParametersOffset;
00499
00500 bool m_UseAllPixels;
00501
00502 virtual void PreComputeTransformValues();
00503
00504 bool m_ReseedIterator;
00505 int m_RandomSeed;
00506
00507
00508
00509 bool m_UseExplicitPDFDerivatives;
00510
00511
00512 bool m_UseCachingOfBSplineWeights;
00513 mutable BSplineTransformWeightsType m_Weights;
00514 mutable BSplineTransformIndexArrayType m_Indices;
00515
00516 };
00517
00518 }
00519
00520 #ifndef ITK_MANUAL_INSTANTIATION
00521 #include "itkMattesMutualInformationImageToImageMetric.txx"
00522 #endif
00523
00524 #endif
00525
00526 #endif
00527