]> Creatis software - clitk.git/blob - registration/clitkCorrelationRatioImageToImageMetric.h
Ensure compatibility with ITK < 4.12 for throw exception
[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 #if ( ( ITK_VERSION_MAJOR == 4 ) && ( ITK_VERSION_MINOR > 12 ) || ( ITK_VERSION_MAJOR > 4 ))
109   virtual void Initialize(void) ITK_OVERRIDE;
110 #else
111   virtual void Initialize(void) throw ( ExceptionObject ) ITK_OVERRIDE;
112 #endif
113
114   /** Get the derivatives of the match measure. */
115   void GetDerivative( const TransformParametersType & parameters,
116                       DerivativeType & derivative ) const ITK_OVERRIDE;
117
118   /**  Get the value for single valued optimizers. */
119   MeasureType GetValue( const TransformParametersType & parameters ) const ITK_OVERRIDE;
120
121   /**  Get value and derivatives for multiple valued optimizers. */
122   void GetValueAndDerivative( const TransformParametersType & parameters,
123                               MeasureType& Value, DerivativeType& Derivative ) const ITK_OVERRIDE;
124
125   /** Number of bins to used in the calculation. Typical value is 50. */
126   itkSetClampMacro( NumberOfBins, unsigned long,
127                     1, NumericTraits<unsigned long>::max() );
128   itkGetConstReferenceMacro( NumberOfBins, unsigned long);
129
130 protected:
131   CorrelationRatioImageToImageMetric();
132   virtual ~CorrelationRatioImageToImageMetric() {};
133
134 private:
135   CorrelationRatioImageToImageMetric(const Self&); //purposely not implemented
136   void operator=(const Self&); //purposely not implemented
137
138
139   //the min and max in the fixed image intensity range
140   double m_FixedImageMin;
141
142   //The bin size in intensity
143   double m_FixedImageBinSize;
144
145   //The number of pixels in the fixed image bins are stored in a vector
146   mutable std::vector<unsigned long> m_NumberOfPixelsCountedPerBin;
147
148   //The mMSVPB and the mSMVPB are stored in vectors of realtype
149   typedef float ValueType;
150   typedef std::vector<ValueType> MeasurePerBinType;
151   mutable MeasurePerBinType m_mMSVPB;
152   mutable MeasurePerBinType m_mSMVPB;
153   unsigned long m_NumberOfBins;
154
155
156 };
157
158 } // end namespace itk
159
160 #ifndef ITK_MANUAL_INSTANTIATION
161 #include "clitkCorrelationRatioImageToImageMetric.txx"
162 #endif
163
164 #endif
165
166
167