]> Creatis software - clitk.git/blob - tools/clitkCorrelationRatioImageToImageMetric.h
Initial revision
[clitk.git] / tools / clitkCorrelationRatioImageToImageMetric.h
1
2 /*=========================================================================
3                                                                                 
4   Program:   clitk
5   Module:    $RCSfile: clitkCorrelationRatioImageToImageMetric.h
6   Language:  C++
7   Date:      $Date: 2010/01/06 13:31:56 $
8   Version:   $Revision: 1.1 $
9                                                                                 
10   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
11   l'Image). All rights reserved. See Doc/License.txt or
12   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13                                                                                 
14      This software is distributed WITHOUT ANY WARRANTY; without even
15      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16      PURPOSE.  See the above copyright notices for more information.
17                                                                              
18 =========================================================================*/
19
20
21 #ifndef __clitkCorrelationRatioImageToImageMetric_h
22 #define __clitkCorrelationRatioImageToImageMetric_h
23
24 /**
25  * @file   clitkCorrelationRatioImageToImageMetric.h
26  * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
27  * @date   July 30  18:14:53 2007
28  * 
29  * @brief  Compute the correlation ratio between 2 images
30  * 
31  * 
32  */
33
34 /* This computes the correlation ratio between 2 images
35  *
36  * This class is templated over the FixedImage type and the MovingImage 
37  * type.
38  *
39  * The fixed and moving images are set via methods SetFixedImage() and
40  * SetMovingImage(). This metric makes use of user specified Transform and
41  * Interpolator. The Transform is used to map points from the fixed image to
42  * the moving image domain. The Interpolator is used to evaluate the image
43  * intensity at user specified geometric points in the moving image.
44  * The Transform and Interpolator are set via methods SetTransform() and
45  * SetInterpolator().
46  *
47  * The method GetValue() computes of the mutual information
48  * while method GetValueAndDerivative() computes
49  * both the mutual information and its derivatives with respect to the
50  * transform parameters.
51  *
52  * The calculations are based on the method of Alexis Roche.
53  *
54  * The number of intensity bins used can be set through the SetNumberOfBins() method
55  *
56  * On Initialize(), we find the min and max intensities in the fixed image and compute the width of 
57  * the intensity bins. The data structures which hold the bins and related measures are initialised.
58  */
59
60
61 #include "itkImageToImageMetric.h"
62 #include "itkCovariantVector.h"
63 #include "itkPoint.h"
64
65 using namespace itk;
66 namespace clitk
67 {
68
69 template < class TFixedImage, class TMovingImage > 
70 class ITK_EXPORT CorrelationRatioImageToImageMetric: 
71     public ImageToImageMetric< TFixedImage, TMovingImage>
72 {
73 public:
74
75   /** Standard class typedefs. */
76   typedef CorrelationRatioImageToImageMetric   Self;
77   typedef ImageToImageMetric<TFixedImage, TMovingImage >  Superclass;
78
79   typedef SmartPointer<Self>         Pointer;
80   typedef SmartPointer<const Self>   ConstPointer;
81
82   /** Method for creation through the object factory. */
83   itkNewMacro(Self);
84  
85   /** Run-time type information (and related methods). */
86   itkTypeMacro(CorrelationRatioImageToImageMetric, ImageToImageMetric);
87
88  
89   /** Types transferred from the base class */
90   typedef typename Superclass::RealType                 RealType;
91   typedef typename Superclass::TransformType            TransformType;
92   typedef typename Superclass::TransformPointer         TransformPointer;
93   typedef typename Superclass::TransformParametersType  TransformParametersType;
94   typedef typename Superclass::TransformJacobianType    TransformJacobianType;
95   typedef typename Superclass::GradientPixelType        GradientPixelType;
96
97   typedef typename Superclass::MeasureType              MeasureType;
98   typedef typename Superclass::DerivativeType           DerivativeType;
99   typedef typename Superclass::FixedImageType           FixedImageType;
100   typedef typename Superclass::MovingImageType          MovingImageType;
101   typedef typename Superclass::FixedImageConstPointer   FixedImageConstPointer;
102   typedef typename Superclass::MovingImageConstPointer  MovingImageConstPointer;
103
104
105  /** 
106    *  Initialize the Metric by 
107    *  (1) making sure that all the components are present and plugged 
108    *      together correctly,
109    *  (3) allocate memory for bin data structures. */
110   virtual void Initialize(void) throw ( ExceptionObject );
111
112   /** Get the derivatives of the match measure. */
113   void GetDerivative( const TransformParametersType & parameters,
114                       DerivativeType & derivative ) const;
115
116   /**  Get the value for single valued optimizers. */
117   MeasureType GetValue( const TransformParametersType & parameters ) const;
118
119   /**  Get value and derivatives for multiple valued optimizers. */
120   void GetValueAndDerivative( const TransformParametersType & parameters,
121                               MeasureType& Value, DerivativeType& Derivative ) const;
122
123  /** Number of bins to used in the calculation. Typical value is 50. */
124   itkSetClampMacro( NumberOfBins, unsigned long,
125                     1, NumericTraits<unsigned long>::max() );
126   itkGetConstReferenceMacro( NumberOfBins, unsigned long);   
127
128 protected:
129   CorrelationRatioImageToImageMetric();
130   virtual ~CorrelationRatioImageToImageMetric() {};
131
132 private:
133   CorrelationRatioImageToImageMetric(const Self&); //purposely not implemented
134   void operator=(const Self&); //purposely not implemented
135
136
137   //the min and max in the fixed image intensity range
138   double m_FixedImageMin;
139
140   //The bin size in intensity
141   double m_FixedImageBinSize;
142
143   //The number of pixels in the fixed image bins are stored in a vector
144    mutable std::vector<unsigned long> m_NumberOfPixelsCountedPerBin;
145
146   //The mMSVPB and the mSMVPB are stored in vectors of realtype
147   typedef float ValueType;
148   typedef std::vector<ValueType> MeasurePerBinType;
149   mutable MeasurePerBinType m_mMSVPB;
150   mutable MeasurePerBinType m_mSMVPB;
151   unsigned long m_NumberOfBins;
152
153
154 };
155
156 } // end namespace itk
157
158 #ifndef ITK_MANUAL_INSTANTIATION
159 #include "clitkCorrelationRatioImageToImageMetric.txx"
160 #endif
161
162 #endif
163
164
165