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 #include "itkImageToImageMetric.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 namespace itk
00032 {
00033
00115 template <class TFixedImage,class TMovingImage >
00116 class ITK_EXPORT MattesMutualInformationImageToImageMetric :
00117 public ImageToImageMetric< TFixedImage, TMovingImage >
00118 {
00119 public:
00120
00122 typedef MattesMutualInformationImageToImageMetric Self;
00123 typedef ImageToImageMetric< TFixedImage, TMovingImage > Superclass;
00124 typedef SmartPointer<Self> Pointer;
00125 typedef SmartPointer<const Self> ConstPointer;
00126
00128 itkNewMacro(Self);
00129
00131 itkTypeMacro(MattesMutualInformationImageToImageMetric, ImageToImageMetric);
00132
00134 typedef typename Superclass::TransformType TransformType;
00135 typedef typename Superclass::TransformPointer TransformPointer;
00136 typedef typename Superclass::TransformJacobianType TransformJacobianType;
00137 typedef typename Superclass::InterpolatorType InterpolatorType;
00138 typedef typename Superclass::MeasureType MeasureType;
00139 typedef typename Superclass::DerivativeType DerivativeType;
00140 typedef typename Superclass::ParametersType ParametersType;
00141 typedef typename Superclass::FixedImageType FixedImageType;
00142 typedef typename Superclass::MovingImageType MovingImageType;
00143 typedef typename Superclass::FixedImageConstPointer FixedImageConstPointer;
00144 typedef typename Superclass::MovingImageConstPointer MovingImageCosntPointer;
00145 typedef typename Superclass::CoordinateRepresentationType
00146 CoordinateRepresentationType;
00147
00149 typedef typename FixedImageType::IndexType FixedImageIndexType;
00150 typedef typename FixedImageIndexType::IndexValueType FixedImageIndexValueType;
00151 typedef typename MovingImageType::IndexType MovingImageIndexType;
00152 typedef typename TransformType::InputPointType FixedImagePointType;
00153 typedef typename TransformType::OutputPointType MovingImagePointType;
00154
00156 itkStaticConstMacro( MovingImageDimension, unsigned int,
00157 MovingImageType::ImageDimension );
00158
00166 virtual void Initialize(void) throw ( ExceptionObject );
00167
00169 void GetDerivative(
00170 const ParametersType& parameters,
00171 DerivativeType & Derivative ) const;
00172
00174 MeasureType GetValue( const ParametersType& parameters ) const;
00175
00177 void GetValueAndDerivative( const ParametersType& parameters,
00178 MeasureType& Value, DerivativeType& Derivative ) const;
00179
00181 itkSetClampMacro( NumberOfSpatialSamples, unsigned long,
00182 1, NumericTraits<unsigned long>::max() );
00183 itkGetConstReferenceMacro( NumberOfSpatialSamples, unsigned long);
00184
00186 itkSetClampMacro( NumberOfHistogramBins, unsigned long,
00187 1, NumericTraits<unsigned long>::max() );
00188 itkGetConstReferenceMacro( NumberOfHistogramBins, unsigned long);
00189
00191 static void ReinitializeSeed();
00192 static void ReinitializeSeed(int);
00193
00196 itkSetMacro(UseAllPixels,bool);
00197 itkGetConstReferenceMacro(UseAllPixels,bool);
00198 itkBooleanMacro(UseAllPixels);
00199
00200
00201 protected:
00202
00203 MattesMutualInformationImageToImageMetric();
00204 virtual ~MattesMutualInformationImageToImageMetric() {};
00205 void PrintSelf(std::ostream& os, Indent indent) const;
00206
00210 class FixedImageSpatialSample
00211 {
00212 public:
00213 FixedImageSpatialSample():FixedImageValue(0.0)
00214 { FixedImagePointValue.Fill(0.0); }
00215 ~FixedImageSpatialSample() {};
00216
00217 FixedImagePointType FixedImagePointValue;
00218 double FixedImageValue;
00219 unsigned int FixedImageParzenWindowIndex;
00220 };
00221
00223 typedef std::vector<FixedImageSpatialSample>
00224 FixedImageSpatialSampleContainer;
00225
00227 FixedImageSpatialSampleContainer m_FixedImageSamples;
00228
00230 virtual void SampleFixedImageDomain(
00231 FixedImageSpatialSampleContainer& samples);
00232
00234 virtual void SampleFullFixedImageDomain(
00235 FixedImageSpatialSampleContainer& samples);
00236
00239 virtual void TransformPoint( unsigned int sampleNumber,
00240 const ParametersType& parameters,
00241 MovingImagePointType& mappedPoint, bool& sampleWithinSupportRegion,
00242 double& movingImageValue ) const;
00243
00244 private:
00245
00246 MattesMutualInformationImageToImageMetric(const Self&);
00247 void operator=(const Self&);
00248
00249
00251 typedef float PDFValueType;
00252 typedef std::vector<PDFValueType> MarginalPDFType;
00253
00255 mutable MarginalPDFType m_FixedImageMarginalPDF;
00256
00258 mutable MarginalPDFType m_MovingImageMarginalPDF;
00259
00261 typedef Image<PDFValueType,2> JointPDFType;
00262 typedef Image<PDFValueType,3> JointPDFDerivativesType;
00263 typedef JointPDFType::IndexType JointPDFIndexType;
00264 typedef JointPDFType::PixelType JointPDFValueType;
00265 typedef JointPDFType::RegionType JointPDFRegionType;
00266 typedef JointPDFType::SizeType JointPDFSizeType;
00267 typedef JointPDFDerivativesType::IndexType JointPDFDerivativesIndexType;
00268 typedef JointPDFDerivativesType::PixelType JointPDFDerivativesValueType;
00269 typedef JointPDFDerivativesType::RegionType JointPDFDerivativesRegionType;
00270 typedef JointPDFDerivativesType::SizeType JointPDFDerivativesSizeType;
00271
00273 typename JointPDFType::Pointer m_JointPDF;
00274 typename JointPDFDerivativesType::Pointer m_JointPDFDerivatives;
00275
00276 unsigned long m_NumberOfSpatialSamples;
00277 unsigned long m_NumberOfParameters;
00278
00280 unsigned long m_NumberOfHistogramBins;
00281 double m_MovingImageNormalizedMin;
00282 double m_FixedImageNormalizedMin;
00283 double m_MovingImageTrueMin;
00284 double m_MovingImageTrueMax;
00285 double m_FixedImageBinSize;
00286 double m_MovingImageBinSize;
00287
00289 typedef BSplineKernelFunction<3> CubicBSplineFunctionType;
00290 typedef BSplineDerivativeKernelFunction<3>
00291 CubicBSplineDerivativeFunctionType;
00292
00294 typename CubicBSplineFunctionType::Pointer m_CubicBSplineKernel;
00295 typename CubicBSplineDerivativeFunctionType::Pointer
00296 m_CubicBSplineDerivativeKernel;
00297
00299 virtual void ComputeFixedImageParzenWindowIndices( FixedImageSpatialSampleContainer& samples );
00300
00307 typedef CovariantVector< double,
00308 itkGetStaticConstMacro(MovingImageDimension) > ImageDerivativesType;
00309
00311 virtual void ComputeImageDerivatives( const MovingImagePointType& mappedPoint,
00312 ImageDerivativesType& gradient ) const;
00313
00315 bool m_InterpolatorIsBSpline;
00316
00318 typedef
00319 BSplineInterpolateImageFunction<MovingImageType,
00320 CoordinateRepresentationType> BSplineInterpolatorType;
00321
00323 typename BSplineInterpolatorType::Pointer m_BSplineInterpolator;
00324
00326 typedef CentralDifferenceImageFunction<MovingImageType,
00327 CoordinateRepresentationType> DerivativeFunctionType;
00328
00330 typename DerivativeFunctionType::Pointer m_DerivativeCalculator;
00331
00332
00334 virtual void ComputePDFDerivatives( unsigned int sampleNumber,
00335 int movingImageParzenWindowIndex,
00336 const ImageDerivativesType& movingImageGradientValue,
00337 double cubicBSplineDerivativeValue ) const;
00338
00348 bool m_TransformIsBSpline;
00349
00351 long m_NumParametersPerDim;
00352
00356 unsigned long m_NumBSplineWeights;
00357
00359 itkStaticConstMacro( FixedImageDimension, unsigned int,
00360 FixedImageType::ImageDimension );
00361
00365 enum { DeformationSplineOrder = 3 };
00366
00370 typedef BSplineDeformableTransform<
00371 CoordinateRepresentationType,
00372 ::itk::GetImageDimension<FixedImageType>::ImageDimension,
00373 DeformationSplineOrder> BSplineTransformType;
00374 typedef typename BSplineTransformType::WeightsType
00375 BSplineTransformWeightsType;
00376 typedef typename BSplineTransformType::ParameterIndexArrayType
00377 BSplineTransformIndexArrayType;
00378
00382 typename BSplineTransformType::Pointer m_BSplineTransform;
00383
00388 typedef typename BSplineTransformWeightsType::ValueType WeightsValueType;
00389 typedef Array2D<WeightsValueType> BSplineTransformWeightsArrayType;
00390 typedef typename BSplineTransformIndexArrayType::ValueType IndexValueType;
00391 typedef Array2D<IndexValueType> BSplineTransformIndicesArrayType;
00392 typedef std::vector<MovingImagePointType> MovingImagePointArrayType;
00393 typedef std::vector<bool> BooleanArrayType;
00394
00395 BSplineTransformWeightsArrayType m_BSplineTransformWeightsArray;
00396 BSplineTransformIndicesArrayType m_BSplineTransformIndicesArray;
00397 MovingImagePointArrayType m_PreTransformPointsArray;
00398 BooleanArrayType m_WithinSupportRegionArray;
00399
00400 typedef FixedArray<unsigned long,
00401 ::itk::GetImageDimension<FixedImageType>::ImageDimension> ParametersOffsetType;
00402 ParametersOffsetType m_ParametersOffset;
00403
00404 bool m_UseAllPixels;
00405
00406 virtual void PreComputeTransformValues();
00407
00408
00409 };
00410
00411 }
00412
00413 #ifndef ITK_MANUAL_INSTANTIATION
00414 #include "itkMattesMutualInformationImageToImageMetric.txx"
00415 #endif
00416
00417 #endif
00418