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: 2006/08/02 11:56:03 $
00007   Version:   $Revision: 1.17 $
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 #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 
00201   void ReinitializeSeed();
00202   void ReinitializeSeed(int);  
00204 
00207   itkSetMacro(UseAllPixels,bool);
00208   itkGetConstReferenceMacro(UseAllPixels,bool);
00209   itkBooleanMacro(UseAllPixels);
00211 
00212 
00213 protected:
00214 
00215   MattesMutualInformationImageToImageMetric();
00216   virtual ~MattesMutualInformationImageToImageMetric() {};
00217   void PrintSelf(std::ostream& os, Indent indent) const;
00218 
00222 
00223   class FixedImageSpatialSample
00224   {
00225   public:
00226     FixedImageSpatialSample():FixedImageValue(0.0)
00227     { FixedImagePointValue.Fill(0.0); }
00228     ~FixedImageSpatialSample() {};
00230 
00231     FixedImagePointType           FixedImagePointValue;
00232     double                        FixedImageValue;
00233     unsigned int                  FixedImageParzenWindowIndex;
00234   };
00236 
00238   typedef std::vector<FixedImageSpatialSample>  
00239   FixedImageSpatialSampleContainer;
00240 
00242   FixedImageSpatialSampleContainer    m_FixedImageSamples;
00243 
00245   virtual void SampleFixedImageDomain( 
00246     FixedImageSpatialSampleContainer& samples);
00247 
00249   virtual void SampleFullFixedImageDomain( 
00250     FixedImageSpatialSampleContainer& samples);
00251 
00254   virtual void TransformPoint( unsigned int sampleNumber,
00255                                const ParametersType& parameters,
00256                                MovingImagePointType& mappedPoint, bool& sampleWithinSupportRegion,
00257                                double& movingImageValue ) const;
00258 
00259 private:
00260 
00261   MattesMutualInformationImageToImageMetric(const Self&); //purposely not implemented
00262   void operator=(const Self&); //purposely not implemented
00263 
00264 
00266   typedef float PDFValueType;
00267   typedef std::vector<PDFValueType> MarginalPDFType;
00268 
00270   mutable MarginalPDFType m_FixedImageMarginalPDF;
00271 
00273   mutable MarginalPDFType m_MovingImageMarginalPDF;
00274 
00276   typedef Image<PDFValueType,2> JointPDFType;
00277   typedef Image<PDFValueType,3> JointPDFDerivativesType;
00278   typedef JointPDFType::IndexType                JointPDFIndexType;
00279   typedef JointPDFType::PixelType                JointPDFValueType;
00280   typedef JointPDFType::RegionType              JointPDFRegionType;
00281   typedef JointPDFType::SizeType                JointPDFSizeType;
00282   typedef JointPDFDerivativesType::IndexType    JointPDFDerivativesIndexType;
00283   typedef JointPDFDerivativesType::PixelType    JointPDFDerivativesValueType;
00284   typedef JointPDFDerivativesType::RegionType    JointPDFDerivativesRegionType;
00285   typedef JointPDFDerivativesType::SizeType      JointPDFDerivativesSizeType;
00286 
00288   typename JointPDFType::Pointer m_JointPDF;
00289   typename JointPDFDerivativesType::Pointer m_JointPDFDerivatives;
00290 
00291   unsigned long m_NumberOfSpatialSamples;
00292   unsigned long m_NumberOfParameters;
00293 
00295   unsigned long m_NumberOfHistogramBins;
00296   double m_MovingImageNormalizedMin;
00297   double m_FixedImageNormalizedMin;
00298   double m_MovingImageTrueMin;
00299   double m_MovingImageTrueMax;
00300   double m_FixedImageBinSize;
00301   double m_MovingImageBinSize;
00302 
00304   typedef BSplineKernelFunction<3> CubicBSplineFunctionType;
00305   typedef BSplineDerivativeKernelFunction<3> 
00306   CubicBSplineDerivativeFunctionType;
00307 
00309   typename CubicBSplineFunctionType::Pointer m_CubicBSplineKernel;
00310   typename CubicBSplineDerivativeFunctionType::Pointer 
00311   m_CubicBSplineDerivativeKernel;
00312 
00314   virtual void ComputeFixedImageParzenWindowIndices( FixedImageSpatialSampleContainer& samples );
00315 
00322   typedef CovariantVector< double,
00323                            itkGetStaticConstMacro(MovingImageDimension) > ImageDerivativesType;
00324 
00326   virtual void ComputeImageDerivatives( const MovingImagePointType& mappedPoint,
00327                                         ImageDerivativesType& gradient ) const;
00328 
00330   bool m_InterpolatorIsBSpline;
00331 
00333   typedef
00334   BSplineInterpolateImageFunction<MovingImageType,
00335                                   CoordinateRepresentationType> BSplineInterpolatorType;
00336 
00338   typename BSplineInterpolatorType::Pointer m_BSplineInterpolator;
00339 
00341   typedef CentralDifferenceImageFunction<MovingImageType,
00342                                          CoordinateRepresentationType> DerivativeFunctionType;
00343 
00345   typename DerivativeFunctionType::Pointer m_DerivativeCalculator;
00346 
00347 
00349   virtual void ComputePDFDerivatives( unsigned int sampleNumber,
00350                                       int movingImageParzenWindowIndex,
00351                                       const ImageDerivativesType& movingImageGradientValue,
00352                                       double cubicBSplineDerivativeValue ) const;
00353 
00363   bool m_TransformIsBSpline;
00364 
00366   long m_NumParametersPerDim;
00367 
00371   unsigned long m_NumBSplineWeights;
00372 
00374   itkStaticConstMacro( FixedImageDimension, unsigned int,
00375                        FixedImageType::ImageDimension );
00376 
00380   enum { DeformationSplineOrder = 3 };
00381 
00385   typedef BSplineDeformableTransform<
00386     CoordinateRepresentationType,
00387     ::itk::GetImageDimension<FixedImageType>::ImageDimension,
00388     DeformationSplineOrder> BSplineTransformType;
00389   typedef typename BSplineTransformType::WeightsType 
00390   BSplineTransformWeightsType;
00391   typedef typename BSplineTransformType::ParameterIndexArrayType 
00392   BSplineTransformIndexArrayType;
00393 
00397   typename BSplineTransformType::Pointer m_BSplineTransform;
00398 
00403   typedef typename BSplineTransformWeightsType::ValueType WeightsValueType;
00404   typedef          Array2D<WeightsValueType> BSplineTransformWeightsArrayType;
00405   typedef typename BSplineTransformIndexArrayType::ValueType IndexValueType;
00406   typedef          Array2D<IndexValueType> BSplineTransformIndicesArrayType;
00407   typedef          std::vector<MovingImagePointType> MovingImagePointArrayType;
00408   typedef          std::vector<bool> BooleanArrayType;
00409 
00410   BSplineTransformWeightsArrayType      m_BSplineTransformWeightsArray;
00411   BSplineTransformIndicesArrayType      m_BSplineTransformIndicesArray;
00412   MovingImagePointArrayType             m_PreTransformPointsArray;
00413   BooleanArrayType                      m_WithinSupportRegionArray;
00414   
00415   typedef FixedArray<unsigned long, 
00416     ::itk::GetImageDimension<FixedImageType>::ImageDimension> ParametersOffsetType;
00417   ParametersOffsetType                  m_ParametersOffset;
00418 
00419   bool             m_UseAllPixels;
00420 
00421   virtual void PreComputeTransformValues();
00422 
00423   bool             m_ReseedIterator;
00424   int              m_RandomSeed;
00425   
00426 };
00427 
00428 } // end namespace itk
00429 
00430 #ifndef ITK_MANUAL_INSTANTIATION
00431 #include "itkMattesMutualInformationImageToImageMetric.txx"
00432 #endif
00433 
00434 #endif
00435 
00436 

Generated at Mon Mar 12 01:35:12 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000