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