go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkAdvancedImageToImageMetric.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 __itkAdvancedImageToImageMetric_h
19 #define __itkAdvancedImageToImageMetric_h
20 
21 #include "itkImageToImageMetric.h"
22 
23 #include "itkImageSamplerBase.h"
24 #include "itkGradientImageFilter.h"
25 #include "itkBSplineInterpolateImageFunction.h"
28 #include "itkLimiterFunctionBase.h"
29 #include "itkFixedArray.h"
30 #include "itkAdvancedTransform.h"
31 #include "vnl/vnl_sparse_matrix.h"
32 
33 // Needed for checking for B-spline for faster implementation
36 
37 #include "itkMultiThreader.h"
38 
39 namespace itk
40 {
41 
78 template< class TFixedImage, class TMovingImage >
80  public ImageToImageMetric< TFixedImage, TMovingImage >
81 {
82 public:
83 
86  typedef ImageToImageMetric< TFixedImage, TMovingImage > Superclass;
88  typedef SmartPointer< const Self > ConstPointer;
89 
91  itkTypeMacro( AdvancedImageToImageMetric, ImageToImageMetric );
92 
94  itkStaticConstMacro( MovingImageDimension, unsigned int,
95  TMovingImage::ImageDimension );
96  itkStaticConstMacro( FixedImageDimension, unsigned int,
97  TFixedImage::ImageDimension );
98 
100  typedef typename Superclass::CoordinateRepresentationType CoordinateRepresentationType;
101  typedef typename Superclass::MovingImageType MovingImageType;
102  typedef typename Superclass::MovingImagePixelType MovingImagePixelType;
103  typedef typename MovingImageType::Pointer MovingImagePointer;
104  typedef typename Superclass::MovingImageConstPointer MovingImageConstPointer;
105  typedef typename Superclass::FixedImageType FixedImageType;
106  typedef typename FixedImageType::Pointer FixedImagePointer;
107  typedef typename Superclass::FixedImageConstPointer FixedImageConstPointer;
108  typedef typename Superclass::FixedImageRegionType FixedImageRegionType;
109  typedef typename Superclass::TransformType TransformType;
110  typedef typename Superclass::TransformPointer TransformPointer;
111  typedef typename Superclass::InputPointType InputPointType;
112  typedef typename Superclass::OutputPointType OutputPointType;
113  typedef typename Superclass::TransformParametersType TransformParametersType;
114  typedef typename Superclass::TransformJacobianType TransformJacobianType;
115  typedef typename Superclass::InterpolatorType InterpolatorType;
116  typedef typename Superclass::InterpolatorPointer InterpolatorPointer;
117  typedef typename Superclass::RealType RealType;
118  typedef typename Superclass::GradientPixelType GradientPixelType;
119  typedef typename Superclass::GradientImageType GradientImageType;
120  typedef typename Superclass::GradientImagePointer GradientImagePointer;
121  typedef typename Superclass::GradientImageFilterType GradientImageFilterType;
122  typedef typename Superclass::GradientImageFilterPointer GradientImageFilterPointer;
123  typedef typename Superclass::FixedImageMaskType FixedImageMaskType;
124  typedef typename Superclass::FixedImageMaskPointer FixedImageMaskPointer;
125  typedef typename Superclass::MovingImageMaskType MovingImageMaskType;
126  typedef typename Superclass::MovingImageMaskPointer MovingImageMaskPointer;
127  typedef typename Superclass::MeasureType MeasureType;
128  typedef typename Superclass::DerivativeType DerivativeType;
129  typedef typename DerivativeType::ValueType DerivativeValueType;
130  typedef typename Superclass::ParametersType ParametersType;
131 
133  typedef typename FixedImageType::PixelType FixedImagePixelType;
134  typedef typename MovingImageType::RegionType MovingImageRegionType;
136 
142 
150 
152  typedef typename TransformType::ScalarType ScalarType;
153  typedef AdvancedTransform<
154  ScalarType, FixedImageDimension, MovingImageDimension > AdvancedTransformType;
156 
165 
167  typedef typename DerivativeType::ValueType HessianValueType;
168  typedef vnl_sparse_matrix< HessianValueType > HessianType;
169 
171  typedef itk::MultiThreader ThreaderType;
172  typedef typename ThreaderType::ThreadInfoStruct ThreadInfoType;
173 
177  virtual void SetTransform( AdvancedTransformType * arg )
178  {
179  this->Superclass::SetTransform( arg );
180  if( this->m_AdvancedTransform != arg )
181  {
182  this->m_AdvancedTransform = arg;
183  this->Modified();
184  }
185  }
186 
187 
189  const AdvancedTransformType * GetTransform( void ) const ITK_OVERRIDE
190  {
191  return this->m_AdvancedTransform.GetPointer();
192  }
193 
194 
196  itkSetObjectMacro( ImageSampler, ImageSamplerType );
197  virtual ImageSamplerType * GetImageSampler( void ) const
198  {
199  return this->m_ImageSampler.GetPointer();
200  }
201 
202 
205  itkGetConstMacro( UseImageSampler, bool );
206 
210  itkSetMacro( RequiredRatioOfValidSamples, double );
211  itkGetConstMacro( RequiredRatioOfValidSamples, double );
212 
215  itkSetObjectMacro( MovingImageLimiter, MovingImageLimiterType );
216  itkGetConstObjectMacro( MovingImageLimiter, MovingImageLimiterType );
217  itkSetObjectMacro( FixedImageLimiter, FixedImageLimiterType );
218  itkGetConstObjectMacro( FixedImageLimiter, FixedImageLimiterType );
219 
226  itkSetMacro( MovingLimitRangeRatio, double );
227  itkGetConstMacro( MovingLimitRangeRatio, double );
228  itkSetMacro( FixedLimitRangeRatio, double );
229  itkGetConstMacro( FixedLimitRangeRatio, double );
230 
233  itkGetConstMacro( UseFixedImageLimiter, bool );
234  itkGetConstMacro( UseMovingImageLimiter, bool );
235 
243  itkSetMacro( UseMovingImageDerivativeScales, bool );
244  itkGetConstMacro( UseMovingImageDerivativeScales, bool );
245 
246  itkSetMacro( ScaleGradientWithRespectToMovingImageOrientation, bool );
247  itkGetConstMacro( ScaleGradientWithRespectToMovingImageOrientation, bool );
248 
249  itkSetMacro( MovingImageDerivativeScales, MovingImageDerivativeScalesType );
250  itkGetConstReferenceMacro( MovingImageDerivativeScales, MovingImageDerivativeScalesType );
251 
260  virtual void Initialize( void ) throw ( ExceptionObject ) ITK_OVERRIDE;
261 
265  virtual void GetSelfHessian( const TransformParametersType & parameters, HessianType & H ) const;
266 
268  virtual void SetNumberOfThreads( ThreadIdType numberOfThreads );
269 
271  itkSetMacro( UseMetricSingleThreaded, bool );
272  itkGetConstReferenceMacro( UseMetricSingleThreaded, bool );
273  itkBooleanMacro( UseMetricSingleThreaded );
274 
276  // \todo: maybe these can be united, check base class.
277  itkSetMacro( UseMultiThread, bool );
278  itkGetConstReferenceMacro( UseMultiThread, bool );
279  itkBooleanMacro( UseMultiThread );
280 
287  const TransformParametersType & parameters ) const;
288 
289 protected:
290 
293 
295  virtual ~AdvancedImageToImageMetric();
296 
298  void PrintSelf( std::ostream & os, Indent indent ) const;
299 
303  typedef typename FixedImageType::IndexType FixedImageIndexType;
304  typedef typename FixedImageIndexType::IndexValueType FixedImageIndexValueType;
305  typedef typename MovingImageType::IndexType MovingImageIndexType;
306  typedef typename TransformType::InputPointType FixedImagePointType;
307  typedef typename TransformType::OutputPointType MovingImagePointType;
308  typedef typename InterpolatorType::ContinuousIndexType MovingImageContinuousIndexType;
309 
311  typedef BSplineInterpolateImageFunction<
313  typedef typename BSplineInterpolatorType::Pointer BSplineInterpolatorPointer;
314  typedef BSplineInterpolateImageFunction<
316  typedef typename BSplineInterpolatorFloatType::Pointer BSplineInterpolatorFloatPointer;
321  MovingImageType, CoordinateRepresentationType > LinearInterpolatorType;
323  typedef typename BSplineInterpolatorType::CovariantVectorType MovingImageDerivativeType;
324  typedef GradientImageFilter<
326  typedef typename CentralDifferenceGradientFilterType::Pointer CentralDifferenceGradientFilterPointer;
327 
329  typedef typename
331 
337  mutable ImageSamplerPointer m_ImageSampler;
338 
344  LinearInterpolatorPointer m_LinearInterpolator;
345  BSplineInterpolatorPointer m_BSplineInterpolator;
346  BSplineInterpolatorFloatPointer m_BSplineInterpolatorFloat;
347  ReducedBSplineInterpolatorPointer m_ReducedBSplineInterpolator;
348 
349  CentralDifferenceGradientFilterPointer m_CentralDifferenceGradientFilter;
350 
354  mutable bool m_TransformIsBSpline;
355 
357  FixedImageLimiterPointer m_FixedImageLimiter;
358  MovingImageLimiterPointer m_MovingImageLimiter;
359  FixedImagePixelType m_FixedImageTrueMin;
360  FixedImagePixelType m_FixedImageTrueMax;
361  MovingImagePixelType m_MovingImageTrueMin;
362  MovingImagePixelType m_MovingImageTrueMax;
363  FixedImageLimiterOutputType m_FixedImageMinLimit;
364  FixedImageLimiterOutputType m_FixedImageMaxLimit;
365  MovingImageLimiterOutputType m_MovingImageMinLimit;
366  MovingImageLimiterOutputType m_MovingImageMaxLimit;
367 
371  virtual inline void ThreadedGetValue( ThreadIdType threadID ){}
372 
374  virtual inline void AfterThreadedGetValue( MeasureType & value ) const {}
375 
377  static ITK_THREAD_RETURN_TYPE GetValueThreaderCallback( void * arg );
378 
380  void LaunchGetValueThreaderCallback( void ) const;
381 
383  virtual inline void ThreadedGetValueAndDerivative(
384  ThreadIdType threadID ){}
385 
388  MeasureType & value, DerivativeType & derivative ) const {}
389 
391  static ITK_THREAD_RETURN_TYPE GetValueAndDerivativeThreaderCallback( void * arg );
392 
395 
397  static ITK_THREAD_RETURN_TYPE AccumulateDerivativesThreaderCallback( void * arg );
398 
403 
408  {
409  // To give the threads access to all members.
411  // Used for accumulating derivatives
412  DerivativeValueType * st_DerivativePointer;
413  DerivativeValueType st_NormalizationFactor;
414  };
415  mutable MultiThreaderParameterType m_ThreaderMetricParameters;
416 
426  // test per thread struct with padding and alignment
428  {
430  MeasureType st_Value;
431  };
432  itkPadStruct( ITK_CACHE_LINE_ALIGNMENT, GetValuePerThreadStruct,
433  PaddedGetValuePerThreadStruct );
434  itkAlignedTypedef( ITK_CACHE_LINE_ALIGNMENT, PaddedGetValuePerThreadStruct,
435  AlignedGetValuePerThreadStruct );
436  mutable AlignedGetValuePerThreadStruct * m_GetValuePerThreadVariables;
438 
439  // test per thread struct with padding and alignment
441  {
443  MeasureType st_Value;
444  DerivativeType st_Derivative;
445  };
446  itkPadStruct( ITK_CACHE_LINE_ALIGNMENT, GetValueAndDerivativePerThreadStruct,
447  PaddedGetValueAndDerivativePerThreadStruct );
448  itkAlignedTypedef( ITK_CACHE_LINE_ALIGNMENT, PaddedGetValueAndDerivativePerThreadStruct,
449  AlignedGetValueAndDerivativePerThreadStruct );
450  mutable AlignedGetValueAndDerivativePerThreadStruct * m_GetValueAndDerivativePerThreadVariables;
452 
454  virtual void InitializeThreadingParameters( void ) const;
455 
461  virtual void InitializeImageSampler( void ) throw ( ExceptionObject );
462 
465  itkSetMacro( UseImageSampler, bool );
466 
469  virtual void CheckNumberOfSamples(
470  unsigned long wanted, unsigned long found ) const;
471 
476  virtual void CheckForBSplineInterpolator( void );
477 
487  const MovingImagePointType & mappedPoint,
488  RealType & movingImageValue,
489  MovingImageDerivativeType * gradient ) const;
490 
496  const TransformJacobianType & jacobian,
497  const MovingImageDerivativeType & movingImageDerivative,
498  DerivativeType & imageJacobian ) const;
499 
506  virtual void CheckForAdvancedTransform( void );
507 
509  virtual void CheckForBSplineTransform( void ) const;
510 
515  virtual bool TransformPoint(
516  const FixedImagePointType & fixedImagePoint,
517  MovingImagePointType & mappedPoint ) const;
518 
525  virtual bool EvaluateTransformJacobian(
526  const FixedImagePointType & fixedImagePoint,
527  TransformJacobianType & jacobian,
528  NonZeroJacobianIndicesType & nzji ) const;
529 
531  virtual bool IsInsideMovingMask( const MovingImagePointType & point ) const;
532 
538  virtual void ComputeFixedImageExtrema(
539  const FixedImageType * image,
540  const FixedImageRegionType & region );
541 
545  virtual void ComputeMovingImageExtrema(
546  const MovingImageType * image,
547  const MovingImageRegionType & region );
548 
551  virtual void InitializeLimiters( void );
552 
555  itkSetMacro( UseFixedImageLimiter, bool );
556  itkSetMacro( UseMovingImageLimiter, bool );
557 
558 private:
559 
560  AdvancedImageToImageMetric( const Self & ); // purposely not implemented
561  void operator=( const Self & ); // purposely not implemented
562 
572 
573  MovingImageDerivativeScalesType m_MovingImageDerivativeScales;
574 
575 };
576 
577 } // end namespace itk
578 
579 #ifndef ITK_MANUAL_INSTANTIATION
580 #include "itkAdvancedImageToImageMetric.hxx"
581 #endif
582 
583 #endif // end #ifndef __itkAdvancedImageToImageMetric_h
This class combines two transforms: an &#39;initial transform&#39; with a &#39;current transform&#39;.
ImageToImageMetric< TFixedImage, TMovingImage > Superclass
AdvancedTransformType::NumberOfParametersType NumberOfParametersType
MovingImageDerivativeScalesType m_MovingImageDerivativeScales
AdvancedTransform< ScalarType, FixedImageDimension, MovingImageDimension > AdvancedTransformType
AlignedGetValuePerThreadStruct * m_GetValuePerThreadVariables
Deformable transform using a B-spline representation.
virtual void CheckForAdvancedTransform(void)
LimiterFunctionBase< RealType, FixedImageDimension > FixedImageLimiterType
Superclass::CoordinateRepresentationType CoordinateRepresentationType
Superclass::TransformParametersType TransformParametersType
void operator=(const Self &)
Superclass::FixedImageMaskPointer FixedImageMaskPointer
An extension of the ITK ImageToImageMetric. It is the intended base class for all elastix metrics...
BSplineOrder3TransformType::Pointer BSplineOrder3TransformPointer
virtual void CheckForBSplineInterpolator(void)
std::vector< unsigned long > NonZeroJacobianIndicesType
virtual void ComputeFixedImageExtrema(const FixedImageType *image, const FixedImageRegionType &region)
virtual void InitializeLimiters(void)
virtual void ThreadedGetValueAndDerivative(ThreadIdType threadID)
void LaunchGetValueThreaderCallback(void) const
ReducedDimensionBSplineInterpolateImageFunction< MovingImageType, CoordinateRepresentationType, double > ReducedBSplineInterpolatorType
virtual void Initialize(void) ITK_OVERRIDE
static ITK_THREAD_RETURN_TYPE GetValueThreaderCallback(void *arg)
AdvancedCombinationTransform< ScalarType, FixedImageDimension > CombinationTransformType
BSplineInterpolateImageFunction< MovingImageType, CoordinateRepresentationType, float > BSplineInterpolatorFloatType
virtual bool IsInsideMovingMask(const MovingImagePointType &point) const
Superclass::GradientPixelType GradientPixelType
static ITK_THREAD_RETURN_TYPE AccumulateDerivativesThreaderCallback(void *arg)
virtual void CheckNumberOfSamples(unsigned long wanted, unsigned long found) const
FixedImageLimiterOutputType m_FixedImageMinLimit
FixedImageLimiterType::OutputType FixedImageLimiterOutputType
AdvancedLinearInterpolateImageFunction< MovingImageType, CoordinateRepresentationType > LinearInterpolatorType
Superclass::FixedImageRegionType FixedImageRegionType
ReducedBSplineInterpolatorType::Pointer ReducedBSplineInterpolatorPointer
virtual void BeforeThreadedGetValueAndDerivative(const TransformParametersType &parameters) const
AdvancedTransformType::Pointer m_AdvancedTransform
virtual ImageSamplerType * GetImageSampler(void) const
ImageSamplerType::OutputVectorContainerType ImageSampleContainerType
MovingImageType::IndexType MovingImageIndexType
void PrintSelf(std::ostream &os, Indent indent) const
InterpolatorType::ContinuousIndexType MovingImageContinuousIndexType
TransformType::InputPointType FixedImagePointType
virtual void EvaluateTransformJacobianInnerProduct(const TransformJacobianType &jacobian, const MovingImageDerivativeType &movingImageDerivative, DerivativeType &imageJacobian) const
AlignedGetValueAndDerivativePerThreadStruct * m_GetValueAndDerivativePerThreadVariables
FixedArray< double, Self::MovingImageDimension > MovingImageDerivativeScalesType
This class is a base class for any image sampler.
BSplineInterpolateImageFunction< MovingImageType, CoordinateRepresentationType, double > BSplineInterpolatorType
ImageSamplerBase< FixedImageType > ImageSamplerType
FixedImageLimiterOutputType m_FixedImageMaxLimit
SmartPointer< Self > Pointer
AdvancedTransformType::NonZeroJacobianIndicesType NonZeroJacobianIndicesType
const AdvancedTransformType * GetTransform(void) const ITK_OVERRIDE
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.
BSplineInterpolatorType::Pointer BSplineInterpolatorPointer
MovingImageLimiterOutputType m_MovingImageMaxLimit
LinearInterpolatorType::Pointer LinearInterpolatorPointer
Superclass::InterpolatorPointer InterpolatorPointer
BSplineInterpolatorFloatPointer m_BSplineInterpolatorFloat
Transform maps points, vectors and covariant vectors from an input space to an output space...
FixedImageIndexType::IndexValueType FixedImageIndexValueType
BSplineInterpolatorPointer m_BSplineInterpolator
TransformType::OutputPointType MovingImagePointType
Superclass::NumberOfParametersType NumberOfParametersType
AdvancedBSplineDeformableTransform< ScalarType, FixedImageDimension, 3 > BSplineOrder3TransformType
Superclass::MovingImageMaskType MovingImageMaskType
ReducedBSplineInterpolatorPointer m_ReducedBSplineInterpolator
virtual bool EvaluateMovingImageValueAndDerivative(const MovingImagePointType &mappedPoint, RealType &movingImageValue, MovingImageDerivativeType *gradient) const
LimiterFunctionBase< RealType, MovingImageDimension > MovingImageLimiterType
Superclass::GradientImageType GradientImageType
Evaluates the B-Spline interpolation of an image. Spline order may be from 0 to 5.
Superclass::TransformPointer TransformPointer
virtual void GetSelfHessian(const TransformParametersType &parameters, HessianType &H) const
virtual void ThreadedGetValue(ThreadIdType threadID)
virtual bool TransformPoint(const FixedImagePointType &fixedImagePoint, MovingImagePointType &mappedPoint) const
virtual void SetNumberOfThreads(ThreadIdType numberOfThreads)
Superclass::GradientImageFilterType GradientImageFilterType
MovingImageType::RegionType MovingImageRegionType
MovingImageLimiterOutputType m_MovingImageMinLimit
Superclass::InterpolatorType InterpolatorType
Base class for all ITK limiter function objects.
Superclass::TransformJacobianType TransformJacobianType
virtual void AfterThreadedGetValue(MeasureType &value) const
BSplineOrder1TransformType::Pointer BSplineOrder1TransformPointer
MovingImageLimiterType::Pointer MovingImageLimiterPointer
virtual bool EvaluateTransformJacobian(const FixedImagePointType &fixedImagePoint, TransformJacobianType &jacobian, NonZeroJacobianIndicesType &nzji) const
AdvancedBSplineDeformableTransform< ScalarType, FixedImageDimension, 1 > BSplineOrder1TransformType
virtual void ComputeMovingImageExtrema(const MovingImageType *image, const MovingImageRegionType &region)
FixedImageLimiterType::Pointer FixedImageLimiterPointer
CentralDifferenceGradientFilterType::Pointer CentralDifferenceGradientFilterPointer
static ITK_THREAD_RETURN_TYPE GetValueAndDerivativeThreaderCallback(void *arg)
Superclass::MovingImagePixelType MovingImagePixelType
GradientImageFilter< MovingImageType, RealType, RealType > CentralDifferenceGradientFilterType
AdvancedBSplineDeformableTransform< ScalarType, FixedImageDimension, 2 > BSplineOrder2TransformType
Superclass::MovingImageMaskPointer MovingImageMaskPointer
MovingImageLimiterType::OutputType MovingImageLimiterOutputType
virtual void AfterThreadedGetValueAndDerivative(MeasureType &value, DerivativeType &derivative) const
BSplineInterpolatorFloatType::Pointer BSplineInterpolatorFloatPointer
ThreaderType::ThreadInfoStruct ThreadInfoType
virtual void InitializeThreadingParameters(void) const
BSplineOrder2TransformType::Pointer BSplineOrder2TransformPointer
ImageSamplerType::OutputVectorContainerPointer ImageSampleContainerPointer
Superclass::FixedImageMaskType FixedImageMaskType
void LaunchGetValueAndDerivativeThreaderCallback(void) const
MultiThreaderParameterType m_ThreaderMetricParameters
CentralDifferenceGradientFilterPointer m_CentralDifferenceGradientFilter
itkStaticConstMacro(MovingImageDimension, unsigned int, TMovingImage::ImageDimension)
BSplineInterpolatorType::CovariantVectorType MovingImageDerivativeType
Superclass::OutputType OutputType
Superclass::FixedImageConstPointer FixedImageConstPointer
virtual void CheckForBSplineTransform(void) const
itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, GetValuePerThreadStruct, PaddedGetValuePerThreadStruct)
itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedGetValuePerThreadStruct, AlignedGetValuePerThreadStruct)
Superclass::MovingImageConstPointer MovingImageConstPointer
virtual void InitializeImageSampler(void)
Linearly interpolate an image at specified positions.
virtual void SetTransform(AdvancedTransformType *arg)
Superclass::GradientImageFilterPointer GradientImageFilterPointer
vnl_sparse_matrix< HessianValueType > HessianType
Superclass::GradientImagePointer GradientImagePointer


Generated on OURCE_DATE_EPOCH for elastix by doxygen 1.8.13 elastix logo