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