2 /*=========================================================================
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.
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.
15 =========================================================================*/
18 #ifndef __clitkCorrelationRatioImageToImageMetric_h
19 #define __clitkCorrelationRatioImageToImageMetric_h
22 * @file clitkCorrelationRatioImageToImageMetric.h
23 * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
24 * @date July 30 18:14:53 2007
26 * @brief Compute the correlation ratio between 2 images
31 /* This computes the correlation ratio between 2 images
33 * This class is templated over the FixedImage type and the MovingImage
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
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.
49 * The calculations are based on the method of Alexis Roche.
51 * The number of intensity bins used can be set through the SetNumberOfBins() method
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.
58 #include "itkImageToImageMetric.h"
59 #include "itkCovariantVector.h"
66 template < class TFixedImage, class TMovingImage >
67 class ITK_EXPORT CorrelationRatioImageToImageMetric:
68 public ImageToImageMetric< TFixedImage, TMovingImage>
72 /** Standard class typedefs. */
73 typedef CorrelationRatioImageToImageMetric Self;
74 typedef ImageToImageMetric<TFixedImage, TMovingImage > Superclass;
76 typedef SmartPointer<Self> Pointer;
77 typedef SmartPointer<const Self> ConstPointer;
79 /** Method for creation through the object factory. */
82 /** Run-time type information (and related methods). */
83 itkTypeMacro(CorrelationRatioImageToImageMetric, ImageToImageMetric);
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;
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;
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 );
109 /** Get the derivatives of the match measure. */
110 void GetDerivative( const TransformParametersType & parameters,
111 DerivativeType & derivative ) const;
113 /** Get the value for single valued optimizers. */
114 MeasureType GetValue( const TransformParametersType & parameters ) const;
116 /** Get value and derivatives for multiple valued optimizers. */
117 void GetValueAndDerivative( const TransformParametersType & parameters,
118 MeasureType& Value, DerivativeType& Derivative ) const;
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);
126 CorrelationRatioImageToImageMetric();
127 virtual ~CorrelationRatioImageToImageMetric() {};
130 CorrelationRatioImageToImageMetric(const Self&); //purposely not implemented
131 void operator=(const Self&); //purposely not implemented
134 //the min and max in the fixed image intensity range
135 double m_FixedImageMin;
137 //The bin size in intensity
138 double m_FixedImageBinSize;
140 //The number of pixels in the fixed image bins are stored in a vector
141 mutable std::vector<unsigned long> m_NumberOfPixelsCountedPerBin;
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;
153 } // end namespace itk
155 #ifndef ITK_MANUAL_INSTANTIATION
156 #include "clitkCorrelationRatioImageToImageMetric.txx"