ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkMutualInformationImageToImageMetric.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 __itkMutualInformationImageToImageMetric_h
00019 #define __itkMutualInformationImageToImageMetric_h
00020 
00021 #include "itkImageToImageMetric.h"
00022 #include "itkPoint.h"
00023 
00024 #include "itkIndex.h"
00025 #include "itkKernelFunctionBase.h"
00026 
00027 namespace itk
00028 {
00093 template< class TFixedImage, class TMovingImage >
00094 class ITK_EXPORT MutualInformationImageToImageMetric:
00095   public ImageToImageMetric< TFixedImage, TMovingImage >
00096 {
00097 public:
00098 
00100   typedef MutualInformationImageToImageMetric             Self;
00101   typedef ImageToImageMetric< TFixedImage, TMovingImage > Superclass;
00102   typedef SmartPointer< Self >                            Pointer;
00103   typedef SmartPointer< const Self >                      ConstPointer;
00104 
00106   itkNewMacro(Self);
00107 
00109   itkTypeMacro(MutualInformationImageToImageMetric, ImageToImageMetric);
00110 
00112   typedef typename Superclass::TransformType           TransformType;
00113   typedef typename Superclass::TransformPointer        TransformPointer;
00114   typedef typename Superclass::TransformJacobianType   TransformJacobianType;
00115   typedef typename Superclass::InterpolatorType        InterpolatorType;
00116   typedef typename Superclass::MeasureType             MeasureType;
00117   typedef typename Superclass::DerivativeType          DerivativeType;
00118   typedef typename Superclass::ParametersType          ParametersType;
00119   typedef typename Superclass::FixedImageType          FixedImageType;
00120   typedef typename Superclass::MovingImageType         MovingImageType;
00121   typedef typename Superclass::FixedImageConstPointer  FixedImageConstPointer;
00122   typedef typename Superclass::MovingImageConstPointer MovingImageCosntPointer;
00123 
00125   typedef typename FixedImageType::IndexType           FixedImageIndexType;
00126   typedef typename FixedImageIndexType::IndexValueType FixedImageIndexValueType;
00127   typedef typename MovingImageType::IndexType          MovingImageIndexType;
00128   typedef typename TransformType::InputPointType       FixedImagePointType;
00129   typedef typename TransformType::OutputPointType      MovingImagePointType;
00130 
00131   typedef KernelFunctionBase<double>                       KernelFunctionType;
00132 
00134   itkStaticConstMacro(MovingImageDimension, unsigned int,
00135                       MovingImageType::ImageDimension);
00136 
00138   void GetDerivative(
00139     const ParametersType & parameters,
00140     DerivativeType & Derivative) const;
00141 
00143   MeasureType GetValue(const ParametersType & parameters) const;
00144 
00146   void GetValueAndDerivative(const ParametersType & parameters,
00147                              MeasureType & Value, DerivativeType & Derivative) const;
00148 
00153   void SetNumberOfSpatialSamples(unsigned int num);
00154 
00156   itkGetConstReferenceMacro(NumberOfSpatialSamples, unsigned int);
00157 
00163   itkSetClampMacro( MovingImageStandardDeviation, double,
00164                     NumericTraits< double >::NonpositiveMin(), NumericTraits< double >::max() );
00165   itkGetConstReferenceMacro(MovingImageStandardDeviation, double);
00167 
00173   itkSetClampMacro( FixedImageStandardDeviation, double,
00174                     NumericTraits< double >::NonpositiveMin(), NumericTraits< double >::max() );
00175   itkGetConstMacro(FixedImageStandardDeviation, double);
00177 
00180   itkSetObjectMacro(KernelFunction, KernelFunctionType);
00181   itkGetObjectMacro(KernelFunction, KernelFunctionType);
00183 
00193   void ReinitializeSeed();
00194 
00195   void ReinitializeSeed(int);
00196 
00197 protected:
00198   MutualInformationImageToImageMetric();
00199   virtual ~MutualInformationImageToImageMetric() {}
00200   void PrintSelf(std::ostream & os, Indent indent) const;
00201 
00202 private:
00203   MutualInformationImageToImageMetric(const Self &); //purposely not implemented
00204   void operator=(const Self &);                      //purposely not implemented
00205 
00211   class SpatialSample
00212   {
00213 public:
00214     SpatialSample():FixedImageValue(0.0), MovingImageValue(0.0)
00215     { FixedImagePointValue.Fill(0.0); }
00216     ~SpatialSample(){}
00217 
00218     FixedImagePointType FixedImagePointValue;
00219     double              FixedImageValue;
00220     double              MovingImageValue;
00221   };
00222 
00224   typedef std::vector< SpatialSample > SpatialSampleContainer;
00225 
00228   mutable SpatialSampleContainer m_SampleA;
00229 
00232   mutable SpatialSampleContainer m_SampleB;
00233 
00234   unsigned int m_NumberOfSpatialSamples;
00235   double       m_MovingImageStandardDeviation;
00236   double       m_FixedImageStandardDeviation;
00237   double       m_MinProbability;
00238 
00239   typename KernelFunctionType::Pointer m_KernelFunction;
00240 
00246   virtual void SampleFixedImageDomain(SpatialSampleContainer & samples) const;
00247 
00251   void CalculateDerivatives(const FixedImagePointType &, DerivativeType &) const;
00252 
00253   typedef typename Superclass::CoordinateRepresentationType
00254   CoordinateRepresentationType;
00255   typedef CentralDifferenceImageFunction< MovingImageType,
00256                                           CoordinateRepresentationType > DerivativeFunctionType;
00257 
00258   typename DerivativeFunctionType::Pointer m_DerivativeCalculator;
00259 
00260   bool m_ReseedIterator;
00261   int  m_RandomSeed;
00262 };
00263 } // end namespace itk
00264 
00265 #ifndef ITK_MANUAL_INSTANTIATION
00266 #include "itkMutualInformationImageToImageMetric.hxx"
00267 #endif
00268 
00269 #endif
00270