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