ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkImageRegistrationMethodv4.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 itkImageRegistrationMethodv4_h
19 #define itkImageRegistrationMethodv4_h
20 
21 #include "itkProcessObject.h"
22 
23 #include "itkCompositeTransform.h"
24 #include "itkDataObjectDecorator.h"
30 #include "itkShrinkImageFilter.h"
31 #include "itkIdentityTransform.h"
33 
34 #include <vector>
35 
36 namespace itk
37 {
38 
89 template<typename TFixedImage,
90  typename TMovingImage,
91  typename TOutputTransform = Transform<double, TFixedImage::ImageDimension, TFixedImage::ImageDimension>,
92  typename TVirtualImage = TFixedImage,
93  typename TPointSet = PointSet<unsigned int, TFixedImage::ImageDimension> >
94 class ITK_TEMPLATE_EXPORT ImageRegistrationMethodv4
95 :public ProcessObject
96 {
97 public:
98  ITK_DISALLOW_COPY_AND_ASSIGN(ImageRegistrationMethodv4);
99 
105 
107  itkNewMacro( Self );
108 
110  static constexpr unsigned int ImageDimension = TFixedImage::ImageDimension;
111 
113  itkTypeMacro( ImageRegistrationMethodv4, ProcessObject );
114 
116  using FixedImageType = TFixedImage;
117  using FixedImagePointer = typename FixedImageType::Pointer;
118  using FixedImageConstPointer = typename FixedImageType::ConstPointer;
119  using FixedImagesContainerType = std::vector<FixedImageConstPointer>;
120  using MovingImageType = TMovingImage;
121  using MovingImagePointer = typename MovingImageType::Pointer;
122  using MovingImageConstPointer = typename MovingImageType::ConstPointer;
123  using MovingImagesContainerType = std::vector<MovingImageConstPointer>;
124 
125  using PointSetType = TPointSet;
126  using PointSetConstPointer = typename PointSetType::ConstPointer;
127  using PointSetsContainerType = std::vector<PointSetConstPointer>;
128 
130  using OutputTransformType = TOutputTransform;
131  using OutputTransformPointer = typename OutputTransformType::Pointer;
132  using RealType = typename OutputTransformType::ScalarType;
133  using DerivativeType = typename OutputTransformType::DerivativeType;
134  using DerivativeValueType = typename DerivativeType::ValueType;
135 
138 
141 
144 
146 
147  using VirtualImageType = TVirtualImage;
148  using VirtualImagePointer = typename VirtualImageType::Pointer;
151 
155 
157  using FixedImageMaskConstPointer = typename FixedImageMaskType::ConstPointer;
158  using FixedImageMasksContainerType = std::vector<FixedImageMaskConstPointer>;
160  using MovingImageMaskConstPointer = typename MovingImageMaskType::ConstPointer;
161  using MovingImageMasksContainerType = std::vector<MovingImageMaskConstPointer>;
162 
171 
174 
176 
179 
183  using TransformParametersAdaptorsContainerType = std::vector<TransformParametersAdaptorPointer>;
184 
188 
191 
193  enum MetricSamplingStrategyType { NONE, REGULAR, RANDOM };
194 
196 
198  virtual void SetFixedImage( const FixedImageType *image )
199  {
200  this->SetFixedImage( 0, image );
201  }
202  virtual const FixedImageType * GetFixedImage() const
203  {
204  return this->GetFixedImage( 0 );
205  }
206  virtual void SetFixedImage( SizeValueType, const FixedImageType * );
207  virtual const FixedImageType * GetFixedImage( SizeValueType ) const;
209 
211  virtual void SetMovingImage( const MovingImageType *image )
212  {
213  this->SetMovingImage( 0, image );
214  }
215  virtual const MovingImageType * GetMovingImage() const
216  {
217  return this->GetMovingImage( 0 );
218  }
219  virtual void SetMovingImage( SizeValueType, const MovingImageType * );
220  virtual const MovingImageType * GetMovingImage( SizeValueType ) const;
222 
224  virtual void SetFixedPointSet( const PointSetType *pointSet )
225  {
226  this->SetFixedPointSet( 0, pointSet );
227  }
228  virtual const PointSetType * GetFixedPointSet() const
229  {
230  return this->GetFixedPointSet( 0 );
231  }
232  virtual void SetFixedPointSet( SizeValueType, const PointSetType * );
233  virtual const PointSetType * GetFixedPointSet( SizeValueType ) const;
235 
237  virtual void SetMovingPointSet( const PointSetType *pointSet )
238  {
239  this->SetMovingPointSet( 0, pointSet );
240  }
241  virtual const PointSetType * GetMovingPointSet() const
242  {
243  return this->GetMovingPointSet( 0 );
244  }
245  virtual void SetMovingPointSet( SizeValueType, const PointSetType * );
246  virtual const PointSetType * GetMovingPointSet( SizeValueType ) const;
248 
250  itkSetObjectMacro( Optimizer, OptimizerType );
251  itkGetModifiableObjectMacro( Optimizer, OptimizerType );
253 
262  void SetOptimizerWeights( OptimizerWeightsType & );
263  itkGetConstMacro( OptimizerWeights, OptimizerWeightsType );
265 
267  itkSetObjectMacro( Metric, MetricType );
268  itkGetModifiableObjectMacro( Metric, MetricType );
270 
272  itkSetMacro( MetricSamplingStrategy, MetricSamplingStrategyType );
273  itkGetConstMacro( MetricSamplingStrategy, MetricSamplingStrategyType );
275 
287  void MetricSamplingReinitializeSeed();
288  void MetricSamplingReinitializeSeed(int seed);
290 
292  void SetMetricSamplingPercentage( const RealType );
293 
295  virtual void SetMetricSamplingPercentagePerLevel( const MetricSamplingPercentageArrayType &samplingPercentages );
296  itkGetConstMacro( MetricSamplingPercentagePerLevel, MetricSamplingPercentageArrayType );
298 
300  itkSetGetDecoratedObjectInputMacro( FixedInitialTransform, InitialTransformType );
301 
303  itkSetGetDecoratedObjectInputMacro( MovingInitialTransform, InitialTransformType );
304 
320  itkSetGetDecoratedObjectInputMacro(InitialTransform, InitialTransformType);
321 
323  void SetTransformParametersAdaptorsPerLevel( TransformParametersAdaptorsContainerType & );
324  const TransformParametersAdaptorsContainerType & GetTransformParametersAdaptorsPerLevel() const;
326 
334  void SetNumberOfLevels( const SizeValueType );
335  itkGetConstMacro( NumberOfLevels, SizeValueType );
337 
346  {
347  for( unsigned int level = 0; level < factors.Size(); ++level )
348  {
350  shrinkFactors.Fill( factors[level] );
351  this->SetShrinkFactorsPerDimension( level, shrinkFactors );
352  }
353  }
355 
360  {
361  if( level >= this->m_ShrinkFactorsPerLevel.size() )
362  {
363  itkExceptionMacro( "Requesting level greater than the number of levels." );
364  }
365  return this->m_ShrinkFactorsPerLevel[level];
366  }
368 
373  {
374  if( level >= this->m_ShrinkFactorsPerLevel.size() )
375  {
376  this->m_ShrinkFactorsPerLevel.resize( level + 1 );
377  }
378  this->m_ShrinkFactorsPerLevel[level] = factors;
379  this->Modified();
380  }
382 
388  itkSetMacro( SmoothingSigmasPerLevel, SmoothingSigmasArrayType );
389  itkGetConstMacro( SmoothingSigmasPerLevel, SmoothingSigmasArrayType );
391 
396  itkSetMacro( SmoothingSigmasAreSpecifiedInPhysicalUnits, bool );
397  itkGetConstMacro( SmoothingSigmasAreSpecifiedInPhysicalUnits, bool );
398  itkBooleanMacro( SmoothingSigmasAreSpecifiedInPhysicalUnits );
400 
403  using Superclass::MakeOutput;
404  DataObjectPointer MakeOutput( DataObjectPointerArraySizeType ) override;
405 
407  virtual DecoratedOutputTransformType * GetOutput();
408  virtual const DecoratedOutputTransformType * GetOutput() const;
410 
411  virtual DecoratedOutputTransformType * GetTransformOutput() { return this->GetOutput(); }
412  virtual const DecoratedOutputTransformType * GetTransformOutput() const { return this->GetOutput(); }
413 
414  virtual OutputTransformType * GetModifiableTransform();
415  virtual const OutputTransformType * GetTransform() const;
416 
418  itkGetConstMacro( CurrentLevel, SizeValueType );
419 
421  itkGetConstReferenceMacro( CurrentIteration, SizeValueType );
422 
423  /* Get the current metric value. This is a helper function for reporting observations. */
424  itkGetConstReferenceMacro( CurrentMetricValue, RealType );
425 
427  itkGetConstReferenceMacro( CurrentConvergenceValue, RealType );
428 
430  itkGetConstReferenceMacro( IsConverged, bool );
431 
435  itkSetMacro( InPlace, bool );
436  itkGetConstMacro( InPlace, bool );
437  itkBooleanMacro( InPlace );
439 
445  itkBooleanMacro( InitializeCenterOfLinearOutputTransform );
446  itkSetMacro( InitializeCenterOfLinearOutputTransform, bool );
447  itkGetConstMacro( InitializeCenterOfLinearOutputTransform, bool );
449 
462  void InitializeCenterOfLinearOutputTransform();
463 
464 protected:
466  ~ImageRegistrationMethodv4() override = default;
467  void PrintSelf( std::ostream & os, Indent indent ) const override;
468 
470  void GenerateData() override;
471 
472  virtual void AllocateOutputs();
473 
475  virtual void InitializeRegistrationAtEachLevel( const SizeValueType );
476 
478  virtual VirtualImageBaseConstPointer GetCurrentLevelVirtualDomainImage();
479 
481  virtual void SetMetricSamplePoints();
482 
489 
499 
503 
509  std::vector<ShrinkFactorsPerDimensionContainerType> m_ShrinkFactorsPerLevel;
512 
516 
517 
519 
521 
522  //TODO: m_OutputTransform should be removed and replaced with a named input parameter for
523  // the pipeline
525 
526 
527 private:
528  bool m_InPlace;
529 
531 
532  // helper function to create the right kind of concrete transform
533  template<typename TTransform>
535  {
536  ptr = TTransform::New();
537  }
538 
540  {
542  }
543 
544 };
545 } // end namespace itk
546 
547 #ifndef ITK_MANUAL_INSTANTIATION
548 #include "itkImageRegistrationMethodv4.hxx"
549 #endif
550 
551 #endif
typename MovingImageType::ConstPointer MovingImageConstPointer
Light weight base class for most itk classes.
virtual DecoratedOutputTransformType * GetTransformOutput()
std::vector< FixedImageMaskConstPointer > FixedImageMasksContainerType
typename VirtualImageType::Pointer VirtualImagePointer
virtual void SetMovingImage(const MovingImageType *image)
typename DecoratedInitialTransformType::Pointer DecoratedInitialTransformPointer
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
virtual void SetMovingPointSet(const PointSetType *pointSet)
typename CompositeTransformType::Pointer CompositeTransformPointer
typename OutputTransformType::DerivativeType DerivativeType
MovingImageMasksContainerType m_MovingImageMasks
unsigned long SizeValueType
Definition: itkIntTypes.h:83
This class takes one ore more ObjectToObject metrics and assigns weights to their derivatives to comp...
virtual const PointSetType * GetFixedPointSet() const
ObjectType * GetPointer() const noexcept
Computes similarity between two point sets.
typename PointSetType::ConstPointer PointSetConstPointer
std::vector< MovingImageConstPointer > MovingImagesContainerType
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
std::vector< TransformParametersAdaptorPointer > TransformParametersAdaptorsContainerType
typename TransformParametersAdaptorType::Pointer TransformParametersAdaptorPointer
typename ImageMetricType::FixedImageMaskType FixedImageMaskType
typename FixedImageType::ConstPointer FixedImageConstPointer
Base helper class intended for multi-resolution image registration.
typename VirtualImageBaseType::ConstPointer VirtualImageBaseConstPointer
Base class for all object-to-object similarlity metrics added in ITKv4.
std::vector< ShrinkFactorsPerDimensionContainerType > m_ShrinkFactorsPerLevel
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:40
void SetShrinkFactorsPerLevel(ShrinkFactorsArrayType factors)
static Pointer New()
typename MovingImageType::Pointer MovingImagePointer
typename InitialTransformType::Pointer InitialTransformPointer
MetricSamplingPercentageArrayType m_MetricSamplingPercentagePerLevel
virtual void SetFixedPointSet(const PointSetType *pointSet)
MovingImagesContainerType m_MovingSmoothImages
std::vector< MovingImageMaskConstPointer > MovingImageMasksContainerType
std::vector< PointSetConstPointer > PointSetsContainerType
static void MakeOutputTransform(SmartPointer< TTransform > &ptr)
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:83
ShrinkFactorsPerDimensionContainerType GetShrinkFactorsPerDimension(const unsigned int level) const
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
virtual const FixedImageType * GetFixedImage() const
typename OptimizerType::ScalesType OptimizerWeightsType
SizeValueType Size() const
Definition: itkArray.h:120
This class contains a list of transforms and concatenates them by composition.
Decorates any subclass of itkObject with a DataObject API.
static void MakeOutputTransform(SmartPointer< InitialTransformType > &ptr)
Implementation of the composite pattern.
typename DerivativeType::ValueType DerivativeValueType
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition: itkPointSet.h:84
typename ShrinkFilterType::ShrinkFactorsType ShrinkFactorsPerDimensionContainerType
Generic representation for an optimization method.
Definition: itkOptimizer.h:38
typename DecoratedOutputTransformType::Pointer DecoratedOutputTransformPointer
std::vector< FixedImageConstPointer > FixedImagesContainerType
TransformParametersAdaptorsContainerType m_TransformParametersAdaptorsPerLevel
CompositeTransformPointer m_CompositeTransform
virtual void SetFixedImage(const FixedImageType *image)
void SetShrinkFactorsPerDimension(unsigned int level, ShrinkFactorsPerDimensionContainerType factors)
typename FixedImageType::Pointer FixedImagePointer
MetricSamplingStrategyType m_MetricSamplingStrategy
typename MovingImageMaskType::ConstPointer MovingImageMaskConstPointer
Base class for templated image classes.
Definition: itkImageBase.h:105
typename ImageMetricType::MovingImageMaskType MovingImageMaskType
virtual const DecoratedOutputTransformType * GetTransformOutput() const
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Reduce the size of an image by an integer factor in each dimension.
typename OutputTransformType::ScalarType RealType
SmoothingSigmasArrayType m_SmoothingSigmasPerLevel
typename ImageMetricType::FixedSampledPointSetType MetricSamplePointSetType
virtual const PointSetType * GetMovingPointSet() const
FixedImageMasksContainerType m_FixedImageMasks
Interface method for the current registration framework.
Abstract base for object-to-object optimizers.
typename MetricType::Pointer MetricPointer
virtual const MovingImageType * GetMovingImage() const
typename OptimizerType::Pointer OptimizerPointer
typename OutputTransformType::Pointer OutputTransformPointer
typename FixedImageMaskType::ConstPointer FixedImageMaskConstPointer