ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkMattesMutualInformationImageToImageMetricv4.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 __itkMattesMutualInformationImageToImageMetricv4_h
00019 #define __itkMattesMutualInformationImageToImageMetricv4_h
00020 
00021 #include "itkImageToImageMetricv4.h"
00022 #include "itkMattesMutualInformationImageToImageMetricv4GetValueAndDerivativeThreader.h"
00023 #include "itkPoint.h"
00024 #include "itkIndex.h"
00025 #include "itkBSplineDerivativeKernelFunction.h"
00026 #include "itkArray2D.h"
00027 
00028 namespace itk
00029 {
00030 
00095 template <class TFixedImage, class TMovingImage, class TVirtualImage = TFixedImage >
00096 class ITK_EXPORT MattesMutualInformationImageToImageMetricv4 :
00097 public ImageToImageMetricv4<TFixedImage, TMovingImage, TVirtualImage>
00098 {
00099 public:
00101   typedef MattesMutualInformationImageToImageMetricv4                                     Self;
00102   typedef ImageToImageMetricv4<TFixedImage, TMovingImage, TVirtualImage> Superclass;
00103   typedef SmartPointer<Self>                                             Pointer;
00104   typedef SmartPointer<const Self>                                       ConstPointer;
00105 
00107   itkNewMacro(Self);
00108 
00110   itkTypeMacro(MattesMutualInformationImageToImageMetricv4, ImageToImageMetricv4);
00111 
00113   typedef typename Superclass::MeasureType             MeasureType;
00114   typedef typename Superclass::DerivativeType          DerivativeType;
00115   typedef typename DerivativeType::ValueType           DerivativeValueType;
00116 
00117   typedef typename Superclass::FixedImageType          FixedImageType;
00118   typedef typename Superclass::FixedImagePointType     FixedImagePointType;
00119   typedef typename Superclass::FixedImageIndexType     FixedImageIndexType;
00120   typedef typename Superclass::FixedImagePixelType     FixedImagePixelType;
00121   typedef typename Superclass::FixedImageGradientType  FixedImageGradientType;
00122 
00123   typedef typename Superclass::MovingImagePointType    MovingImagePointType;
00124   typedef typename Superclass::MovingImagePixelType    MovingImagePixelType;
00125   typedef typename Superclass::MovingImageGradientType MovingImageGradientType;
00126 
00127   typedef typename Superclass::MovingTransformType        MovingTransformType;
00128   typedef typename Superclass::JacobianType               JacobianType;
00129   typedef typename Superclass::VirtualImageType           VirtualImageType;
00130   typedef typename Superclass::VirtualIndexType           VirtualIndexType;
00131   typedef typename Superclass::VirtualPointType           VirtualPointType;
00132   typedef typename Superclass::VirtualSampledPointSetType VirtualSampledPointSetType;
00133 
00135   typedef typename Superclass::FixedSampledPointSetPointer    FixedSampledPointSetPointer;
00136 
00137 
00138   /* Image dimension accessors */
00139   itkStaticConstMacro(VirtualImageDimension, ImageDimensionType,
00140       ::itk::GetImageDimension<TVirtualImage>::ImageDimension);
00141   itkStaticConstMacro(FixedImageDimension, ImageDimensionType,
00142       ::itk::GetImageDimension<TFixedImage>::ImageDimension);
00143   itkStaticConstMacro(MovingImageDimension, ImageDimensionType,
00144       ::itk::GetImageDimension<TMovingImage>::ImageDimension);
00145 
00146 
00152   itkSetClampMacro( NumberOfHistogramBins, SizeValueType,
00153                     5, NumericTraits<SizeValueType>::max() );
00154   itkGetConstReferenceMacro(NumberOfHistogramBins, SizeValueType);
00156 
00157   virtual void Initialize(void) throw ( itk::ExceptionObject );
00158 
00162   virtual void GetValueAndDerivative( MeasureType & value,
00163                                       DerivativeType & derivative ) const;
00164 
00166   //NOTE:  floating point precision is not as stable.
00167   // Double precision proves faster and more robust in real-world testing.
00168   typedef double PDFValueType;
00169 
00171   typedef Image<PDFValueType, 2> JointPDFType;
00172   typedef Image<PDFValueType, 3> JointPDFDerivativesType;
00173 
00178   const typename JointPDFType::Pointer GetJointPDF () const
00179     {
00180     if( this->m_ThreaderJointPDF.size() == 0 )
00181       {
00182       return JointPDFType::Pointer(NULL);
00183       }
00184     return this->m_ThreaderJointPDF[0];
00185     }
00187 
00194   const typename JointPDFDerivativesType::Pointer GetJointPDFDerivatives () const
00195     {
00196     if( this->m_ThreaderJointPDFDerivatives.size() == 0 )
00197       {
00198       return JointPDFDerivativesType::Pointer(NULL);
00199       }
00200     return this->m_ThreaderJointPDFDerivatives[0];
00201     }
00203 
00204 
00205 protected:
00206   MattesMutualInformationImageToImageMetricv4();
00207   virtual ~MattesMutualInformationImageToImageMetricv4();
00208 
00209   friend class MattesMutualInformationImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedImageRegionPartitioner< Superclass::VirtualImageDimension >, Superclass, Self >;
00210   friend class MattesMutualInformationImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedIndexedContainerPartitioner, Superclass, Self >;
00211   typedef MattesMutualInformationImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedImageRegionPartitioner< Superclass::VirtualImageDimension >, Superclass, Self >
00212     MattesMutualInformationDenseGetValueAndDerivativeThreaderType;
00213   typedef MattesMutualInformationImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedIndexedContainerPartitioner, Superclass, Self >
00214     MattesMutualInformationSparseGetValueAndDerivativeThreaderType;
00215 
00216   void PrintSelf(std::ostream& os, Indent indent) const;
00217 
00218 
00219   typedef JointPDFType::IndexType             JointPDFIndexType;
00220   typedef JointPDFType::PixelType             JointPDFValueType;
00221   typedef JointPDFType::RegionType            JointPDFRegionType;
00222   typedef JointPDFType::SizeType              JointPDFSizeType;
00223   typedef JointPDFDerivativesType::IndexType  JointPDFDerivativesIndexType;
00224   typedef JointPDFDerivativesType::PixelType  JointPDFDerivativesValueType;
00225   typedef JointPDFDerivativesType::RegionType JointPDFDerivativesRegionType;
00226   typedef JointPDFDerivativesType::SizeType   JointPDFDerivativesSizeType;
00227 
00229   typedef BSplineKernelFunction<3,PDFValueType>           CubicBSplineFunctionType;
00230   typedef BSplineDerivativeKernelFunction<3,PDFValueType> CubicBSplineDerivativeFunctionType;
00231 
00234   virtual void GetValueCommonAfterThreadedExecution();
00235 
00236   OffsetValueType ComputeSingleFixedImageParzenWindowIndex( const FixedImagePixelType & value ) const;
00237 
00239   SizeValueType m_NumberOfHistogramBins;
00240   PDFValueType  m_MovingImageNormalizedMin;
00241   PDFValueType  m_FixedImageNormalizedMin;
00242   PDFValueType  m_FixedImageTrueMin;
00243   PDFValueType  m_FixedImageTrueMax;
00244   PDFValueType  m_MovingImageTrueMin;
00245   PDFValueType  m_MovingImageTrueMax;
00246   PDFValueType  m_FixedImageBinSize;
00247   PDFValueType  m_MovingImageBinSize;
00248 
00250   typename CubicBSplineFunctionType::Pointer           m_CubicBSplineKernel;
00251   typename CubicBSplineDerivativeFunctionType::Pointer m_CubicBSplineDerivativeKernel;
00252 
00254   typedef PDFValueType              PRatioType;
00255   typedef std::vector<PRatioType>   PRatioArrayType;
00256 
00257   mutable PRatioArrayType           m_PRatioArray;
00258 
00261   mutable std::vector<OffsetValueType>   m_JointPdfIndex1DArray;
00262 
00264   mutable std::vector<PDFValueType>               m_MovingImageMarginalPDF;
00265   mutable std::vector<std::vector<PDFValueType> > m_ThreaderFixedImageMarginalPDF;
00266 
00268   typename std::vector<JointPDFType::Pointer>            m_ThreaderJointPDF;
00269   typename std::vector<JointPDFDerivativesType::Pointer> m_ThreaderJointPDFDerivatives;
00270 
00271   std::vector<int> m_ThreaderJointPDFStartBin;
00272   std::vector<int> m_ThreaderJointPDFEndBin;
00273 
00274   mutable std::vector<PDFValueType> m_ThreaderJointPDFSum;
00275 
00278   mutable std::vector<DerivativeType>              m_LocalDerivativeByParzenBin;
00279 
00280 private:
00281   MattesMutualInformationImageToImageMetricv4(const Self &); //purposely not implemented
00282   void operator = (const Self &); //purposely not implemented
00283 };
00284 
00285 } // end namespace itk
00286 
00287 #ifndef ITK_MANUAL_INSTANTIATION
00288 #include "itkMattesMutualInformationImageToImageMetricv4.hxx"
00289 #endif
00290 
00291 #endif
00292