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);
00185
00187 itkSetClampMacro( NumberOfHistogramBins, unsigned long,
00188 1, NumericTraits<unsigned long>::max() );
00189 itkGetConstReferenceMacro( NumberOfHistogramBins, unsigned long);
00191
00193 void ReinitializeSeed();
00194 void ReinitializeSeed(int);
00196
00199 itkSetMacro(UseAllPixels,bool);
00200 itkGetConstReferenceMacro(UseAllPixels,bool);
00201 itkBooleanMacro(UseAllPixels);
00203
00204
00205 protected:
00206
00207 MattesMutualInformationImageToImageMetric();
00208 virtual ~MattesMutualInformationImageToImageMetric() {};
00209 void PrintSelf(std::ostream& os, Indent indent) const;
00210
00214
00215 class FixedImageSpatialSample
00216 {
00217 public:
00218 FixedImageSpatialSample():FixedImageValue(0.0)
00219 { FixedImagePointValue.Fill(0.0); }
00220 ~FixedImageSpatialSample() {};
00222
00223 FixedImagePointType FixedImagePointValue;
00224 double FixedImageValue;
00225 unsigned int FixedImageParzenWindowIndex;
00226 };
00228
00230 typedef std::vector<FixedImageSpatialSample>
00231 FixedImageSpatialSampleContainer;
00232
00234 FixedImageSpatialSampleContainer m_FixedImageSamples;
00235
00237 virtual void SampleFixedImageDomain(
00238 FixedImageSpatialSampleContainer& samples);
00239
00241 virtual void SampleFullFixedImageDomain(
00242 FixedImageSpatialSampleContainer& samples);
00243
00246 virtual void TransformPoint( unsigned int sampleNumber,
00247 const ParametersType& parameters,
00248 MovingImagePointType& mappedPoint, bool& sampleWithinSupportRegion,
00249 double& movingImageValue ) const;
00250
00251 private:
00252
00253 MattesMutualInformationImageToImageMetric(const Self&);
00254 void operator=(const Self&);
00255
00256
00258 typedef float PDFValueType;
00259 typedef std::vector<PDFValueType> MarginalPDFType;
00260
00262 mutable MarginalPDFType m_FixedImageMarginalPDF;
00263
00265 mutable MarginalPDFType m_MovingImageMarginalPDF;
00266
00268 typedef Image<PDFValueType,2> JointPDFType;
00269 typedef Image<PDFValueType,3> JointPDFDerivativesType;
00270 typedef JointPDFType::IndexType JointPDFIndexType;
00271 typedef JointPDFType::PixelType JointPDFValueType;
00272 typedef JointPDFType::RegionType JointPDFRegionType;
00273 typedef JointPDFType::SizeType JointPDFSizeType;
00274 typedef JointPDFDerivativesType::IndexType JointPDFDerivativesIndexType;
00275 typedef JointPDFDerivativesType::PixelType JointPDFDerivativesValueType;
00276 typedef JointPDFDerivativesType::RegionType JointPDFDerivativesRegionType;
00277 typedef JointPDFDerivativesType::SizeType JointPDFDerivativesSizeType;
00278
00280 typename JointPDFType::Pointer m_JointPDF;
00281 typename JointPDFDerivativesType::Pointer m_JointPDFDerivatives;
00282
00283 unsigned long m_NumberOfSpatialSamples;
00284 unsigned long m_NumberOfParameters;
00285
00287 unsigned long m_NumberOfHistogramBins;
00288 double m_MovingImageNormalizedMin;
00289 double m_FixedImageNormalizedMin;
00290 double m_MovingImageTrueMin;
00291 double m_MovingImageTrueMax;
00292 double m_FixedImageBinSize;
00293 double m_MovingImageBinSize;
00294
00296 typedef BSplineKernelFunction<3> CubicBSplineFunctionType;
00297 typedef BSplineDerivativeKernelFunction<3>
00298 CubicBSplineDerivativeFunctionType;
00299
00301 typename CubicBSplineFunctionType::Pointer m_CubicBSplineKernel;
00302 typename CubicBSplineDerivativeFunctionType::Pointer
00303 m_CubicBSplineDerivativeKernel;
00304
00306 virtual void ComputeFixedImageParzenWindowIndices( FixedImageSpatialSampleContainer& samples );
00307
00314 typedef CovariantVector< double,
00315 itkGetStaticConstMacro(MovingImageDimension) > ImageDerivativesType;
00316
00318 virtual void ComputeImageDerivatives( const MovingImagePointType& mappedPoint,
00319 ImageDerivativesType& gradient ) const;
00320
00322 bool m_InterpolatorIsBSpline;
00323
00325 typedef
00326 BSplineInterpolateImageFunction<MovingImageType,
00327 CoordinateRepresentationType> BSplineInterpolatorType;
00328
00330 typename BSplineInterpolatorType::Pointer m_BSplineInterpolator;
00331
00333 typedef CentralDifferenceImageFunction<MovingImageType,
00334 CoordinateRepresentationType> DerivativeFunctionType;
00335
00337 typename DerivativeFunctionType::Pointer m_DerivativeCalculator;
00338
00339
00341 virtual void ComputePDFDerivatives( unsigned int sampleNumber,
00342 int movingImageParzenWindowIndex,
00343 const ImageDerivativesType& movingImageGradientValue,
00344 double cubicBSplineDerivativeValue ) const;
00345
00355 bool m_TransformIsBSpline;
00356
00358 long m_NumParametersPerDim;
00359
00363 unsigned long m_NumBSplineWeights;
00364
00366 itkStaticConstMacro( FixedImageDimension, unsigned int,
00367 FixedImageType::ImageDimension );
00368
00372 enum { DeformationSplineOrder = 3 };
00373
00377 typedef BSplineDeformableTransform<
00378 CoordinateRepresentationType,
00379 ::itk::GetImageDimension<FixedImageType>::ImageDimension,
00380 DeformationSplineOrder> BSplineTransformType;
00381 typedef typename BSplineTransformType::WeightsType
00382 BSplineTransformWeightsType;
00383 typedef typename BSplineTransformType::ParameterIndexArrayType
00384 BSplineTransformIndexArrayType;
00385
00389 typename BSplineTransformType::Pointer m_BSplineTransform;
00390
00395 typedef typename BSplineTransformWeightsType::ValueType WeightsValueType;
00396 typedef Array2D<WeightsValueType> BSplineTransformWeightsArrayType;
00397 typedef typename BSplineTransformIndexArrayType::ValueType IndexValueType;
00398 typedef Array2D<IndexValueType> BSplineTransformIndicesArrayType;
00399 typedef std::vector<MovingImagePointType> MovingImagePointArrayType;
00400 typedef std::vector<bool> BooleanArrayType;
00401
00402 BSplineTransformWeightsArrayType m_BSplineTransformWeightsArray;
00403 BSplineTransformIndicesArrayType m_BSplineTransformIndicesArray;
00404 MovingImagePointArrayType m_PreTransformPointsArray;
00405 BooleanArrayType m_WithinSupportRegionArray;
00406
00407 typedef FixedArray<unsigned long,
00408 ::itk::GetImageDimension<FixedImageType>::ImageDimension> ParametersOffsetType;
00409 ParametersOffsetType m_ParametersOffset;
00410
00411 bool m_UseAllPixels;
00412
00413 virtual void PreComputeTransformValues();
00414
00415 bool m_ReseedIterator;
00416 int m_RandomSeed;
00417
00418 };
00419
00420 }
00421
00422 #ifndef ITK_MANUAL_INSTANTIATION
00423 #include "itkMattesMutualInformationImageToImageMetric.txx"
00424 #endif
00425
00426 #endif
00427
00428