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: 2005/10/31 22:14:35 $
00007   Version:   $Revision: 1.16 $
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); 
00184 
00186   itkSetClampMacro( NumberOfHistogramBins, unsigned long,
00187                     1, NumericTraits<unsigned long>::max() );
00188   itkGetConstReferenceMacro( NumberOfHistogramBins, unsigned long);   
00189 
00191   void ReinitializeSeed();
00192   void ReinitializeSeed(int);  
00193 
00196   itkSetMacro(UseAllPixels,bool);
00197   itkGetConstReferenceMacro(UseAllPixels,bool);
00198   itkBooleanMacro(UseAllPixels);
00199 
00200 
00201 protected:
00202 
00203   MattesMutualInformationImageToImageMetric();
00204   virtual ~MattesMutualInformationImageToImageMetric() {};
00205   void PrintSelf(std::ostream& os, Indent indent) const;
00206 
00210 
00211   class FixedImageSpatialSample
00212   {
00213   public:
00214     FixedImageSpatialSample():FixedImageValue(0.0)
00215     { FixedImagePointValue.Fill(0.0); }
00216     ~FixedImageSpatialSample() {};
00217 
00218     FixedImagePointType           FixedImagePointValue;
00219     double                        FixedImageValue;
00220     unsigned int                  FixedImageParzenWindowIndex;
00221   };
00223 
00225   typedef std::vector<FixedImageSpatialSample>  
00226   FixedImageSpatialSampleContainer;
00227 
00229   FixedImageSpatialSampleContainer    m_FixedImageSamples;
00230 
00232   virtual void SampleFixedImageDomain( 
00233     FixedImageSpatialSampleContainer& samples);
00234 
00236   virtual void SampleFullFixedImageDomain( 
00237     FixedImageSpatialSampleContainer& samples);
00238 
00241   virtual void TransformPoint( unsigned int sampleNumber,
00242                                const ParametersType& parameters,
00243                                MovingImagePointType& mappedPoint, bool& sampleWithinSupportRegion,
00244                                double& movingImageValue ) const;
00245 
00246 private:
00247 
00248   MattesMutualInformationImageToImageMetric(const Self&); //purposely not implemented
00249   void operator=(const Self&); //purposely not implemented
00250 
00251 
00253   typedef float PDFValueType;
00254   typedef std::vector<PDFValueType> MarginalPDFType;
00255 
00257   mutable MarginalPDFType m_FixedImageMarginalPDF;
00258 
00260   mutable MarginalPDFType m_MovingImageMarginalPDF;
00261 
00263   typedef Image<PDFValueType,2> JointPDFType;
00264   typedef Image<PDFValueType,3> JointPDFDerivativesType;
00265   typedef JointPDFType::IndexType                JointPDFIndexType;
00266   typedef JointPDFType::PixelType                JointPDFValueType;
00267   typedef JointPDFType::RegionType              JointPDFRegionType;
00268   typedef JointPDFType::SizeType                JointPDFSizeType;
00269   typedef JointPDFDerivativesType::IndexType    JointPDFDerivativesIndexType;
00270   typedef JointPDFDerivativesType::PixelType    JointPDFDerivativesValueType;
00271   typedef JointPDFDerivativesType::RegionType    JointPDFDerivativesRegionType;
00272   typedef JointPDFDerivativesType::SizeType      JointPDFDerivativesSizeType;
00273 
00275   typename JointPDFType::Pointer m_JointPDF;
00276   typename JointPDFDerivativesType::Pointer m_JointPDFDerivatives;
00277 
00278   unsigned long m_NumberOfSpatialSamples;
00279   unsigned long m_NumberOfParameters;
00280 
00282   unsigned long m_NumberOfHistogramBins;
00283   double m_MovingImageNormalizedMin;
00284   double m_FixedImageNormalizedMin;
00285   double m_MovingImageTrueMin;
00286   double m_MovingImageTrueMax;
00287   double m_FixedImageBinSize;
00288   double m_MovingImageBinSize;
00289 
00291   typedef BSplineKernelFunction<3> CubicBSplineFunctionType;
00292   typedef BSplineDerivativeKernelFunction<3> 
00293   CubicBSplineDerivativeFunctionType;
00294 
00296   typename CubicBSplineFunctionType::Pointer m_CubicBSplineKernel;
00297   typename CubicBSplineDerivativeFunctionType::Pointer 
00298   m_CubicBSplineDerivativeKernel;
00299 
00301   virtual void ComputeFixedImageParzenWindowIndices( FixedImageSpatialSampleContainer& samples );
00302 
00309   typedef CovariantVector< double,
00310                            itkGetStaticConstMacro(MovingImageDimension) > ImageDerivativesType;
00311 
00313   virtual void ComputeImageDerivatives( const MovingImagePointType& mappedPoint,
00314                                         ImageDerivativesType& gradient ) const;
00315 
00317   bool m_InterpolatorIsBSpline;
00318 
00320   typedef
00321   BSplineInterpolateImageFunction<MovingImageType,
00322                                   CoordinateRepresentationType> BSplineInterpolatorType;
00323 
00325   typename BSplineInterpolatorType::Pointer m_BSplineInterpolator;
00326 
00328   typedef CentralDifferenceImageFunction<MovingImageType,
00329                                          CoordinateRepresentationType> DerivativeFunctionType;
00330 
00332   typename DerivativeFunctionType::Pointer m_DerivativeCalculator;
00333 
00334 
00336   virtual void ComputePDFDerivatives( unsigned int sampleNumber,
00337                                       int movingImageParzenWindowIndex,
00338                                       const ImageDerivativesType& movingImageGradientValue,
00339                                       double cubicBSplineDerivativeValue ) const;
00340 
00350   bool m_TransformIsBSpline;
00351 
00353   long m_NumParametersPerDim;
00354 
00358   unsigned long m_NumBSplineWeights;
00359 
00361   itkStaticConstMacro( FixedImageDimension, unsigned int,
00362                        FixedImageType::ImageDimension );
00363 
00367   enum { DeformationSplineOrder = 3 };
00368 
00372   typedef BSplineDeformableTransform<
00373     CoordinateRepresentationType,
00374     ::itk::GetImageDimension<FixedImageType>::ImageDimension,
00375     DeformationSplineOrder> BSplineTransformType;
00376   typedef typename BSplineTransformType::WeightsType 
00377   BSplineTransformWeightsType;
00378   typedef typename BSplineTransformType::ParameterIndexArrayType 
00379   BSplineTransformIndexArrayType;
00380 
00384   typename BSplineTransformType::Pointer m_BSplineTransform;
00385 
00390   typedef typename BSplineTransformWeightsType::ValueType WeightsValueType;
00391   typedef          Array2D<WeightsValueType> BSplineTransformWeightsArrayType;
00392   typedef typename BSplineTransformIndexArrayType::ValueType IndexValueType;
00393   typedef          Array2D<IndexValueType> BSplineTransformIndicesArrayType;
00394   typedef          std::vector<MovingImagePointType> MovingImagePointArrayType;
00395   typedef          std::vector<bool> BooleanArrayType;
00396 
00397   BSplineTransformWeightsArrayType      m_BSplineTransformWeightsArray;
00398   BSplineTransformIndicesArrayType      m_BSplineTransformIndicesArray;
00399   MovingImagePointArrayType             m_PreTransformPointsArray;
00400   BooleanArrayType                      m_WithinSupportRegionArray;
00401   
00402   typedef FixedArray<unsigned long, 
00403     ::itk::GetImageDimension<FixedImageType>::ImageDimension> ParametersOffsetType;
00404   ParametersOffsetType                  m_ParametersOffset;
00405 
00406   bool             m_UseAllPixels;
00407 
00408   virtual void PreComputeTransformValues();
00409 
00410   bool             m_ReseedIterator;
00411   int              m_RandomSeed;
00412   
00413 };
00414 
00415 } // end namespace itk
00416 
00417 #ifndef ITK_MANUAL_INSTANTIATION
00418 #include "itkMattesMutualInformationImageToImageMetric.txx"
00419 #endif
00420 
00421 #endif
00422 

Generated at Wed May 24 23:37:59 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000