ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkHistogramImageToImageMetric.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkHistogramImageToImageMetric_h
00019 #define __itkHistogramImageToImageMetric_h
00020 
00021 #include "itkHistogram.h"
00022 #include "itkImageToImageMetric.h"
00023 
00024 namespace itk
00025 {
00038 template< class TFixedImage, class TMovingImage >
00039 class ITK_EXPORT HistogramImageToImageMetric:
00040   public ImageToImageMetric< TFixedImage, TMovingImage >
00041 {
00042 public:
00044   typedef HistogramImageToImageMetric                     Self;
00045   typedef ImageToImageMetric< TFixedImage, TMovingImage > Superclass;
00046   typedef SmartPointer< Self >                            Pointer;
00047   typedef SmartPointer< const Self >                      ConstPointer;
00048 
00050   itkTypeMacro(HistogramImageToImageMetric, ImageToImageMetric);
00051 
00053   typedef typename Superclass::RealType                   RealType;
00054   typedef typename Superclass::TransformType              TransformType;
00055   typedef typename Superclass::TransformPointer           TransformPointer;
00056   typedef typename Superclass::TransformParametersType    TransformParametersType;
00057   typedef typename Superclass::TransformJacobianType      TransformJacobianType;
00058   typedef typename Superclass::GradientPixelType          GradientPixelType;
00059   typedef typename Superclass::InputPointType             InputPointType;
00060   typedef typename Superclass::OutputPointType            OutputPointType;
00061   typedef typename Superclass::MeasureType                MeasureType;
00062   typedef typename Superclass::DerivativeType             DerivativeType;
00063   typedef typename Superclass::FixedImageType             FixedImageType;
00064   typedef typename Superclass::FixedImageType::PixelType  FixedImagePixelType;
00065   typedef typename Superclass::MovingImageType            MovingImageType;
00066   typedef typename Superclass::MovingImageType::PixelType MovingImagePixelType;
00067   typedef typename Superclass::FixedImageConstPointer
00068   FixedImageConstPointerType;
00069   typedef typename Superclass::MovingImageConstPointer
00070   MovingImageConstPointerType;
00071 
00075   typedef Statistics::Histogram< double > HistogramType;
00076 
00077   typedef typename HistogramType::MeasurementVectorType MeasurementVectorType;
00078   typedef typename HistogramType::SizeType              HistogramSizeType;
00079   typedef typename HistogramType::Pointer               HistogramPointer;
00080 
00082   void Initialize()
00083   throw ( ExceptionObject );
00084 
00087   void SetTransform(TransformType *transform);
00088 
00091   itkSetMacro(HistogramSize, HistogramSizeType);
00092 
00094   itkGetConstReferenceMacro(HistogramSize, HistogramSizeType);
00095 
00098   itkSetMacro(UpperBoundIncreaseFactor, double);
00099   itkGetConstMacro(UpperBoundIncreaseFactor, double);
00101 
00103   itkSetMacro(PaddingValue, FixedImagePixelType);
00104 
00106   itkGetConstReferenceMacro(PaddingValue, FixedImagePixelType);
00107 
00111   itkGetConstReferenceMacro(Histogram, HistogramPointer);
00112 
00116   itkSetMacro(UsePaddingValue, bool);
00117   itkGetConstMacro(UsePaddingValue, bool);
00119 
00121   itkSetMacro(DerivativeStepLength, double);
00122 
00124   itkGetConstMacro(DerivativeStepLength, double);
00125 
00127   typedef Array< double > ScalesType;
00128 
00130   itkSetMacro(DerivativeStepLengthScales, ScalesType);
00131 
00133   itkGetConstReferenceMacro(DerivativeStepLengthScales, ScalesType);
00134 
00136   MeasureType GetValue(const TransformParametersType & parameters) const;
00137 
00139   void GetDerivative(const TransformParametersType & parameters,
00140                      DerivativeType & derivative) const;
00141 
00143   void GetValueAndDerivative(const TransformParametersType & parameters,
00144                              MeasureType & Value,
00145                              DerivativeType & Derivative) const;
00146 
00150   void SetLowerBound(const MeasurementVectorType & bound);
00151 
00155   void SetUpperBound(const MeasurementVectorType & bound);
00156 
00157 protected:
00160   HistogramImageToImageMetric();
00161   virtual ~HistogramImageToImageMetric() {}
00162 
00164   HistogramSizeType m_HistogramSize;
00165 
00167   mutable MeasurementVectorType m_LowerBound;
00168 
00170   mutable MeasurementVectorType m_UpperBound;
00171 
00173   double m_UpperBoundIncreaseFactor;
00174 
00177   bool m_LowerBoundSetByUser;
00178 
00181   bool m_UpperBoundSetByUser;
00182 
00185   void ComputeHistogram(const TransformParametersType & parameters,
00186                         HistogramType & histogram) const;
00187 
00190   void ComputeHistogram(const TransformParametersType & parameters,
00191                         unsigned int parameter,
00192                         double step,
00193                         HistogramType & histogram) const;
00194 
00196   void CopyHistogram(HistogramType & target, HistogramType & source) const;
00197 
00200   virtual MeasureType EvaluateMeasure(HistogramType & histogram) const = 0;
00201 
00203   void PrintSelf(std::ostream & os, Indent indent) const;
00204 
00205 private:
00206   HistogramImageToImageMetric(const Self &); //purposely not implemented
00207   void operator=(const Self &);              //purposely not implemented
00208 
00210   FixedImagePixelType m_PaddingValue;
00211 
00215   bool m_UsePaddingValue;
00216 
00218   double m_DerivativeStepLength;
00219 
00221   ScalesType m_DerivativeStepLengthScales;
00222 
00225   HistogramPointer m_Histogram;
00226 };
00227 } // end namespace itk
00228 
00229 #ifndef ITK_MANUAL_INSTANTIATION
00230 #include "itkHistogramImageToImageMetric.hxx"
00231 #endif
00232 
00233 #endif // __itkHistogramImageToImageMetric_h
00234