Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkMattesMutualInformationImageToImageMetric.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkMattesMutualInformationImageToImageMetric.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-03-14 16:26:01 $
00007   Version:   $Revision: 1.25 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkMattesMutualInformationImageToImageMetric_h
00018 #define __itkMattesMutualInformationImageToImageMetric_h
00019 
00020 // First make sure that the configuration is available.
00021 // This line can be removed once the optimized versions
00022 // gets integrated into the main directories.
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 FixedImageIndexType::IndexValueType FixedImageIndexValueType;
00163   typedef typename MovingImageType::IndexType           MovingImageIndexType;
00164   typedef typename TransformType::InputPointType        FixedImagePointType;
00165   typedef typename TransformType::OutputPointType       MovingImagePointType;
00166 
00168   itkStaticConstMacro( MovingImageDimension, unsigned int,
00169                        MovingImageType::ImageDimension );
00170 
00178   virtual void Initialize(void) throw ( ExceptionObject );
00179 
00181   void GetDerivative( const ParametersType& parameters,
00182                       DerivativeType & Derivative ) const;
00183 
00185   MeasureType GetValue( const ParametersType& parameters ) const;
00186 
00188   void GetValueAndDerivative( const ParametersType& parameters, 
00189                               MeasureType& Value,
00190                               DerivativeType& Derivative ) const;
00191 
00193   itkSetClampMacro( NumberOfSpatialSamples, unsigned long,
00194                     1, NumericTraits<unsigned long>::max() );
00195   itkGetConstReferenceMacro( NumberOfSpatialSamples, unsigned long); 
00197 
00199   itkSetClampMacro( NumberOfHistogramBins, unsigned long,
00200                     1, NumericTraits<unsigned long>::max() );
00201   itkGetConstReferenceMacro( NumberOfHistogramBins, unsigned long);   
00203 
00213   void ReinitializeSeed();
00214   void ReinitializeSeed(int);  
00216 
00219   itkSetMacro(UseAllPixels,bool);
00220   itkGetConstReferenceMacro(UseAllPixels,bool);
00221   itkBooleanMacro(UseAllPixels);
00223 
00248   itkSetMacro(UseExplicitPDFDerivatives,bool);
00249   itkGetConstReferenceMacro(UseExplicitPDFDerivatives,bool);
00250   itkBooleanMacro(UseExplicitPDFDerivatives);
00252 
00269   itkSetMacro(UseCachingOfBSplineWeights,bool);
00270   itkGetConstReferenceMacro(UseCachingOfBSplineWeights,bool);
00271   itkBooleanMacro(UseCachingOfBSplineWeights);
00273 
00274 protected:
00275 
00276   MattesMutualInformationImageToImageMetric();
00277   virtual ~MattesMutualInformationImageToImageMetric() {};
00278   void PrintSelf(std::ostream& os, Indent indent) const;
00279 
00283 
00284   class FixedImageSpatialSample
00285     {
00286     public:
00287       FixedImageSpatialSample():FixedImageValue(0.0)
00288       { FixedImagePointValue.Fill(0.0); }
00289       ~FixedImageSpatialSample() {};
00291 
00292       FixedImagePointType           FixedImagePointValue;
00293       double                        FixedImageValue;
00294       unsigned int                  FixedImageParzenWindowIndex;
00295     };
00297 
00299   typedef std::vector<FixedImageSpatialSample>  
00300   FixedImageSpatialSampleContainer;
00301 
00303   FixedImageSpatialSampleContainer    m_FixedImageSamples;
00304 
00306   virtual void SampleFixedImageDomain( 
00307     FixedImageSpatialSampleContainer& samples);
00308 
00310   virtual void SampleFullFixedImageDomain( 
00311     FixedImageSpatialSampleContainer& samples);
00312 
00315   virtual void TransformPoint( unsigned int sampleNumber,
00316                                const ParametersType& parameters,
00317                                MovingImagePointType& mappedPoint,
00318                                bool& sampleWithinSupportRegion,
00319                                double& movingImageValue ) const;
00320 
00321 private:
00322 
00323   //purposely not implemented
00324   MattesMutualInformationImageToImageMetric(const Self&); 
00325   //purposely not implemented
00326   void operator=(const Self&); 
00327 
00328 
00330   typedef float                       PDFValueType;
00331   typedef std::vector<PDFValueType>   MarginalPDFType;
00332 
00334   mutable MarginalPDFType             m_FixedImageMarginalPDF;
00335 
00337   mutable MarginalPDFType             m_MovingImageMarginalPDF;
00338 
00340   typedef double                      PRatioType;
00341   typedef Array2D< PRatioType >       PRatioArrayType;
00342   mutable PRatioArrayType             m_PRatioArray;
00343 
00345   mutable DerivativeType              m_MetricDerivative;
00346 
00348   typedef Image<PDFValueType,2>                 JointPDFType;
00349   typedef JointPDFType::IndexType               JointPDFIndexType;
00350   typedef JointPDFType::PixelType               JointPDFValueType;
00351   typedef JointPDFType::RegionType              JointPDFRegionType;
00352   typedef JointPDFType::SizeType                JointPDFSizeType;
00353   typedef Image<PDFValueType,3>                 JointPDFDerivativesType;
00354   typedef JointPDFDerivativesType::IndexType    JointPDFDerivativesIndexType;
00355   typedef JointPDFDerivativesType::PixelType    JointPDFDerivativesValueType;
00356   typedef JointPDFDerivativesType::RegionType   JointPDFDerivativesRegionType;
00357   typedef JointPDFDerivativesType::SizeType     JointPDFDerivativesSizeType;
00358 
00360   typename JointPDFType::Pointer                m_JointPDF;
00361   typename JointPDFDerivativesType::Pointer     m_JointPDFDerivatives;
00362 
00363   unsigned long                                 m_NumberOfSpatialSamples;
00364   unsigned long                                 m_NumberOfParameters;
00365 
00367   unsigned long  m_NumberOfHistogramBins;
00368   double         m_MovingImageNormalizedMin;
00369   double         m_FixedImageNormalizedMin;
00370   double         m_MovingImageTrueMin;
00371   double         m_MovingImageTrueMax;
00372   double         m_FixedImageBinSize;
00373   double         m_MovingImageBinSize;
00374 
00376   typedef BSplineKernelFunction<3>           CubicBSplineFunctionType;
00377   typedef BSplineDerivativeKernelFunction<3> CubicBSplineDerivativeFunctionType;
00378 
00380   typename CubicBSplineFunctionType::Pointer   m_CubicBSplineKernel;
00381   typename CubicBSplineDerivativeFunctionType::Pointer 
00382   m_CubicBSplineDerivativeKernel;
00383 
00385   virtual void ComputeFixedImageParzenWindowIndices( 
00386                    FixedImageSpatialSampleContainer& samples );
00387 
00394   typedef CovariantVector< double,
00395                            itkGetStaticConstMacro(MovingImageDimension) >
00396                                                          ImageDerivativesType;
00397 
00399   virtual void ComputeImageDerivatives( const MovingImagePointType& mappedPoint,
00400                                         ImageDerivativesType& gradient ) const;
00401 
00403   bool m_InterpolatorIsBSpline;
00404 
00406   typedef
00407   BSplineInterpolateImageFunction<MovingImageType,
00408                                   CoordinateRepresentationType> 
00409                                                       BSplineInterpolatorType;
00410 
00412   typename BSplineInterpolatorType::Pointer m_BSplineInterpolator;
00413 
00415   typedef CentralDifferenceImageFunction<MovingImageType,
00416                                          CoordinateRepresentationType> 
00417                                                        DerivativeFunctionType;
00418 
00420   typename DerivativeFunctionType::Pointer m_DerivativeCalculator;
00421 
00422 
00424   virtual void ComputePDFDerivatives( unsigned int sampleNumber,
00425                                       int movingImageParzenWindowIndex,
00426                                       const ImageDerivativesType&
00427                                                 movingImageGradientValue,
00428                                       double cubicBSplineDerivativeValue
00429                                       ) const;
00430 
00440   bool m_TransformIsBSpline;
00441 
00443   long m_NumParametersPerDim;
00444 
00448   unsigned long m_NumBSplineWeights;
00449 
00451   itkStaticConstMacro( FixedImageDimension, unsigned int,
00452                        FixedImageType::ImageDimension );
00453 
00457   enum { DeformationSplineOrder = 3 };
00458 
00462   typedef BSplineDeformableTransform<
00463     CoordinateRepresentationType,
00464     ::itk::GetImageDimension<FixedImageType>::ImageDimension,
00465     DeformationSplineOrder> BSplineTransformType;
00466   typedef typename BSplineTransformType::WeightsType 
00467   BSplineTransformWeightsType;
00468   typedef typename BSplineTransformType::ParameterIndexArrayType 
00469   BSplineTransformIndexArrayType;
00470 
00474   typename BSplineTransformType::Pointer m_BSplineTransform;
00475 
00480   typedef typename BSplineTransformWeightsType::ValueType WeightsValueType;
00481   typedef          Array2D<WeightsValueType> BSplineTransformWeightsArrayType;
00482   typedef typename BSplineTransformIndexArrayType::ValueType IndexValueType;
00483   typedef          Array2D<IndexValueType> BSplineTransformIndicesArrayType;
00484   typedef          std::vector<MovingImagePointType> MovingImagePointArrayType;
00485   typedef          std::vector<bool> BooleanArrayType;
00486 
00487   BSplineTransformWeightsArrayType      m_BSplineTransformWeightsArray;
00488   BSplineTransformIndicesArrayType      m_BSplineTransformIndicesArray;
00489   MovingImagePointArrayType             m_PreTransformPointsArray;
00490   BooleanArrayType                      m_WithinSupportRegionArray;
00491   
00492   typedef FixedArray<unsigned long, 
00493                      ::itk::GetImageDimension<FixedImageType>::ImageDimension>
00494                                                           ParametersOffsetType;
00495   ParametersOffsetType                  m_ParametersOffset;
00496 
00497   bool             m_UseAllPixels;
00498 
00499   virtual void PreComputeTransformValues();
00500 
00501   bool             m_ReseedIterator;
00502   int              m_RandomSeed;
00503   
00504   // Selection of explicit or implicit computation of PDF derivatives
00505   // with respect to Transform parameters.
00506   bool             m_UseExplicitPDFDerivatives;
00507 
00508   // Variables needed for optionally caching values when using a BSpline transform.
00509   bool                                    m_UseCachingOfBSplineWeights;
00510   mutable BSplineTransformWeightsType     m_Weights;
00511   mutable BSplineTransformIndexArrayType  m_Indices;
00512 
00513 };
00514 
00515 } // end namespace itk
00516 
00517 #ifndef ITK_MANUAL_INSTANTIATION
00518 #include "itkMattesMutualInformationImageToImageMetric.txx"
00519 #endif
00520 
00521 #endif
00522 
00523 #endif
00524 
00525 

Generated at Wed Nov 5 22:46:10 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000