ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkJointHistogramMutualInformationImageToImageMetricv4.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 
00019 #ifndef __itkJointHistogramMutualInformationImageToImageMetricv4_h
00020 #define __itkJointHistogramMutualInformationImageToImageMetricv4_h
00021 
00022 #include "itkImageToImageMetricv4.h"
00023 #include "itkImage.h"
00024 #include "itkBSplineDerivativeKernelFunction.h"
00025 
00026 #include "itkJointHistogramMutualInformationComputeJointPDFThreader.h"
00027 #include "itkJointHistogramMutualInformationGetValueAndDerivativeThreader.h"
00028 
00029 namespace itk
00030 {
00044 template<class TFixedImage,class TMovingImage,class TVirtualImage = TFixedImage>
00045 class ITK_EXPORT JointHistogramMutualInformationImageToImageMetricv4 :
00046   public ImageToImageMetricv4<TFixedImage, TMovingImage, TVirtualImage>
00047 {
00048 public:
00049 
00051   typedef JointHistogramMutualInformationImageToImageMetricv4            Self;
00052   typedef ImageToImageMetricv4<TFixedImage, TMovingImage, TVirtualImage> Superclass;
00053   typedef SmartPointer<Self>                                                 Pointer;
00054   typedef SmartPointer<const Self>                                           ConstPointer;
00055 
00057   itkNewMacro(Self);
00058 
00060   itkTypeMacro(JointHistogramMutualInformationImageToImageMetricv4,
00061                 ImageToImageMetricv4);
00062 
00064   typedef typename Superclass::CoordinateRepresentationType
00065                                                   CoordinateRepresentationType;
00066 
00068   typedef typename Superclass::InternalComputationValueType
00069                                                   InternalComputationValueType;
00070 
00072   typedef typename Superclass::ParametersType         ParametersType;
00073   typedef typename Superclass::ParametersValueType    ParametersValueType;
00074   typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
00075 
00077   typedef typename Superclass::MeasureType              MeasureType;
00078   typedef typename Superclass::DerivativeType           DerivativeType;
00079   typedef typename Superclass::FixedImagePointType      FixedImagePointType;
00080   typedef typename Superclass::FixedImagePixelType      FixedImagePixelType;
00081   typedef typename Superclass::FixedGradientPixelType
00082                                                         FixedImageGradientType;
00083   typedef typename Superclass::MovingImagePointType     MovingImagePointType;
00084   typedef typename Superclass::MovingImagePixelType     MovingImagePixelType;
00085   typedef typename Superclass::MovingGradientPixelType
00086                                                         MovingImageGradientType;
00087   typedef typename Superclass::FixedTransformType::JacobianType
00088                                                         FixedTransformJacobianType;
00089   typedef typename Superclass::MovingTransformType::JacobianType
00090                                                         MovingTransformJacobianType;
00091   typedef typename Superclass::VirtualImageType         VirtualImageType;
00092   typedef typename Superclass::VirtualIndexType         VirtualIndexType;
00093   typedef typename Superclass::VirtualPointType         VirtualPointType;
00094   typedef typename Superclass::VirtualSampledPointSetType
00095                                                         VirtualSampledPointSetType;
00096 
00097   /* Image dimension accessors */
00098   itkStaticConstMacro(VirtualImageDimension, ImageDimensionType,
00099       ::itk::GetImageDimension<TVirtualImage>::ImageDimension);
00100   itkStaticConstMacro(MovingImageDimension, ImageDimensionType,
00101       ::itk::GetImageDimension<TMovingImage>::ImageDimension);
00102 
00104   typedef InternalComputationValueType                  PDFValueType;
00105 
00107   typedef Image<PDFValueType,1>                 MarginalPDFType;
00108   typedef typename MarginalPDFType::IndexType   MarginalPDFIndexType;
00109   typedef typename MarginalPDFType::PointType   MarginalPDFPointType;
00110   typedef Image< PDFValueType, 2>               JointPDFType;
00111   typedef typename JointPDFType::IndexType      JointPDFIndexType;
00112   typedef typename JointPDFType::PointType      JointPDFPointType;
00113   typedef typename JointPDFType::IndexValueType JointPDFIndexValueType;
00114 
00116   itkGetConstObjectMacro( JointPDF, JointPDFType );
00117 
00118   // Declare the type for the derivative calculation
00119   typedef itk::GradientRecursiveGaussianImageFilter< JointPDFType >
00120                                                          JPDFGradientFilterType;
00121 
00122   typedef typename JPDFGradientFilterType::OutputImageType JPDFGradientImageType;
00123 
00124   typedef typename JPDFGradientImageType::Pointer JPDFGradientImagePointer;
00125 
00126   typedef itk::GradientRecursiveGaussianImageFilter< MarginalPDFType >
00127                                                   MarginalGradientFilterType;
00128   typedef typename MarginalGradientFilterType::OutputImageType
00129                                                   MarginalGradientImageType;
00130   typedef typename MarginalGradientImageType::Pointer
00131                                                   MarginalGradientImagePointer;
00132 
00134   typedef LinearInterpolateImageFunction<JointPDFType,double>
00135                                                      JointPDFInterpolatorType;
00136   typedef typename JointPDFInterpolatorType::Pointer JointPDFInterpolatorPointer;
00137   typedef LinearInterpolateImageFunction<MarginalPDFType,double>
00138                                                      MarginalPDFInterpolatorType;
00139   typedef typename MarginalPDFInterpolatorType::Pointer
00140                                                      MarginalPDFInterpolatorPointer;
00141 
00143   typedef typename JointPDFType::PixelType             JointPDFValueType;
00144   typedef typename JointPDFType::RegionType            JointPDFRegionType;
00145   typedef typename JointPDFType::SizeType              JointPDFSizeType;
00146   typedef typename JointPDFType::SpacingType           JointPDFSpacingType;
00147 
00148 
00150   itkSetClampMacro( NumberOfHistogramBins, SizeValueType,
00151                     5, NumericTraits< SizeValueType >::max() );
00152   itkGetConstReferenceMacro(NumberOfHistogramBins, SizeValueType );
00154 
00156   itkSetMacro(VarianceForJointPDFSmoothing, InternalComputationValueType);
00157   itkGetMacro(VarianceForJointPDFSmoothing, InternalComputationValueType);
00159 
00161   virtual void Initialize() throw (itk::ExceptionObject);
00162 
00163   virtual MeasureType GetValue() const;
00164 
00165 protected:
00166   JointHistogramMutualInformationImageToImageMetricv4();
00167   virtual ~JointHistogramMutualInformationImageToImageMetricv4();
00168 
00172   virtual void InitializeForIteration() const;
00173 
00175   MeasureType ComputeValue() const;
00176 
00179   inline void ComputeJointPDFPoint( const FixedImagePixelType fixedImageValue,
00180                                const MovingImagePixelType movingImageValue,
00181                                JointPDFPointType & jointPDFpoint ) const;
00182 
00183   friend class JointHistogramMutualInformationComputeJointPDFThreaderBase< ThreadedImageRegionPartitioner< Self::VirtualImageDimension >, Self >;
00184   friend class JointHistogramMutualInformationComputeJointPDFThreaderBase< ThreadedIndexedContainerPartitioner, Self >;
00185   friend class JointHistogramMutualInformationComputeJointPDFThreader< ThreadedImageRegionPartitioner< Self::VirtualImageDimension >, Self >;
00186   friend class JointHistogramMutualInformationComputeJointPDFThreader< ThreadedIndexedContainerPartitioner, Self >;
00187 
00188   typedef JointHistogramMutualInformationComputeJointPDFThreader< ThreadedImageRegionPartitioner< Self::VirtualImageDimension >, Self >
00189     JointHistogramMutualInformationDenseComputeJointPDFThreaderType;
00190   typedef JointHistogramMutualInformationComputeJointPDFThreader< ThreadedIndexedContainerPartitioner, Self >
00191     JointHistogramMutualInformationSparseComputeJointPDFThreaderType;
00192 
00193   typename JointHistogramMutualInformationDenseComputeJointPDFThreaderType::Pointer  m_JointHistogramMutualInformationDenseComputeJointPDFThreader;
00194   typename JointHistogramMutualInformationSparseComputeJointPDFThreaderType::Pointer m_JointHistogramMutualInformationSparseComputeJointPDFThreader;
00195 
00196   friend class JointHistogramMutualInformationGetValueAndDerivativeThreader< ThreadedImageRegionPartitioner< Superclass::VirtualImageDimension >, Superclass, Self >;
00197   friend class JointHistogramMutualInformationGetValueAndDerivativeThreader< ThreadedIndexedContainerPartitioner, Superclass, Self >;
00198 
00199   typedef JointHistogramMutualInformationGetValueAndDerivativeThreader< ThreadedImageRegionPartitioner< Superclass::VirtualImageDimension >, Superclass, Self >
00200     JointHistogramMutualInformationDenseGetValueAndDerivativeThreaderType;
00201   typedef JointHistogramMutualInformationGetValueAndDerivativeThreader< ThreadedIndexedContainerPartitioner, Superclass, Self >
00202     JointHistogramMutualInformationSparseGetValueAndDerivativeThreaderType;
00203 
00205   void PrintSelf(std::ostream & os, Indent indent) const;
00206 
00208   SizeValueType   m_JointHistogramTotalCount;
00209 
00210 private:
00211   JointHistogramMutualInformationImageToImageMetricv4(const Self &); //purposely not implemented
00212   void operator=(const Self &); //purposely not implemented
00213 
00215   typename MarginalPDFType::Pointer m_FixedImageMarginalPDF;
00216 
00218   typename MarginalPDFType::Pointer m_MovingImageMarginalPDF;
00219 
00221   mutable typename JointPDFType::Pointer            m_JointPDF;
00222 
00224   InternalComputationValueType        m_VarianceForJointPDFSmoothing;
00225 
00227   SizeValueType                       m_NumberOfHistogramBins;
00228   InternalComputationValueType        m_FixedImageTrueMin;
00229   InternalComputationValueType        m_FixedImageTrueMax;
00230   InternalComputationValueType        m_MovingImageTrueMin;
00231   InternalComputationValueType        m_MovingImageTrueMax;
00232   InternalComputationValueType        m_FixedImageBinSize;
00233   InternalComputationValueType        m_MovingImageBinSize;
00234 
00235   InternalComputationValueType        m_JointPDFSum;
00236   JointPDFSpacingType                 m_JointPDFSpacing;
00237 
00238   InternalComputationValueType        m_Log2;
00239   JointPDFIndexValueType              m_Padding;
00240 
00241 };
00242 
00243 } // end namespace itk
00244 
00245 #ifndef ITK_MANUAL_INSTANTIATION
00246 #include "itkJointHistogramMutualInformationImageToImageMetricv4.hxx"
00247 #endif
00248 
00249 #endif
00250