00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkOptMattesMutualInformationImageToImageMetric_h
00018 #define __itkOptMattesMutualInformationImageToImageMetric_h
00019
00020 #include "itkOptImageToImageMetric.h"
00021 #include "itkCovariantVector.h"
00022 #include "itkPoint.h"
00023 #include "itkIndex.h"
00024 #include "itkBSplineKernelFunction.h"
00025 #include "itkBSplineDerivativeKernelFunction.h"
00026 #include "itkCentralDifferenceImageFunction.h"
00027 #include "itkBSplineInterpolateImageFunction.h"
00028 #include "itkBSplineDeformableTransform.h"
00029 #include "itkArray2D.h"
00030
00031 #include "itkMultiThreader.h"
00032
00033 namespace itk
00034 {
00035
00116 template <class TFixedImage,class TMovingImage >
00117 class ITK_EXPORT MattesMutualInformationImageToImageMetric :
00118 public ImageToImageMetric< TFixedImage, TMovingImage >
00119 {
00120 public:
00121
00123 typedef MattesMutualInformationImageToImageMetric Self;
00124 typedef ImageToImageMetric< TFixedImage, TMovingImage > Superclass;
00125 typedef SmartPointer<Self> Pointer;
00126 typedef SmartPointer<const Self> ConstPointer;
00127
00129 itkNewMacro(Self);
00130
00132 itkTypeMacro(MattesMutualInformationImageToImageMetric,
00133 ImageToImageMetric);
00134
00136 typedef typename Superclass::TransformType TransformType;
00137 typedef typename Superclass::TransformPointer TransformPointer;
00138 typedef typename Superclass::TransformJacobianType TransformJacobianType;
00139 typedef typename Superclass::InterpolatorType InterpolatorType;
00140 typedef typename Superclass::MeasureType MeasureType;
00141 typedef typename Superclass::DerivativeType DerivativeType;
00142 typedef typename Superclass::ParametersType ParametersType;
00143 typedef typename Superclass::FixedImageType FixedImageType;
00144 typedef typename Superclass::MovingImageType MovingImageType;
00145 typedef typename Superclass::MovingImagePointType MovingImagePointType;
00146 typedef typename Superclass::FixedImageConstPointer FixedImageConstPointer;
00147 typedef typename Superclass::MovingImageConstPointer MovingImageConstPointer;
00148 typedef typename Superclass::BSplineTransformWeightsType
00149 BSplineTransformWeightsType;
00150 typedef typename Superclass::BSplineTransformIndexArrayType
00151 BSplineTransformIndexArrayType;
00152
00153 typedef typename Superclass::CoordinateRepresentationType
00154 CoordinateRepresentationType;
00155 typedef typename Superclass::FixedImageSampleContainer
00156 FixedImageSampleContainer;
00157 typedef typename Superclass::ImageDerivativesType ImageDerivativesType;
00158 typedef typename Superclass::WeightsValueType WeightsValueType;
00159 typedef typename Superclass::IndexValueType IndexValueType;
00160
00162 itkStaticConstMacro( MovingImageDimension, unsigned int,
00163 MovingImageType::ImageDimension );
00164
00172 virtual void Initialize(void) throw ( ExceptionObject );
00173
00175 MeasureType GetValue( const ParametersType & parameters ) const;
00176
00178 void GetDerivative( const ParametersType & parameters,
00179 DerivativeType & Derivative ) const;
00180
00182 void GetValueAndDerivative( const ParametersType & parameters,
00183 MeasureType & Value,
00184 DerivativeType & Derivative ) const;
00185
00187 itkSetClampMacro( NumberOfHistogramBins, unsigned long,
00188 1, NumericTraits<unsigned long>::max() );
00189 itkGetConstReferenceMacro( NumberOfHistogramBins, unsigned long);
00191
00216 itkSetMacro(UseExplicitPDFDerivatives,bool);
00217 itkGetConstReferenceMacro(UseExplicitPDFDerivatives,bool);
00218 itkBooleanMacro(UseExplicitPDFDerivatives);
00220
00221 protected:
00222
00223 MattesMutualInformationImageToImageMetric();
00224 virtual ~MattesMutualInformationImageToImageMetric();
00225 void PrintSelf(std::ostream& os, Indent indent) const;
00226
00227 private:
00228
00229
00230 MattesMutualInformationImageToImageMetric(const Self &);
00231
00232 void operator=(const Self &);
00233
00234
00236 typedef float PDFValueType;
00237 typedef float * MarginalPDFType;
00238
00239 mutable MarginalPDFType m_FixedImageMarginalPDF;
00240
00242 mutable MarginalPDFType m_MovingImageMarginalPDF;
00243
00245 typedef double PRatioType;
00246 typedef Array2D< PRatioType > PRatioArrayType;
00247 mutable PRatioArrayType m_PRatioArray;
00248
00250 mutable DerivativeType m_MetricDerivative;
00251 mutable DerivativeType * m_ThreaderMetricDerivative;
00252
00254 typedef Image<PDFValueType,2> JointPDFType;
00255 typedef Image<PDFValueType,3> JointPDFDerivativesType;
00256 typedef JointPDFType::IndexType JointPDFIndexType;
00257 typedef JointPDFType::PixelType JointPDFValueType;
00258 typedef JointPDFType::RegionType JointPDFRegionType;
00259 typedef JointPDFType::SizeType JointPDFSizeType;
00260 typedef JointPDFDerivativesType::IndexType JointPDFDerivativesIndexType;
00261 typedef JointPDFDerivativesType::PixelType JointPDFDerivativesValueType;
00262 typedef JointPDFDerivativesType::RegionType JointPDFDerivativesRegionType;
00263 typedef JointPDFDerivativesType::SizeType JointPDFDerivativesSizeType;
00264
00266 typename JointPDFType::Pointer m_JointPDF;
00267 unsigned long m_JointPDFBufferSize;
00268 typename JointPDFDerivativesType::Pointer m_JointPDFDerivatives;
00269 unsigned long m_JointPDFDerivativesBufferSize;
00270
00272 unsigned long m_NumberOfHistogramBins;
00273 double m_MovingImageNormalizedMin;
00274 double m_FixedImageNormalizedMin;
00275 double m_FixedImageTrueMin;
00276 double m_FixedImageTrueMax;
00277 double m_MovingImageTrueMin;
00278 double m_MovingImageTrueMax;
00279 double m_FixedImageBinSize;
00280 double m_MovingImageBinSize;
00281
00283 typedef BSplineKernelFunction<3> CubicBSplineFunctionType;
00284 typedef BSplineDerivativeKernelFunction<3> CubicBSplineDerivativeFunctionType;
00285
00287 typename CubicBSplineFunctionType::Pointer m_CubicBSplineKernel;
00288 typename CubicBSplineDerivativeFunctionType::Pointer
00289 m_CubicBSplineDerivativeKernel;
00290
00292 virtual void ComputeFixedImageParzenWindowIndices(
00293 FixedImageSampleContainer & samples );
00294
00296 virtual void ComputePDFDerivatives( unsigned int threadID,
00297 unsigned int sampleNumber,
00298 int movingImageParzenWindowIndex,
00299 const ImageDerivativesType
00300 & movingImageGradientValue,
00301 double cubicBSplineDerivativeValue
00302 ) const;
00303
00304 PDFValueType * m_ThreaderFixedImageMarginalPDF;
00305 typename JointPDFType::Pointer * m_ThreaderJointPDF;
00306 typename JointPDFDerivativesType::Pointer * m_ThreaderJointPDFDerivatives;
00307 int * m_ThreaderJointPDFStartBin;
00308 int * m_ThreaderJointPDFEndBin;
00309 mutable double * m_ThreaderJointPDFSum;
00310 mutable double m_JointPDFSum;
00311
00312 bool m_UseExplicitPDFDerivatives;
00313 mutable bool m_ImplicitDerivativesSecondPass;
00314
00315
00316 inline void GetValueThreadPreProcess( unsigned int threadID,
00317 bool withinSampleThread ) const;
00318 inline bool GetValueThreadProcessSample( unsigned int threadID,
00319 unsigned long fixedImageSample,
00320 const MovingImagePointType & mappedPoint,
00321 double movingImageValue ) const;
00322 inline void GetValueThreadPostProcess( unsigned int threadID,
00323 bool withinSampleThread ) const;
00324
00325 inline void GetValueAndDerivativeThreadPreProcess(
00326 unsigned int threadID,
00327 bool withinSampleThread ) const;
00328 inline bool GetValueAndDerivativeThreadProcessSample( unsigned int threadID,
00329 unsigned long fixedImageSample,
00330 const MovingImagePointType & mappedPoint,
00331 double movingImageValue,
00332 const ImageDerivativesType &
00333 movingImageGradientValue ) const;
00334 inline void GetValueAndDerivativeThreadPostProcess(
00335 unsigned int threadID,
00336 bool withinSampleThread ) const;
00337
00338 };
00339
00340 }
00341
00342 #ifndef ITK_MANUAL_INSTANTIATION
00343 #include "itkOptMattesMutualInformationImageToImageMetric.txx"
00344 #endif
00345
00346 #endif
00347