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: 2007/03/31 20:19:16 $
00007   Version:   $Revision: 1.18 $
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( const ParametersType& parameters,
00170                       DerivativeType & Derivative ) const;
00171 
00173   MeasureType GetValue( const ParametersType& parameters ) const;
00174 
00176   void GetValueAndDerivative( const ParametersType& parameters, 
00177                               MeasureType& Value,
00178                               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,
00257                                bool& sampleWithinSupportRegion,
00258                                double& movingImageValue ) const;
00259 
00260 private:
00261 
00262   //purposely not implemented
00263   MattesMutualInformationImageToImageMetric(const Self&); 
00264   //purposely not implemented
00265   void operator=(const Self&); 
00266 
00267 
00269   typedef float PDFValueType;
00270   typedef std::vector<PDFValueType> MarginalPDFType;
00271 
00273   mutable MarginalPDFType m_FixedImageMarginalPDF;
00274 
00276   mutable MarginalPDFType m_MovingImageMarginalPDF;
00277 
00279   typedef Image<PDFValueType,2> JointPDFType;
00280   typedef Image<PDFValueType,3> JointPDFDerivativesType;
00281   typedef JointPDFType::IndexType                JointPDFIndexType;
00282   typedef JointPDFType::PixelType                JointPDFValueType;
00283   typedef JointPDFType::RegionType              JointPDFRegionType;
00284   typedef JointPDFType::SizeType                JointPDFSizeType;
00285   typedef JointPDFDerivativesType::IndexType    JointPDFDerivativesIndexType;
00286   typedef JointPDFDerivativesType::PixelType    JointPDFDerivativesValueType;
00287   typedef JointPDFDerivativesType::RegionType    JointPDFDerivativesRegionType;
00288   typedef JointPDFDerivativesType::SizeType      JointPDFDerivativesSizeType;
00289 
00291   typename JointPDFType::Pointer m_JointPDF;
00292   typename JointPDFDerivativesType::Pointer m_JointPDFDerivatives;
00293 
00294   unsigned long m_NumberOfSpatialSamples;
00295   unsigned long m_NumberOfParameters;
00296 
00298   unsigned long m_NumberOfHistogramBins;
00299   double m_MovingImageNormalizedMin;
00300   double m_FixedImageNormalizedMin;
00301   double m_MovingImageTrueMin;
00302   double m_MovingImageTrueMax;
00303   double m_FixedImageBinSize;
00304   double m_MovingImageBinSize;
00305 
00307   typedef BSplineKernelFunction<3> CubicBSplineFunctionType;
00308   typedef BSplineDerivativeKernelFunction<3> 
00309   CubicBSplineDerivativeFunctionType;
00310 
00312   typename CubicBSplineFunctionType::Pointer m_CubicBSplineKernel;
00313   typename CubicBSplineDerivativeFunctionType::Pointer 
00314   m_CubicBSplineDerivativeKernel;
00315 
00317   virtual void ComputeFixedImageParzenWindowIndices( 
00318                    FixedImageSpatialSampleContainer& samples );
00319 
00326   typedef CovariantVector< double,
00327                            itkGetStaticConstMacro(MovingImageDimension) >
00328                                                          ImageDerivativesType;
00329 
00331   virtual void ComputeImageDerivatives( const MovingImagePointType& mappedPoint,
00332                                         ImageDerivativesType& gradient ) const;
00333 
00335   bool m_InterpolatorIsBSpline;
00336 
00338   typedef
00339   BSplineInterpolateImageFunction<MovingImageType,
00340                                   CoordinateRepresentationType> 
00341                                                       BSplineInterpolatorType;
00342 
00344   typename BSplineInterpolatorType::Pointer m_BSplineInterpolator;
00345 
00347   typedef CentralDifferenceImageFunction<MovingImageType,
00348                                          CoordinateRepresentationType> 
00349                                                        DerivativeFunctionType;
00350 
00352   typename DerivativeFunctionType::Pointer m_DerivativeCalculator;
00353 
00354 
00356   virtual void ComputePDFDerivatives( unsigned int sampleNumber,
00357                                       int movingImageParzenWindowIndex,
00358                                       const ImageDerivativesType&
00359                                                 movingImageGradientValue,
00360                                       double cubicBSplineDerivativeValue 
00361                                       ) const;
00362 
00372   bool m_TransformIsBSpline;
00373 
00375   long m_NumParametersPerDim;
00376 
00380   unsigned long m_NumBSplineWeights;
00381 
00383   itkStaticConstMacro( FixedImageDimension, unsigned int,
00384                        FixedImageType::ImageDimension );
00385 
00389   enum { DeformationSplineOrder = 3 };
00390 
00394   typedef BSplineDeformableTransform<
00395     CoordinateRepresentationType,
00396     ::itk::GetImageDimension<FixedImageType>::ImageDimension,
00397     DeformationSplineOrder> BSplineTransformType;
00398   typedef typename BSplineTransformType::WeightsType 
00399   BSplineTransformWeightsType;
00400   typedef typename BSplineTransformType::ParameterIndexArrayType 
00401   BSplineTransformIndexArrayType;
00402 
00406   typename BSplineTransformType::Pointer m_BSplineTransform;
00407 
00412   typedef typename BSplineTransformWeightsType::ValueType WeightsValueType;
00413   typedef          Array2D<WeightsValueType> BSplineTransformWeightsArrayType;
00414   typedef typename BSplineTransformIndexArrayType::ValueType IndexValueType;
00415   typedef          Array2D<IndexValueType> BSplineTransformIndicesArrayType;
00416   typedef          std::vector<MovingImagePointType> MovingImagePointArrayType;
00417   typedef          std::vector<bool> BooleanArrayType;
00418 
00419   BSplineTransformWeightsArrayType      m_BSplineTransformWeightsArray;
00420   BSplineTransformIndicesArrayType      m_BSplineTransformIndicesArray;
00421   MovingImagePointArrayType             m_PreTransformPointsArray;
00422   BooleanArrayType                      m_WithinSupportRegionArray;
00423   
00424   typedef FixedArray<unsigned long, 
00425                      ::itk::GetImageDimension<FixedImageType>::ImageDimension>
00426                                                           ParametersOffsetType;
00427   ParametersOffsetType                  m_ParametersOffset;
00428 
00429   bool             m_UseAllPixels;
00430 
00431   virtual void PreComputeTransformValues();
00432 
00433   bool             m_ReseedIterator;
00434   int              m_RandomSeed;
00435   
00436 };
00437 
00438 } // end namespace itk
00439 
00440 #ifndef ITK_MANUAL_INSTANTIATION
00441 #include "itkMattesMutualInformationImageToImageMetric.txx"
00442 #endif
00443 
00444 #endif
00445 
00446 

Generated at Sun Sep 23 13:27:59 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000