go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkParzenWindowHistogramImageToImageMetric.h
Go to the documentation of this file.
00001 /*======================================================================
00002 
00003   This file is part of the elastix software.
00004 
00005   Copyright (c) University Medical Center Utrecht. All rights reserved.
00006   See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php for
00007   details.
00008 
00009      This software is distributed WITHOUT ANY WARRANTY; without even
00010      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00011      PURPOSE. See the above copyright notices for more information.
00012 
00013 ======================================================================*/
00014 
00015 #ifndef __itkParzenWindowHistogramImageToImageMetric_H__
00016 #define __itkParzenWindowHistogramImageToImageMetric_H__
00017 
00018 #include "itkAdvancedImageToImageMetric.h"
00019 #include "itkBSplineKernelFunction.h"
00020 
00021 
00022 namespace itk
00023 {
00024 
00071   template <class TFixedImage,class TMovingImage >
00072     class ParzenWindowHistogramImageToImageMetric :
00073   public AdvancedImageToImageMetric< TFixedImage, TMovingImage >
00074   {
00075   public:
00076 
00078     typedef ParzenWindowHistogramImageToImageMetric                     Self;
00079     typedef AdvancedImageToImageMetric< TFixedImage, TMovingImage >     Superclass;
00080     typedef SmartPointer<Self>                                          Pointer;
00081     typedef SmartPointer<const Self>                                    ConstPointer;
00082 
00084     itkTypeMacro( ParzenWindowHistogramImageToImageMetric, AdvancedImageToImageMetric );
00085 
00087     typedef typename
00088       Superclass::CoordinateRepresentationType              CoordinateRepresentationType;
00089     typedef typename Superclass::MovingImageType            MovingImageType;
00090     typedef typename Superclass::MovingImagePixelType       MovingImagePixelType;
00091     typedef typename Superclass::MovingImageConstPointer    MovingImageConstPointer;
00092     typedef typename Superclass::FixedImageType             FixedImageType;
00093     typedef typename Superclass::FixedImageConstPointer     FixedImageConstPointer;
00094     typedef typename Superclass::FixedImageRegionType       FixedImageRegionType;
00095     typedef typename Superclass::TransformType              TransformType;
00096     typedef typename Superclass::TransformPointer           TransformPointer;
00097     typedef typename Superclass::InputPointType             InputPointType;
00098     typedef typename Superclass::OutputPointType            OutputPointType;
00099     typedef typename Superclass::TransformParametersType    TransformParametersType;
00100     typedef typename Superclass::TransformJacobianType      TransformJacobianType;
00101     typedef typename Superclass::InterpolatorType           InterpolatorType;
00102     typedef typename Superclass::InterpolatorPointer        InterpolatorPointer;
00103     typedef typename Superclass::RealType                   RealType;
00104     typedef typename Superclass::GradientPixelType          GradientPixelType;
00105     typedef typename Superclass::GradientImageType          GradientImageType;
00106     typedef typename Superclass::GradientImagePointer       GradientImagePointer;
00107     typedef typename Superclass::GradientImageFilterType    GradientImageFilterType;
00108     typedef typename Superclass::GradientImageFilterPointer GradientImageFilterPointer;
00109     typedef typename Superclass::FixedImageMaskType         FixedImageMaskType;
00110     typedef typename Superclass::FixedImageMaskPointer      FixedImageMaskPointer;
00111     typedef typename Superclass::MovingImageMaskType        MovingImageMaskType;
00112     typedef typename Superclass::MovingImageMaskPointer     MovingImageMaskPointer;
00113     typedef typename Superclass::MeasureType                MeasureType;
00114     typedef typename Superclass::DerivativeType             DerivativeType;
00115     typedef typename Superclass::DerivativeValueType        DerivativeValueType;
00116     typedef typename Superclass::ParametersType             ParametersType;
00117     typedef typename Superclass::FixedImagePixelType        FixedImagePixelType;
00118     typedef typename Superclass::MovingImageRegionType      MovingImageRegionType;
00119     typedef typename Superclass::ImageSamplerType           ImageSamplerType;
00120     typedef typename Superclass::ImageSamplerPointer        ImageSamplerPointer;
00121     typedef typename Superclass::ImageSampleContainerType   ImageSampleContainerType;
00122     typedef typename
00123       Superclass::ImageSampleContainerPointer               ImageSampleContainerPointer;
00124     typedef typename Superclass::FixedImageLimiterType      FixedImageLimiterType;
00125     typedef typename Superclass::MovingImageLimiterType     MovingImageLimiterType;
00126     typedef typename
00127       Superclass::FixedImageLimiterOutputType               FixedImageLimiterOutputType;
00128     typedef typename
00129       Superclass::MovingImageLimiterOutputType              MovingImageLimiterOutputType;
00130     typedef typename
00131       Superclass::MovingImageDerivativeScalesType           MovingImageDerivativeScalesType;
00132 
00134     itkStaticConstMacro( FixedImageDimension, unsigned int,
00135       FixedImageType::ImageDimension );
00136 
00138     itkStaticConstMacro( MovingImageDimension, unsigned int,
00139       MovingImageType::ImageDimension );
00140 
00147     void Initialize(void) throw ( ExceptionObject );
00148 
00153     void GetDerivative(
00154       const ParametersType& parameters,
00155       DerivativeType & Derivative ) const;
00156 
00162     void GetValueAndDerivative( const ParametersType& parameters,
00163       MeasureType& value, DerivativeType& derivative ) const;
00164 
00171     itkSetClampMacro( NumberOfFixedHistogramBins, unsigned long,
00172       4, NumericTraits<unsigned long>::max() );
00173     itkGetMacro( NumberOfFixedHistogramBins, unsigned long);
00174 
00181     itkSetClampMacro( NumberOfMovingHistogramBins, unsigned long,
00182       4, NumericTraits<unsigned long>::max() );
00183     itkGetMacro( NumberOfMovingHistogramBins, unsigned long);
00184 
00186     itkSetClampMacro( FixedKernelBSplineOrder, unsigned int, 0, 3 );
00187     itkGetConstMacro( FixedKernelBSplineOrder, unsigned int );
00188 
00190     itkSetClampMacro( MovingKernelBSplineOrder, unsigned int, 0, 3 );
00191     itkGetConstMacro( MovingKernelBSplineOrder, unsigned int );
00192 
00196     itkSetMacro( UseExplicitPDFDerivatives, bool );
00197     itkGetConstReferenceMacro( UseExplicitPDFDerivatives, bool );
00198     itkBooleanMacro( UseExplicitPDFDerivatives );
00199 
00203     itkSetMacro( UseDerivative, bool );
00204     itkGetConstMacro( UseDerivative, bool );
00205 
00209     itkSetMacro( UseFiniteDifferenceDerivative, bool );
00210     itkGetConstMacro( UseFiniteDifferenceDerivative, bool );
00211 
00216     itkSetMacro( FiniteDifferencePerturbation, double );
00217     itkGetConstMacro( FiniteDifferencePerturbation, double );
00218 
00219   protected:
00220 
00222     ParzenWindowHistogramImageToImageMetric();
00223 
00225     virtual ~ParzenWindowHistogramImageToImageMetric() {};
00226 
00228     void PrintSelf( std::ostream& os, Indent indent ) const;
00229 
00233     typedef typename Superclass::FixedImageIndexType                FixedImageIndexType;
00234     typedef typename Superclass::FixedImageIndexValueType           FixedImageIndexValueType;
00235     typedef typename FixedImageType::OffsetValueType                OffsetValueType;
00236     typedef typename Superclass::MovingImageIndexType               MovingImageIndexType;
00237     typedef typename Superclass::FixedImagePointType                FixedImagePointType;
00238     typedef typename Superclass::MovingImagePointType               MovingImagePointType;
00239     typedef typename Superclass::MovingImageContinuousIndexType     MovingImageContinuousIndexType;
00240     typedef typename Superclass::BSplineInterpolatorType            BSplineInterpolatorType;
00241     typedef typename Superclass::MovingImageDerivativeType          MovingImageDerivativeType;
00242     typedef typename Superclass::CentralDifferenceGradientFilterType CentralDifferenceGradientFilterType;
00243     typedef typename Superclass::NonZeroJacobianIndicesType         NonZeroJacobianIndicesType;
00244 
00246     typedef float                                   PDFValueType;
00247     typedef Array<PDFValueType>                     MarginalPDFType;
00248     typedef Image<PDFValueType,2>                   JointPDFType;
00249     typedef Image<PDFValueType,3>                   JointPDFDerivativesType;
00250     typedef Image<PDFValueType,2>                   IncrementalMarginalPDFType;
00251     typedef JointPDFType::IndexType                 JointPDFIndexType;
00252     typedef JointPDFType::RegionType                JointPDFRegionType;
00253     typedef JointPDFType::SizeType                  JointPDFSizeType;
00254     typedef JointPDFDerivativesType::IndexType      JointPDFDerivativesIndexType;
00255     typedef JointPDFDerivativesType::RegionType     JointPDFDerivativesRegionType;
00256     typedef JointPDFDerivativesType::SizeType       JointPDFDerivativesSizeType;
00257     typedef IncrementalMarginalPDFType::IndexType   IncrementalMarginalPDFIndexType;
00258     typedef IncrementalMarginalPDFType::RegionType  IncrementalMarginalPDFRegionType;
00259     typedef IncrementalMarginalPDFType::SizeType    IncrementalMarginalPDFSizeType;
00260     typedef Array<double>                           ParzenValueContainerType;
00261 
00263     typedef KernelFunction KernelFunctionType;
00264 
00268     mutable double                                m_Alpha;
00269     mutable DerivativeType                        m_PerturbedAlphaRight;
00270     mutable DerivativeType                        m_PerturbedAlphaLeft;
00271 
00273     mutable MarginalPDFType                       m_FixedImageMarginalPDF;
00274     mutable MarginalPDFType                       m_MovingImageMarginalPDF;
00275     typename JointPDFType::Pointer                m_JointPDF;
00276     typename JointPDFDerivativesType::Pointer     m_JointPDFDerivatives;
00277     typename JointPDFDerivativesType::Pointer     m_IncrementalJointPDFRight;
00278     typename JointPDFDerivativesType::Pointer     m_IncrementalJointPDFLeft;
00279     typename IncrementalMarginalPDFType::Pointer  m_FixedIncrementalMarginalPDFRight;
00280     typename IncrementalMarginalPDFType::Pointer  m_MovingIncrementalMarginalPDFRight;
00281     typename IncrementalMarginalPDFType::Pointer  m_FixedIncrementalMarginalPDFLeft;
00282     typename IncrementalMarginalPDFType::Pointer  m_MovingIncrementalMarginalPDFLeft;
00283     mutable JointPDFRegionType                    m_JointPDFWindow;
00284     double m_MovingImageNormalizedMin;
00285     double m_FixedImageNormalizedMin;
00286     double m_FixedImageBinSize;
00287     double m_MovingImageBinSize;
00288     double m_FixedParzenTermToIndexOffset;
00289     double m_MovingParzenTermToIndexOffset;
00290 
00292     typename KernelFunctionType::Pointer m_FixedKernel;
00293     typename KernelFunctionType::Pointer m_MovingKernel;
00294     typename KernelFunctionType::Pointer m_DerivativeMovingKernel;
00295 
00300     void EvaluateTransformJacobianInnerProduct(
00301       const TransformJacobianType & jacobian,
00302       const MovingImageDerivativeType & movingImageDerivative,
00303       DerivativeType & imageJacobian ) const;
00304 
00311     void EvaluateParzenValues(
00312       double parzenWindowTerm, OffsetValueType parzenWindowIndex,
00313       const KernelFunctionType * kernel, ParzenValueContainerType & parzenValues ) const;
00314 
00318     virtual void UpdateJointPDFAndDerivatives(
00319       RealType fixedImageValue, RealType movingImageValue,
00320       const DerivativeType * imageJacobian, const NonZeroJacobianIndicesType * nzji ) const;
00321 
00332     virtual void UpdateJointPDFAndIncrementalPDFs(
00333       RealType fixedImageValue, RealType movingImageValue, RealType movingMaskValue,
00334       const DerivativeType & movingImageValuesRight,
00335       const DerivativeType & movingImageValuesLeft,
00336       const DerivativeType & movingMaskValuesRight,
00337       const DerivativeType & movingMaskValuesLeft,
00338       const NonZeroJacobianIndicesType & nzji ) const;
00339 
00345     void UpdateJointPDFDerivatives(
00346       const JointPDFIndexType & pdfIndex, double factor,
00347       const DerivativeType & imageJacobian,
00348       const NonZeroJacobianIndicesType & nzji ) const;
00349 
00351     virtual void NormalizeJointPDF(
00352       JointPDFType * pdf, double factor ) const;
00353 
00355     virtual void NormalizeJointPDFDerivatives(
00356       JointPDFDerivativesType * pdf, double factor ) const;
00357 
00362     virtual void ComputeMarginalPDF(
00363       const JointPDFType * jointPDF,
00364       MarginalPDFType & marginalPDF,
00365       unsigned int direction ) const;
00366 
00370     virtual void ComputeIncrementalMarginalPDFs(
00371       const JointPDFDerivativesType * incrementalPDF,
00372       IncrementalMarginalPDFType * fixedIncrementalMarginalPDF,
00373       IncrementalMarginalPDFType * movingIncrementalMarginalPDF ) const;
00374 
00384     virtual void ComputePDFsAndPDFDerivatives( const ParametersType & parameters ) const;
00385 
00409     virtual void ComputePDFsAndIncrementalPDFs( const ParametersType & parameters ) const;
00410 
00419     virtual void ComputePDFs( const ParametersType & parameters ) const;
00420 
00422     virtual void InitializeHistograms( void );
00423     virtual void InitializeKernels( void );
00424 
00429     virtual void GetValueAndAnalyticDerivative(
00430       const ParametersType & itkNotUsed( parameters ),
00431       MeasureType & itkNotUsed( value ),
00432       DerivativeType & itkNotUsed( derivative ) ) const {};
00433 
00438     virtual void GetValueAndFiniteDifferenceDerivative(
00439       const ParametersType & itkNotUsed( parameters ),
00440       MeasureType & itkNotUsed( value ),
00441       DerivativeType & itkNotUsed( derivative ) ) const {};
00442 
00443   private:
00444 
00446     ParzenWindowHistogramImageToImageMetric( const Self& ); // purposely not implemented
00448     void operator=( const Self& );                          // purposely not implemented
00449 
00451     unsigned long m_NumberOfFixedHistogramBins;
00452     unsigned long m_NumberOfMovingHistogramBins;
00453     unsigned int m_FixedKernelBSplineOrder;
00454     unsigned int m_MovingKernelBSplineOrder;
00455     bool m_UseDerivative;
00456     bool m_UseFiniteDifferenceDerivative;
00457     double m_FiniteDifferencePerturbation;
00458 
00459     bool m_UseExplicitPDFDerivatives;
00460 
00461   }; // end class ParzenWindowHistogramImageToImageMetric
00462 
00463 } // end namespace itk
00464 
00465 #ifndef ITK_MANUAL_INSTANTIATION
00466 #include "itkParzenWindowHistogramImageToImageMetric.hxx"
00467 #endif
00468 
00469 #endif // end #ifndef __itkParzenWindowHistogramImageToImageMetric_H__
00470 


Generated on 11-05-2012 for elastix by doxygen 1.7.6.1 elastix logo