1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
19 #ifndef __clitkCorrelationRatioImageToImageMetric_h
20 #define __clitkCorrelationRatioImageToImageMetric_h
23 * @file clitkCorrelationRatioImageToImageMetric.h
24 * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
25 * @date July 30 18:14:53 2007
27 * @brief Compute the correlation ratio between 2 images
32 /* This computes the correlation ratio between 2 images
34 * This class is templated over the FixedImage type and the MovingImage
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
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.
50 * The calculations are based on the method of Alexis Roche.
52 * The number of intensity bins used can be set through the SetNumberOfBins() method
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.
59 #include "itkImageToImageMetric.h"
60 #include "itkCovariantVector.h"
67 template < class TFixedImage, class TMovingImage >
68 class ITK_EXPORT CorrelationRatioImageToImageMetric:
69 public ImageToImageMetric< TFixedImage, TMovingImage>
73 /** Standard class typedefs. */
74 typedef CorrelationRatioImageToImageMetric Self;
75 typedef ImageToImageMetric<TFixedImage, TMovingImage > Superclass;
77 typedef SmartPointer<Self> Pointer;
78 typedef SmartPointer<const Self> ConstPointer;
80 /** Method for creation through the object factory. */
83 /** Run-time type information (and related methods). */
84 itkTypeMacro(CorrelationRatioImageToImageMetric, ImageToImageMetric);
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;
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;
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;
111 virtual void Initialize(void) throw ( ExceptionObject ) ITK_OVERRIDE;
114 /** Get the derivatives of the match measure. */
115 void GetDerivative( const TransformParametersType & parameters,
116 DerivativeType & derivative ) const ITK_OVERRIDE;
118 /** Get the value for single valued optimizers. */
119 MeasureType GetValue( const TransformParametersType & parameters ) const ITK_OVERRIDE;
121 /** Get value and derivatives for multiple valued optimizers. */
122 void GetValueAndDerivative( const TransformParametersType & parameters,
123 MeasureType& Value, DerivativeType& Derivative ) const ITK_OVERRIDE;
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);
131 CorrelationRatioImageToImageMetric();
132 virtual ~CorrelationRatioImageToImageMetric() {};
135 CorrelationRatioImageToImageMetric(const Self&); //purposely not implemented
136 void operator=(const Self&); //purposely not implemented
139 //the min and max in the fixed image intensity range
140 double m_FixedImageMin;
142 //The bin size in intensity
143 double m_FixedImageBinSize;
145 //The number of pixels in the fixed image bins are stored in a vector
146 mutable std::vector<unsigned long> m_NumberOfPixelsCountedPerBin;
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;
158 } // end namespace itk
160 #ifndef ITK_MANUAL_INSTANTIATION
161 #include "clitkCorrelationRatioImageToImageMetric.txx"