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
00030
00031 namespace itk
00032 {
00033
00110 template <class TFixedImage,class TMovingImage >
00111 class ITK_EXPORT MattesMutualInformationImageToImageMetric :
00112 public ImageToImageMetric< TFixedImage, TMovingImage >
00113 {
00114 public:
00115
00117 typedef MattesMutualInformationImageToImageMetric Self;
00118 typedef ImageToImageMetric< TFixedImage, TMovingImage > Superclass;
00119 typedef SmartPointer<Self> Pointer;
00120 typedef SmartPointer<const Self> ConstPointer;
00121
00123 itkNewMacro(Self);
00124
00126 itkTypeMacro(MattesMutualInformationImageToImageMetric, ImageToImageMetric);
00127
00129 typedef typename Superclass::TransformType TransformType;
00130 typedef typename Superclass::TransformPointer TransformPointer;
00131 typedef typename Superclass::TransformJacobianType TransformJacobianType;
00132 typedef typename Superclass::InterpolatorType InterpolatorType;
00133 typedef typename Superclass::MeasureType MeasureType;
00134 typedef typename Superclass::DerivativeType DerivativeType;
00135 typedef typename Superclass::ParametersType ParametersType;
00136 typedef typename Superclass::FixedImageType FixedImageType;
00137 typedef typename Superclass::MovingImageType MovingImageType;
00138 typedef typename Superclass::FixedImageConstPointer FixedImageConstPointer;
00139 typedef typename Superclass::MovingImageConstPointer MovingImageCosntPointer;
00140
00142 typedef typename FixedImageType::IndexType FixedImageIndexType;
00143 typedef typename FixedImageIndexType::IndexValueType FixedImageIndexValueType;
00144 typedef typename MovingImageType::IndexType MovingImageIndexType;
00145 typedef typename TransformType::InputPointType FixedImagePointType;
00146 typedef typename TransformType::OutputPointType MovingImagePointType;
00147
00149 itkStaticConstMacro( MovingImageDimension, unsigned int,
00150 MovingImageType::ImageDimension );
00151
00159 void Initialize(void) throw ( ExceptionObject );
00160
00162 void GetDerivative(
00163 const ParametersType& parameters,
00164 DerivativeType & Derivative ) const;
00165
00167 MeasureType GetValue( const ParametersType& parameters ) const;
00168
00170 void GetValueAndDerivative( const ParametersType& parameters,
00171 MeasureType& Value, DerivativeType& Derivative ) const;
00172
00174 itkSetClampMacro( NumberOfSpatialSamples, unsigned long,
00175 1, NumericTraits<unsigned long>::max() );
00176 itkGetMacro( NumberOfSpatialSamples, unsigned long);
00177
00179 itkSetClampMacro( NumberOfHistogramBins, unsigned long,
00180 1, NumericTraits<unsigned long>::max() );
00181 itkGetMacro( NumberOfHistogramBins, unsigned long);
00182
00183 protected:
00184
00185 MattesMutualInformationImageToImageMetric();
00186 virtual ~MattesMutualInformationImageToImageMetric() {};
00187 void PrintSelf(std::ostream& os, Indent indent) const;
00188
00189 private:
00190
00191 MattesMutualInformationImageToImageMetric(const Self&);
00192 void operator=(const Self&);
00193
00197 class FixedImageSpatialSample
00198 {
00199 public:
00200 FixedImageSpatialSample():FixedImageValue(0.0)
00201 { FixedImagePointValue.Fill(0.0); }
00202 ~FixedImageSpatialSample() {};
00203
00204 FixedImagePointType FixedImagePointValue;
00205 double FixedImageValue;
00206 };
00207
00209 typedef std::vector<FixedImageSpatialSample>
00210 FixedImageSpatialSampleContainer;
00211
00213 mutable FixedImageSpatialSampleContainer m_FixedImageSamples;
00214
00216 void SampleFixedImageDomain(
00217 FixedImageSpatialSampleContainer& samples) const;
00218
00220 typedef float PDFValueType;
00221 typedef std::vector<PDFValueType> MarginalPDFType;
00222
00224 mutable MarginalPDFType m_FixedImageMarginalPDF;
00225
00227 mutable MarginalPDFType m_MovingImageMarginalPDF;
00228
00230 typedef Image<PDFValueType,2> JointPDFType;
00231 typedef Image<PDFValueType,3> JointPDFDerivativesType;
00232 typedef JointPDFType::IndexType JointPDFIndexType;
00233 typedef JointPDFType::PixelType JointPDFValueType;
00234 typedef JointPDFType::RegionType JointPDFRegionType;
00235 typedef JointPDFType::SizeType JointPDFSizeType;
00236 typedef JointPDFDerivativesType::IndexType JointPDFDerivativesIndexType;
00237 typedef JointPDFDerivativesType::PixelType JointPDFDerivativesValueType;
00238 typedef JointPDFDerivativesType::RegionType JointPDFDerivativesRegionType;
00239 typedef JointPDFDerivativesType::SizeType JointPDFDerivativesSizeType;
00240
00242 typename JointPDFType::Pointer m_JointPDF;
00243 typename JointPDFDerivativesType::Pointer m_JointPDFDerivatives;
00244
00245 unsigned long m_NumberOfSpatialSamples;
00246 unsigned long m_NumberOfParameters;
00247
00249 unsigned long m_NumberOfHistogramBins;
00250 double m_MovingImageNormalizedMin;
00251 double m_FixedImageNormalizedMin;
00252 double m_MovingImageTrueMin;
00253 double m_MovingImageTrueMax;
00254 double m_FixedImageBinSize;
00255 double m_MovingImageBinSize;
00256
00258 typedef BSplineKernelFunction<3> CubicBSplineFunctionType;
00259 typedef BSplineDerivativeKernelFunction<3>
00260 CubicBSplineDerivativeFunctionType;
00261
00263 typename CubicBSplineFunctionType::Pointer m_CubicBSplineKernel;
00264 typename CubicBSplineDerivativeFunctionType::Pointer
00265 m_CubicBSplineDerivativeKernel;
00266
00273 typedef CovariantVector< double,
00274 itkGetStaticConstMacro(MovingImageDimension) > ImageDerivativesType;
00275
00277 virtual void ComputeImageDerivatives( const MovingImagePointType& mappedPoint,
00278 ImageDerivativesType& gradient ) const;
00279
00281 bool m_InterpolatorIsBSpline;
00282
00284 typedef typename Superclass::CoordinateRepresentationType
00285 CoordinateRepresentationType;
00286 typedef
00287 BSplineInterpolateImageFunction<MovingImageType,
00288 CoordinateRepresentationType> BSplineInterpolatorType;
00289
00291 typename BSplineInterpolatorType::Pointer m_BSplineInterpolator;
00292
00294 typedef CentralDifferenceImageFunction<MovingImageType,
00295 CoordinateRepresentationType> DerivativeFunctionType;
00296
00298 typename DerivativeFunctionType::Pointer m_DerivativeCalculator;
00299
00302 virtual void TransformPoint( const FixedImagePointType& fixedImagePoint,
00303 MovingImagePointType& mappedPoint, bool& sampleWithinSupportRegion,
00304 double& movingImageValue ) const;
00305
00307 virtual void ComputePDFDerivatives( const FixedImagePointType& fixedImagePoint,
00308 int fixedImageParzenWindowIndex, int movingImageParzenWindowIndex,
00309 const ImageDerivativesType& movingImageGradientValue,
00310 double cubicBSplineDerivativeValue ) const;
00311
00321 bool m_TransformIsBSpline;
00322
00324 long m_NumParametersPerDim;
00325
00329 unsigned long m_NumBSplineWeights;
00330
00332 itkStaticConstMacro( FixedImageDimension, unsigned int,
00333 FixedImageType::ImageDimension );
00334
00338 enum { DeformationSplineOrder = 3 };
00339
00343 typedef BSplineDeformableTransform<
00344 CoordinateRepresentationType,
00345 ::itk::GetImageDimension<FixedImageType>::ImageDimension,
00346 DeformationSplineOrder> BSplineTransformType;
00347 typedef typename BSplineTransformType::WeightsType
00348 BSplineTransformWeightsType;
00349 typedef typename BSplineTransformType::ParameterIndexArrayType
00350 BSplineTransformIndexArrayType;
00351
00355 typename BSplineTransformType::Pointer m_BSplineTransform;
00356 mutable BSplineTransformWeightsType m_BSplineTransformWeights;
00357 mutable BSplineTransformIndexArrayType m_BSplineTransformIndices;
00358
00359 };
00360
00361 }
00362
00363 #ifndef ITK_MANUAL_INSTANTIATION
00364 #include "itkMattesMutualInformationImageToImageMetric.txx"
00365 #endif
00366
00367 #endif
00368