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/01/21 23:01:50 $
00007   Version:   $Revision: 1.13 $
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 
00111 template <class TFixedImage,class TMovingImage >
00112 class ITK_EXPORT MattesMutualInformationImageToImageMetric :
00113     public ImageToImageMetric< TFixedImage, TMovingImage >
00114 {
00115 public:
00116 
00118   typedef MattesMutualInformationImageToImageMetric  Self;
00119   typedef ImageToImageMetric< TFixedImage, TMovingImage > Superclass;
00120   typedef SmartPointer<Self>  Pointer;
00121   typedef SmartPointer<const Self>  ConstPointer;
00122 
00124   itkNewMacro(Self);
00125 
00127   itkTypeMacro(MattesMutualInformationImageToImageMetric, ImageToImageMetric);
00128 
00130   typedef typename Superclass::TransformType            TransformType;
00131   typedef typename Superclass::TransformPointer         TransformPointer;
00132   typedef typename Superclass::TransformJacobianType    TransformJacobianType;
00133   typedef typename Superclass::InterpolatorType         InterpolatorType;
00134   typedef typename Superclass::MeasureType              MeasureType;
00135   typedef typename Superclass::DerivativeType           DerivativeType;
00136   typedef typename Superclass::ParametersType           ParametersType;
00137   typedef typename Superclass::FixedImageType           FixedImageType;
00138   typedef typename Superclass::MovingImageType          MovingImageType;
00139   typedef typename Superclass::FixedImageConstPointer   FixedImageConstPointer;
00140   typedef typename Superclass::MovingImageConstPointer  MovingImageCosntPointer;
00141   typedef typename Superclass::CoordinateRepresentationType
00142   CoordinateRepresentationType;
00143 
00145   typedef typename FixedImageType::IndexType            FixedImageIndexType;
00146   typedef typename FixedImageIndexType::IndexValueType  FixedImageIndexValueType;
00147   typedef typename MovingImageType::IndexType           MovingImageIndexType;
00148   typedef typename TransformType::InputPointType        FixedImagePointType;
00149   typedef typename TransformType::OutputPointType       MovingImagePointType;
00150 
00152   itkStaticConstMacro( MovingImageDimension, unsigned int,
00153                        MovingImageType::ImageDimension );
00154 
00162   virtual void Initialize(void) throw ( ExceptionObject );
00163 
00165   void GetDerivative( 
00166     const ParametersType& parameters,
00167     DerivativeType & Derivative ) const;
00168 
00170   MeasureType GetValue( const ParametersType& parameters ) const;
00171 
00173   void GetValueAndDerivative( const ParametersType& parameters, 
00174                               MeasureType& Value, DerivativeType& Derivative ) const;
00175 
00177   itkSetClampMacro( NumberOfSpatialSamples, unsigned long,
00178                     1, NumericTraits<unsigned long>::max() );
00179   itkGetConstReferenceMacro( NumberOfSpatialSamples, unsigned long); 
00180 
00182   itkSetClampMacro( NumberOfHistogramBins, unsigned long,
00183                     1, NumericTraits<unsigned long>::max() );
00184   itkGetConstReferenceMacro( NumberOfHistogramBins, unsigned long);   
00185 
00187   static void ReinitializeSeed();
00188   static void ReinitializeSeed(int);  
00189 
00190 protected:
00191 
00192   MattesMutualInformationImageToImageMetric();
00193   virtual ~MattesMutualInformationImageToImageMetric() {};
00194   void PrintSelf(std::ostream& os, Indent indent) const;
00195 
00199   class FixedImageSpatialSample
00200   {
00201   public:
00202     FixedImageSpatialSample():FixedImageValue(0.0)
00203     { FixedImagePointValue.Fill(0.0); }
00204     ~FixedImageSpatialSample() {};
00205 
00206     FixedImagePointType           FixedImagePointValue;
00207     double                        FixedImageValue;
00208     unsigned int                  FixedImageParzenWindowIndex;
00209   };
00210 
00212   typedef std::vector<FixedImageSpatialSample>  
00213   FixedImageSpatialSampleContainer;
00214 
00216   FixedImageSpatialSampleContainer    m_FixedImageSamples;
00217 
00219   virtual void SampleFixedImageDomain( 
00220     FixedImageSpatialSampleContainer& samples);
00221 
00224   virtual void TransformPoint( unsigned int sampleNumber,
00225                                const ParametersType& parameters,
00226                                MovingImagePointType& mappedPoint, bool& sampleWithinSupportRegion,
00227                                double& movingImageValue ) const;
00228 
00229 private:
00230 
00231   MattesMutualInformationImageToImageMetric(const Self&); //purposely not implemented
00232   void operator=(const Self&); //purposely not implemented
00233 
00234 
00236   typedef float PDFValueType;
00237   typedef std::vector<PDFValueType> MarginalPDFType;
00238 
00240   mutable MarginalPDFType m_FixedImageMarginalPDF;
00241 
00243   mutable MarginalPDFType m_MovingImageMarginalPDF;
00244 
00246   typedef Image<PDFValueType,2> JointPDFType;
00247   typedef Image<PDFValueType,3> JointPDFDerivativesType;
00248   typedef JointPDFType::IndexType                JointPDFIndexType;
00249   typedef JointPDFType::PixelType                JointPDFValueType;
00250   typedef JointPDFType::RegionType              JointPDFRegionType;
00251   typedef JointPDFType::SizeType                JointPDFSizeType;
00252   typedef JointPDFDerivativesType::IndexType    JointPDFDerivativesIndexType;
00253   typedef JointPDFDerivativesType::PixelType    JointPDFDerivativesValueType;
00254   typedef JointPDFDerivativesType::RegionType    JointPDFDerivativesRegionType;
00255   typedef JointPDFDerivativesType::SizeType      JointPDFDerivativesSizeType;
00256 
00258   typename JointPDFType::Pointer m_JointPDF;
00259   typename JointPDFDerivativesType::Pointer m_JointPDFDerivatives;
00260 
00261   unsigned long m_NumberOfSpatialSamples;
00262   unsigned long m_NumberOfParameters;
00263 
00265   unsigned long m_NumberOfHistogramBins;
00266   double m_MovingImageNormalizedMin;
00267   double m_FixedImageNormalizedMin;
00268   double m_MovingImageTrueMin;
00269   double m_MovingImageTrueMax;
00270   double m_FixedImageBinSize;
00271   double m_MovingImageBinSize;
00272 
00274   typedef BSplineKernelFunction<3> CubicBSplineFunctionType;
00275   typedef BSplineDerivativeKernelFunction<3> 
00276   CubicBSplineDerivativeFunctionType;
00277 
00279   typename CubicBSplineFunctionType::Pointer m_CubicBSplineKernel;
00280   typename CubicBSplineDerivativeFunctionType::Pointer 
00281   m_CubicBSplineDerivativeKernel;
00282 
00284   virtual void ComputeFixedImageParzenWindowIndices( FixedImageSpatialSampleContainer& samples );
00285 
00292   typedef CovariantVector< double,
00293                            itkGetStaticConstMacro(MovingImageDimension) > ImageDerivativesType;
00294 
00296   virtual void ComputeImageDerivatives( const MovingImagePointType& mappedPoint,
00297                                         ImageDerivativesType& gradient ) const;
00298 
00300   bool m_InterpolatorIsBSpline;
00301 
00303   typedef
00304   BSplineInterpolateImageFunction<MovingImageType,
00305                                   CoordinateRepresentationType> BSplineInterpolatorType;
00306 
00308   typename BSplineInterpolatorType::Pointer m_BSplineInterpolator;
00309 
00311   typedef CentralDifferenceImageFunction<MovingImageType,
00312                                          CoordinateRepresentationType> DerivativeFunctionType;
00313 
00315   typename DerivativeFunctionType::Pointer m_DerivativeCalculator;
00316 
00317 
00319   virtual void ComputePDFDerivatives( unsigned int sampleNumber,
00320                                       int movingImageParzenWindowIndex,
00321                                       const ImageDerivativesType& movingImageGradientValue,
00322                                       double cubicBSplineDerivativeValue ) const;
00323 
00333   bool m_TransformIsBSpline;
00334 
00336   long m_NumParametersPerDim;
00337 
00341   unsigned long m_NumBSplineWeights;
00342 
00344   itkStaticConstMacro( FixedImageDimension, unsigned int,
00345                        FixedImageType::ImageDimension );
00346 
00350   enum { DeformationSplineOrder = 3 };
00351 
00355   typedef BSplineDeformableTransform<
00356     CoordinateRepresentationType,
00357     ::itk::GetImageDimension<FixedImageType>::ImageDimension,
00358     DeformationSplineOrder> BSplineTransformType;
00359   typedef typename BSplineTransformType::WeightsType 
00360   BSplineTransformWeightsType;
00361   typedef typename BSplineTransformType::ParameterIndexArrayType 
00362   BSplineTransformIndexArrayType;
00363 
00367   typename BSplineTransformType::Pointer m_BSplineTransform;
00368 
00373   typedef typename BSplineTransformWeightsType::ValueType WeightsValueType;
00374   typedef          Array2D<WeightsValueType> BSplineTransformWeightsArrayType;
00375   typedef typename BSplineTransformIndexArrayType::ValueType IndexValueType;
00376   typedef          Array2D<IndexValueType> BSplineTransformIndicesArrayType;
00377   typedef          std::vector<MovingImagePointType> MovingImagePointArrayType;
00378   typedef          std::vector<bool> BooleanArrayType;
00379 
00380   BSplineTransformWeightsArrayType      m_BSplineTransformWeightsArray;
00381   BSplineTransformIndicesArrayType      m_BSplineTransformIndicesArray;
00382   MovingImagePointArrayType             m_PreTransformPointsArray;
00383   BooleanArrayType                      m_WithinSupportRegionArray;
00384   
00385   typedef FixedArray<unsigned long, 
00386     ::itk::GetImageDimension<FixedImageType>::ImageDimension> ParametersOffsetType;
00387   ParametersOffsetType                  m_ParametersOffset;
00388 
00389   virtual void PreComputeTransformValues();
00390 
00391   
00392 };
00393 
00394 } // end namespace itk
00395 
00396 #ifndef ITK_MANUAL_INSTANTIATION
00397 #include "itkMattesMutualInformationImageToImageMetric.txx"
00398 #endif
00399 
00400 #endif
00401 

Generated at Wed Mar 30 00:02:58 2005 for ITK by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2000