go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkParzenWindowHistogramImageToImageMetric.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright UMC Utrecht and contributors
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkParzenWindowHistogramImageToImageMetric_H__
19 #define __itkParzenWindowHistogramImageToImageMetric_H__
20 
22 #include "itkBSplineKernelFunction.h"
23 
24 namespace itk
25 {
72 template< class TFixedImage, class TMovingImage >
74  public AdvancedImageToImageMetric< TFixedImage, TMovingImage >
75 {
76 public:
77 
82  typedef SmartPointer< const Self > ConstPointer;
83 
86 
103  typedef typename Superclass::RealType RealType;
130 
132  itkStaticConstMacro( FixedImageDimension, unsigned int,
133  FixedImageType::ImageDimension );
134 
136  itkStaticConstMacro( MovingImageDimension, unsigned int,
137  MovingImageType::ImageDimension );
138 
145  void Initialize( void ) throw ( ExceptionObject );
146 
151  void GetDerivative(
152  const ParametersType & parameters,
153  DerivativeType & Derivative ) const;
154 
160  void GetValueAndDerivative( const ParametersType & parameters,
161  MeasureType & value, DerivativeType & derivative ) const;
162 
169  itkSetClampMacro( NumberOfFixedHistogramBins, unsigned long,
170  4, NumericTraits< unsigned long >::max() );
171  itkGetMacro( NumberOfFixedHistogramBins, unsigned long );
172 
179  itkSetClampMacro( NumberOfMovingHistogramBins, unsigned long,
180  4, NumericTraits< unsigned long >::max() );
181  itkGetMacro( NumberOfMovingHistogramBins, unsigned long );
182 
184  itkSetClampMacro( FixedKernelBSplineOrder, unsigned int, 0, 3 );
185  itkGetConstMacro( FixedKernelBSplineOrder, unsigned int );
186 
188  itkSetClampMacro( MovingKernelBSplineOrder, unsigned int, 0, 3 );
189  itkGetConstMacro( MovingKernelBSplineOrder, unsigned int );
190 
194  itkSetMacro( UseExplicitPDFDerivatives, bool );
195  itkGetConstReferenceMacro( UseExplicitPDFDerivatives, bool );
196  itkBooleanMacro( UseExplicitPDFDerivatives );
197 
201  itkSetMacro( UseDerivative, bool );
202  itkGetConstMacro( UseDerivative, bool );
203 
207  itkSetMacro( UseFiniteDifferenceDerivative, bool );
208  itkGetConstMacro( UseFiniteDifferenceDerivative, bool );
209 
214  itkSetMacro( FiniteDifferencePerturbation, double );
215  itkGetConstMacro( FiniteDifferencePerturbation, double );
216 
217 protected:
218 
221 
223  virtual ~ParzenWindowHistogramImageToImageMetric();
224 
226  void PrintSelf( std::ostream & os, Indent indent ) const;
227 
231  typedef typename Superclass::FixedImageIndexType FixedImageIndexType;
233  typedef typename FixedImageType::OffsetValueType OffsetValueType;
234  typedef typename Superclass::MovingImageIndexType MovingImageIndexType;
235  typedef typename Superclass::FixedImagePointType FixedImagePointType;
236  typedef typename Superclass::MovingImagePointType MovingImagePointType;
238  typedef typename Superclass::BSplineInterpolatorType BSplineInterpolatorType;
242 
244  typedef double PDFValueType;
245  typedef float PDFDerivativeValueType;
246  typedef Array< PDFValueType > MarginalPDFType;
247  typedef Image< PDFValueType, 2 > JointPDFType;
248  typedef typename JointPDFType::Pointer JointPDFPointer;
249  typedef Image< PDFDerivativeValueType, 3 > JointPDFDerivativesType;
250  typedef typename JointPDFDerivativesType::Pointer JointPDFDerivativesPointer;
251  typedef Image< PDFValueType, 2 > IncrementalMarginalPDFType;
252  typedef typename IncrementalMarginalPDFType::Pointer IncrementalMarginalPDFPointer;
253  typedef JointPDFType::IndexType JointPDFIndexType;
254  typedef JointPDFType::RegionType JointPDFRegionType;
255  typedef JointPDFType::SizeType JointPDFSizeType;
256  typedef JointPDFDerivativesType::IndexType JointPDFDerivativesIndexType;
257  typedef JointPDFDerivativesType::RegionType JointPDFDerivativesRegionType;
258  typedef JointPDFDerivativesType::SizeType JointPDFDerivativesSizeType;
259  typedef IncrementalMarginalPDFType::IndexType IncrementalMarginalPDFIndexType;
260  typedef IncrementalMarginalPDFType::RegionType IncrementalMarginalPDFRegionType;
261  typedef IncrementalMarginalPDFType::SizeType IncrementalMarginalPDFSizeType;
262  typedef Array< PDFValueType > ParzenValueContainerType;
263 
265  typedef KernelFunctionBase< PDFValueType > KernelFunctionType;
266  typedef typename KernelFunctionType::Pointer KernelFunctionPointer;
267 
271  mutable double m_Alpha;
272  mutable DerivativeType m_PerturbedAlphaRight;
273  mutable DerivativeType m_PerturbedAlphaLeft;
274 
276  mutable MarginalPDFType m_FixedImageMarginalPDF;
277  mutable MarginalPDFType m_MovingImageMarginalPDF;
278  JointPDFPointer m_JointPDF;
279  JointPDFDerivativesPointer m_JointPDFDerivatives;
280  JointPDFDerivativesPointer m_IncrementalJointPDFRight;
281  JointPDFDerivativesPointer m_IncrementalJointPDFLeft;
282  IncrementalMarginalPDFPointer m_FixedIncrementalMarginalPDFRight;
283  IncrementalMarginalPDFPointer m_MovingIncrementalMarginalPDFRight;
284  IncrementalMarginalPDFPointer m_FixedIncrementalMarginalPDFLeft;
285  IncrementalMarginalPDFPointer m_MovingIncrementalMarginalPDFLeft;
286  mutable JointPDFRegionType m_JointPDFWindow; // no need for mutable anymore?
293 
295  KernelFunctionPointer m_FixedKernel;
296  KernelFunctionPointer m_MovingKernel;
297  KernelFunctionPointer m_DerivativeMovingKernel;
298 
300  mutable std::vector< JointPDFPointer > m_ThreaderJointPDFs;
301 
305  struct ParzenWindowHistogramMultiThreaderParameterType // can't we use the one from AdvancedImageToImageMetric ?
306  {
307  Self * m_Metric;
308  };
309  ParzenWindowHistogramMultiThreaderParameterType m_ParzenWindowHistogramThreaderParameters;
310 
312  {
315  };
317  PaddedParzenWindowHistogramGetValueAndDerivativePerThreadStruct );
318  itkAlignedTypedef( ITK_CACHE_LINE_ALIGNMENT, PaddedParzenWindowHistogramGetValueAndDerivativePerThreadStruct,
319  AlignedParzenWindowHistogramGetValueAndDerivativePerThreadStruct );
320  mutable AlignedParzenWindowHistogramGetValueAndDerivativePerThreadStruct * m_ParzenWindowHistogramGetValueAndDerivativePerThreadVariables;
322 
324  virtual void InitializeThreadingParameters( void ) const;
325 
327  inline void ThreadedComputePDFs( ThreadIdType threadId );
328 
330  inline void AfterThreadedComputePDFs( void ) const;
331 
333  static ITK_THREAD_RETURN_TYPE ComputePDFsThreaderCallback( void * arg );
334 
336  void LaunchComputePDFsThreaderCallback( void ) const;
337 
345  double parzenWindowTerm, OffsetValueType parzenWindowIndex,
346  const KernelFunctionType * kernel,
347  ParzenValueContainerType & parzenValues ) const;
348 
352  virtual void UpdateJointPDFAndDerivatives(
353  const RealType & fixedImageValue,
354  const RealType & movingImageValue,
355  const DerivativeType * imageJacobian,
356  const NonZeroJacobianIndicesType * nzji,
357  JointPDFType * jointPDF ) const;
358 
370  RealType fixedImageValue, RealType movingImageValue, RealType movingMaskValue,
371  const DerivativeType & movingImageValuesRight,
372  const DerivativeType & movingImageValuesLeft,
373  const DerivativeType & movingMaskValuesRight,
374  const DerivativeType & movingMaskValuesLeft,
375  const NonZeroJacobianIndicesType & nzji ) const;
376 
383  const JointPDFIndexType & pdfIndex, double factor,
384  const DerivativeType & imageJacobian,
385  const NonZeroJacobianIndicesType & nzji ) const;
386 
388  virtual void NormalizeJointPDF(
389  JointPDFType * pdf, const double & factor ) const;
390 
392  virtual void NormalizeJointPDFDerivatives(
393  JointPDFDerivativesType * pdf, const double & factor ) const;
394 
399  virtual void ComputeMarginalPDF(
400  const JointPDFType * jointPDF,
401  MarginalPDFType & marginalPDF,
402  const unsigned int & direction ) const;
403 
407  virtual void ComputeIncrementalMarginalPDFs(
408  const JointPDFDerivativesType * incrementalPDF,
409  IncrementalMarginalPDFType * fixedIncrementalMarginalPDF,
410  IncrementalMarginalPDFType * movingIncrementalMarginalPDF ) const;
411 
421  virtual void ComputePDFsAndPDFDerivatives( const ParametersType & parameters ) const;
422 
446  virtual void ComputePDFsAndIncrementalPDFs( const ParametersType & parameters ) const;
447 
456  virtual void ComputePDFsSingleThreaded( const ParametersType & parameters ) const;
457 
458  virtual void ComputePDFs( const ParametersType & parameters ) const;
459 
461  virtual void InitializeHistograms( void );
462 
463  virtual void InitializeKernels( void );
464 
470  const ParametersType & itkNotUsed( parameters ),
471  MeasureType & itkNotUsed( value ),
472  DerivativeType & itkNotUsed( derivative ) ) const {}
473 
479  const ParametersType & itkNotUsed( parameters ),
480  MeasureType & itkNotUsed( value ),
481  DerivativeType & itkNotUsed( derivative ) ) const {}
482 
483 private:
484 
486  ParzenWindowHistogramImageToImageMetric( const Self & ); // purposely not implemented
488  void operator=( const Self & ); // purposely not implemented
489 
499 
500 };
501 
502 } // end namespace itk
503 
504 #ifndef ITK_MANUAL_INSTANTIATION
505 #include "itkParzenWindowHistogramImageToImageMetric.hxx"
506 #endif
507 
508 #endif // end #ifndef __itkParzenWindowHistogramImageToImageMetric_H__
virtual void GetValueAndFiniteDifferenceDerivative(const ParametersType &, MeasureType &, DerivativeType &) const
Superclass::MovingImageDerivativeScalesType MovingImageDerivativeScalesType
virtual void ComputeIncrementalMarginalPDFs(const JointPDFDerivativesType *incrementalPDF, IncrementalMarginalPDFType *fixedIncrementalMarginalPDF, IncrementalMarginalPDFType *movingIncrementalMarginalPDF) const
virtual void NormalizeJointPDFDerivatives(JointPDFDerivativesType *pdf, const double &factor) const
LimiterFunctionBase< RealType, FixedImageDimension > FixedImageLimiterType
Superclass::CoordinateRepresentationType CoordinateRepresentationType
void EvaluateParzenValues(double parzenWindowTerm, OffsetValueType parzenWindowIndex, const KernelFunctionType *kernel, ParzenValueContainerType &parzenValues) const
Superclass::TransformParametersType TransformParametersType
Superclass::FixedImageMaskPointer FixedImageMaskPointer
An extension of the ITK ImageToImageMetric. It is the intended base class for all elastix metrics...
Superclass::GradientPixelType GradientPixelType
FixedImageLimiterType::OutputType FixedImageLimiterOutputType
Superclass::FixedImageRegionType FixedImageRegionType
itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedParzenWindowHistogramGetValueAndDerivativePerThreadStruct, AlignedParzenWindowHistogramGetValueAndDerivativePerThreadStruct)
void ThreadedComputePDFs(ThreadIdType threadId)
ImageSamplerType::OutputVectorContainerType ImageSampleContainerType
virtual void NormalizeJointPDF(JointPDFType *pdf, const double &factor) const
FixedArray< double, Self::MovingImageDimension > MovingImageDerivativeScalesType
BSplineInterpolateImageFunction< MovingImageType, CoordinateRepresentationType, double > BSplineInterpolatorType
ImageSamplerBase< FixedImageType > ImageSamplerType
virtual void ComputePDFsSingleThreaded(const ParametersType &parameters) const
virtual void ComputePDFsAndIncrementalPDFs(const ParametersType &parameters) const
virtual void UpdateJointPDFAndIncrementalPDFs(RealType fixedImageValue, RealType movingImageValue, RealType movingMaskValue, const DerivativeType &movingImageValuesRight, const DerivativeType &movingImageValuesLeft, const DerivativeType &movingMaskValuesRight, const DerivativeType &movingMaskValuesLeft, const NonZeroJacobianIndicesType &nzji) const
Superclass::InterpolatorPointer InterpolatorPointer
Superclass::CoordinateRepresentationType CoordinateRepresentationType
virtual void GetValueAndAnalyticDerivative(const ParametersType &, MeasureType &, DerivativeType &) const
virtual void InitializeThreadingParameters(void) const
int max(int a, int b)
Superclass::MovingImageMaskType MovingImageMaskType
LimiterFunctionBase< RealType, MovingImageDimension > MovingImageLimiterType
Superclass::GradientImageType GradientImageType
virtual void ComputePDFs(const ParametersType &parameters) const
Superclass::TransformPointer TransformPointer
ParzenWindowHistogramMultiThreaderParameterType m_ParzenWindowHistogramThreaderParameters
A base class for image metrics based on a joint histogram computed using Parzen Windowing.
void PrintSelf(std::ostream &os, Indent indent) const
void UpdateJointPDFDerivatives(const JointPDFIndexType &pdfIndex, double factor, const DerivativeType &imageJacobian, const NonZeroJacobianIndicesType &nzji) const
itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, ParzenWindowHistogramGetValueAndDerivativePerThreadStruct, PaddedParzenWindowHistogramGetValueAndDerivativePerThreadStruct)
void GetValueAndDerivative(const ParametersType &parameters, MeasureType &value, DerivativeType &derivative) const
void GetDerivative(const ParametersType &parameters, DerivativeType &Derivative) const
Superclass::GradientImageFilterType GradientImageFilterType
MovingImageType::RegionType MovingImageRegionType
Superclass::InterpolatorType InterpolatorType
Superclass::TransformJacobianType TransformJacobianType
static ITK_THREAD_RETURN_TYPE ComputePDFsThreaderCallback(void *arg)
virtual void UpdateJointPDFAndDerivatives(const RealType &fixedImageValue, const RealType &movingImageValue, const DerivativeType *imageJacobian, const NonZeroJacobianIndicesType *nzji, JointPDFType *jointPDF) const
virtual void ComputeMarginalPDF(const JointPDFType *jointPDF, MarginalPDFType &marginalPDF, const unsigned int &direction) const
Superclass::MovingImagePixelType MovingImagePixelType
Superclass::MovingImageMaskPointer MovingImageMaskPointer
MovingImageLimiterType::OutputType MovingImageLimiterOutputType
ThreaderType::ThreadInfoStruct ThreadInfoType
virtual void ComputePDFsAndPDFDerivatives(const ParametersType &parameters) const
ImageSamplerType::OutputVectorContainerPointer ImageSampleContainerPointer
Superclass::FixedImageMaskType FixedImageMaskType
itkStaticConstMacro(FixedImageDimension, unsigned int, FixedImageType::ImageDimension)
Superclass::FixedImageConstPointer FixedImageConstPointer
AlignedParzenWindowHistogramGetValueAndDerivativePerThreadStruct * m_ParzenWindowHistogramGetValueAndDerivativePerThreadVariables
Superclass::MovingImageConstPointer MovingImageConstPointer
AdvancedImageToImageMetric< TFixedImage, TMovingImage > Superclass
Superclass::GradientImageFilterPointer GradientImageFilterPointer
Superclass::GradientImagePointer GradientImagePointer


Generated on 04-09-2015 for elastix by doxygen 1.8.9.1 elastix logo