ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
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 __itkMattesMutualInformationImageToImageMetric_h 00019 #define __itkMattesMutualInformationImageToImageMetric_h 00020 00021 #include "itkImageToImageMetric.h" 00022 #include "itkPoint.h" 00023 #include "itkIndex.h" 00024 #include "itkBSplineDerivativeKernelFunction.h" 00025 #include "itkArray2D.h" 00026 00027 #include "itkSimpleFastMutexLock.h" 00028 00029 00030 namespace itk 00031 { 00113 template <class TFixedImage, class TMovingImage> 00114 class ITK_EXPORT MattesMutualInformationImageToImageMetric: 00115 public ImageToImageMetric<TFixedImage, TMovingImage> 00116 { 00117 public: 00118 00120 typedef MattesMutualInformationImageToImageMetric Self; 00121 typedef ImageToImageMetric<TFixedImage, TMovingImage> Superclass; 00122 typedef SmartPointer<Self> Pointer; 00123 typedef SmartPointer<const Self> ConstPointer; 00124 00126 itkNewMacro(Self); 00127 00129 itkTypeMacro(MattesMutualInformationImageToImageMetric, 00130 ImageToImageMetric); 00131 00133 typedef typename Superclass::TransformType TransformType; 00134 typedef typename Superclass::TransformPointer TransformPointer; 00135 typedef typename Superclass::TransformJacobianType TransformJacobianType; 00136 typedef typename Superclass::InterpolatorType InterpolatorType; 00137 typedef typename Superclass::MeasureType MeasureType; 00138 typedef typename Superclass::DerivativeType DerivativeType; 00139 typedef typename Superclass::ParametersType ParametersType; 00140 typedef typename Superclass::FixedImageType FixedImageType; 00141 typedef typename Superclass::MovingImageType MovingImageType; 00142 typedef typename Superclass::MovingImagePointType MovingImagePointType; 00143 typedef typename Superclass::FixedImageConstPointer FixedImageConstPointer; 00144 typedef typename Superclass::MovingImageConstPointer MovingImageConstPointer; 00145 typedef typename Superclass::BSplineTransformWeightsType BSplineTransformWeightsType; 00146 typedef typename Superclass::BSplineTransformIndexArrayType BSplineTransformIndexArrayType; 00147 00148 typedef typename Superclass::CoordinateRepresentationType CoordinateRepresentationType; 00149 typedef typename Superclass::FixedImageSampleContainer FixedImageSampleContainer; 00150 typedef typename Superclass::ImageDerivativesType ImageDerivativesType; 00151 typedef typename Superclass::WeightsValueType WeightsValueType; 00152 typedef typename Superclass::IndexValueType IndexValueType; 00153 00154 typedef typename FixedImageType::OffsetValueType OffsetValueType; 00155 00157 itkStaticConstMacro(MovingImageDimension, unsigned int, 00158 MovingImageType::ImageDimension); 00159 00167 virtual void Initialize(void) 00168 throw ( ExceptionObject ); 00169 00171 MeasureType GetValue(const ParametersType & parameters) const; 00172 00174 void GetDerivative(const ParametersType & parameters, DerivativeType & Derivative) const; 00175 00177 void GetValueAndDerivative(const ParametersType & parameters, MeasureType & Value, DerivativeType & Derivative) const; 00178 00184 itkSetClampMacro( NumberOfHistogramBins, SizeValueType, 00185 5, NumericTraits<SizeValueType>::max() ); 00186 itkGetConstReferenceMacro(NumberOfHistogramBins, SizeValueType); 00188 00213 itkSetMacro(UseExplicitPDFDerivatives, bool); 00214 itkGetConstReferenceMacro(UseExplicitPDFDerivatives, bool); 00215 itkBooleanMacro(UseExplicitPDFDerivatives); 00217 00219 typedef double PDFValueType; //NOTE: floating point precision is not as stable. Double precision proves faster and more robust in real-world testing. 00220 00222 typedef Image<PDFValueType, 2> JointPDFType; 00223 typedef Image<PDFValueType, 3> JointPDFDerivativesType; 00224 00229 const typename JointPDFType::Pointer GetJointPDF () const 00230 { 00231 if( this->m_ThreaderJointPDF.size() == 0 ) 00232 { 00233 return JointPDFType::Pointer(NULL); 00234 } 00235 return this->m_ThreaderJointPDF[0]; 00236 } 00238 00245 const typename JointPDFDerivativesType::Pointer GetJointPDFDerivatives () const 00246 { 00247 if( this->m_ThreaderJointPDFDerivatives.size() == 0 ) 00248 { 00249 return JointPDFDerivativesType::Pointer(NULL); 00250 } 00251 return this->m_ThreaderJointPDFDerivatives[0]; 00252 } 00253 protected: 00255 00256 MattesMutualInformationImageToImageMetric(); 00257 virtual ~MattesMutualInformationImageToImageMetric(); 00258 void PrintSelf(std::ostream & os, Indent indent) const; 00259 00260 private: 00261 00262 // purposely not implemented 00263 MattesMutualInformationImageToImageMetric(const Self &); 00264 // purposely not implemented 00265 void operator=(const Self &); 00266 00267 typedef JointPDFType::IndexType JointPDFIndexType; 00268 typedef JointPDFType::PixelType JointPDFValueType; 00269 typedef JointPDFType::RegionType JointPDFRegionType; 00270 typedef JointPDFType::SizeType JointPDFSizeType; 00271 typedef JointPDFDerivativesType::IndexType JointPDFDerivativesIndexType; 00272 typedef JointPDFDerivativesType::PixelType JointPDFDerivativesValueType; 00273 typedef JointPDFDerivativesType::RegionType JointPDFDerivativesRegionType; 00274 typedef JointPDFDerivativesType::SizeType JointPDFDerivativesSizeType; 00275 00277 typedef BSplineKernelFunction<3,PDFValueType> CubicBSplineFunctionType; 00278 typedef BSplineDerivativeKernelFunction<3,PDFValueType> CubicBSplineDerivativeFunctionType; 00279 00281 void ComputeFixedImageParzenWindowIndices( FixedImageSampleContainer & samples); 00282 00284 void ComputePDFDerivatives(ThreadIdType threadID, unsigned int sampleNumber, int movingImageParzenWindowIndex, 00285 const ImageDerivativesType 00286 & movingImageGradientValue, 00287 PDFValueType cubicBSplineDerivativeValue) const; 00288 00289 virtual void GetValueThreadPreProcess(ThreadIdType threadID, bool withinSampleThread) const; 00290 virtual void GetValueThreadPostProcess(ThreadIdType threadID, bool withinSampleThread) const; 00291 //NOTE: The signature in base class requires that movingImageValue is of type double 00292 virtual bool GetValueThreadProcessSample(ThreadIdType threadID, SizeValueType fixedImageSample, 00293 const MovingImagePointType & mappedPoint, 00294 double movingImageValue) const; 00295 00296 virtual void GetValueAndDerivativeThreadPreProcess( ThreadIdType threadID, bool withinSampleThread) const; 00297 virtual void GetValueAndDerivativeThreadPostProcess( ThreadIdType threadID, bool withinSampleThread) const; 00298 //NOTE: The signature in base class requires that movingImageValue is of type double 00299 virtual bool GetValueAndDerivativeThreadProcessSample(ThreadIdType threadID, SizeValueType fixedImageSample, 00300 const MovingImagePointType & mappedPoint, 00301 double movingImageValue, const ImageDerivativesType & 00302 movingImageGradientValue) const; 00303 00305 SizeValueType m_NumberOfHistogramBins; 00306 PDFValueType m_MovingImageNormalizedMin; 00307 PDFValueType m_FixedImageNormalizedMin; 00308 PDFValueType m_FixedImageTrueMin; 00309 PDFValueType m_FixedImageTrueMax; 00310 PDFValueType m_MovingImageTrueMin; 00311 PDFValueType m_MovingImageTrueMax; 00312 PDFValueType m_FixedImageBinSize; 00313 PDFValueType m_MovingImageBinSize; 00314 00316 typename CubicBSplineFunctionType::Pointer m_CubicBSplineKernel; 00317 typename CubicBSplineDerivativeFunctionType::Pointer m_CubicBSplineDerivativeKernel; 00318 00320 typedef PDFValueType PRatioType; 00321 typedef Array2D<PRatioType> PRatioArrayType; 00322 00323 mutable PRatioArrayType m_PRatioArray; 00324 00326 mutable std::vector<DerivativeType> m_ThreaderMetricDerivative; 00327 00329 mutable std::vector<PDFValueType> m_MovingImageMarginalPDF; 00330 mutable std::vector<std::vector<PDFValueType> > m_ThreaderFixedImageMarginalPDF; 00331 00333 typename std::vector<JointPDFType::Pointer> m_ThreaderJointPDF; 00334 typename std::vector<JointPDFDerivativesType::Pointer> m_ThreaderJointPDFDerivatives; 00335 00336 std::vector<int> m_ThreaderJointPDFStartBin; 00337 std::vector<int> m_ThreaderJointPDFEndBin; 00338 00339 mutable std::vector<PDFValueType> m_ThreaderJointPDFSum; 00340 00341 bool m_UseExplicitPDFDerivatives; 00342 mutable bool m_ImplicitDerivativesSecondPass; 00343 }; 00344 } // end namespace itk 00345 00346 #ifndef ITK_MANUAL_INSTANTIATION 00347 #include "itkMattesMutualInformationImageToImageMetric.hxx" 00348 #endif 00349 00350 #endif 00351