go home Home | Main Page | Topics | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
elastix::MetricBase< TElastix > Class Template Reference

#include <elxMetricBase.h>

Detailed Description

template<typename TElastix>
class elastix::MetricBase< TElastix >

This class is the elastix base class for all Metrics.

This class contains the common functionality for all Metrics.

The parameters used in this class are:

Parameters

ShowExactMetricValue: Flag that can set to "true" or "false". If "true" the metric computes the exact metric value (computed on all voxels rather than on the set of spatial samples) and shows it each iteration. Must be given for each resolution.
example: (ShowExactMetricValue "true" "true" "false")
Default is "false" for all resolutions.

ExactMetricSampleGridSpacing: Set an integer downsampling rate for computing the "exact" metric. Only meaningful if set in combination with the ShowExactMetricValue set to "true". In some cases, it might be an overkill to really compute the exact metric with the ShowExactMetricValue. The metric computed on a downsampled image might already be accurate enough to draw conclusions about the rate of convergence for example. The downsampling rate must be given for each resolution, for each dimension.
example: (ExactMetricSampleGridSpacing 1 1 2 2 )
This example for a 2D registration of 2 resolutions sets the downsampling rate to 1 in the first resolution (so: use really all pixels), and to 2 in the second resolution. Default: 1 in each resolution and each dimension.

CheckNumberOfSamples: Whether the metric checks if at least a certain fraction (default 1/4) of the samples map inside the moving image. Can be given for each resolution or for all resolutions at once.
example: (CheckNumberOfSamples "false" "true" "false")
The default is true. In general it is wise to set this to true, since it detects if the registration is going really bad.

RequiredRatioOfValidSamples: Defines the fraction needed in CheckNumberOfSamples.
example: (RequiredRatioOfValidSamples 0.1)
The default is 0.25.

UseMultiThreadingForMetrics: Flag that can set to "true" or "false". If "true" the metric may use multi-threading (at least if multi-threading is implemented for the selected metric). If "false", it will run single-threaded. This flag will not affect the output of the metric.
example: (UseMultiThreadingForMetrics "false")
Default is "true".

Definition at line 77 of file elxMetricBase.h.

Inheritance diagram for elastix::MetricBase< TElastix >:

Public Types

using AdvancedMetricType = itk::AdvancedImageToImageMetric<FixedImageType, MovingImageType>
using CoordinateRepresentationType = typename ITKBaseType::ParametersValueType
using ElastixType
using FixedImageType = typename ElastixType::FixedImageType
using FixedPointSetType
using FixedPointType = typename FixedImageType::PointType
using FixedPointValueType = typename FixedPointType::ValueType
using ImageSamplerBaseType = typename AdvancedMetricType::ImageSamplerType
using ITKBaseType = itk::SingleValuedCostFunction
using MeasureType = typename ITKBaseType::MeasureType
using MovingImageDerivativeScalesType = typename AdvancedMetricType::MovingImageDerivativeScalesType
using MovingImageType = typename ElastixType::MovingImageType
using MovingPointSetType
using MovingPointType = typename MovingImageType::PointType
using MovingPointValueType = typename MovingPointType::ValueType
using RegistrationType
using Self = MetricBase
using Superclass = BaseComponentSE<TElastix>
Public Types inherited from elastix::BaseComponentSE< TElastix >
using ElastixType = TElastix
using RegistrationType = typename ElastixType::RegistrationBaseType
using Self = BaseComponentSE
using Superclass = BaseComponent

Public Member Functions

void AfterEachIterationBase () override
void BeforeEachResolutionBase () override
void BeforeRegistrationBase () override
virtual ImageSamplerBaseTypeGetAdvancedMetricImageSampler () const
virtual bool GetAdvancedMetricUseImageSampler () const
ITKBaseTypeGetAsITKBaseType ()
const ITKBaseTypeGetAsITKBaseType () const
virtual MeasureType GetCurrentExactMetricValue () const
virtual bool GetShowExactMetricValue () const
 ITK_DISALLOW_COPY_AND_MOVE (MetricBase)
 itkOverrideGetNameOfClassMacro (MetricBase)
 itkStaticConstMacro (FixedImageDimension, unsigned int, FixedImageType::ImageDimension)
 itkStaticConstMacro (MovingImageDimension, unsigned int, MovingImageType::ImageDimension)
virtual void SelectNewSamples ()
virtual void SetAdvancedMetricImageSampler (ImageSamplerBaseType *sampler)
Public Member Functions inherited from elastix::BaseComponentSE< TElastix >
void AddTargetCellToIterationInfo (const char *const name)
const ConfigurationGetConfiguration () const
ElastixTypeGetElastix () const
auto & GetIterationInfoAt (const char *const name)
itk::Statistics::MersenneTwisterRandomVariateGenerator & GetRandomVariateGenerator ()
RegistrationTypeGetRegistration () const
 ITK_DISALLOW_COPY_AND_MOVE (BaseComponentSE)
void RemoveTargetCellFromIterationInfo (const char *const name)
void SetConfiguration (const Configuration *_arg)
void SetElastix (ElastixType *_arg)
Public Member Functions inherited from elastix::BaseComponent
virtual void AfterEachIteration ()
virtual void AfterEachResolution ()
virtual void AfterEachResolutionBase ()
virtual void AfterRegistration ()
virtual void AfterRegistrationBase ()
virtual int BeforeAll ()
virtual int BeforeAllBase ()
virtual void BeforeEachResolution ()
virtual void BeforeRegistration ()
virtual const char * elxGetClassName () const
const char * GetComponentLabel () const
 ITK_DISALLOW_COPY_AND_MOVE (BaseComponent)
 itkVirtualGetNameOfClassMacro (BaseComponent)
void SetComponentLabel (const char *label, unsigned int idx)

Protected Types

using ExactMetricImageSamplerPointer = typename ExactMetricImageSamplerType::Pointer
using ExactMetricImageSamplerType = itk::ImageGridSampler<FixedImageType>
using ExactMetricSampleGridSpacingType = typename ExactMetricImageSamplerType::SampleGridSpacingType
using ParametersType = typename ITKBaseType::ParametersType

Protected Member Functions

virtual MeasureType GetExactValue (const ParametersType &parameters)
 MetricBase ()=default
 ~MetricBase () override=default
Protected Member Functions inherited from elastix::BaseComponentSE< TElastix >
 BaseComponentSE ()=default
 ~BaseComponentSE () override=default
Protected Member Functions inherited from elastix::BaseComponent
 BaseComponent ()=default
virtual ~BaseComponent ()=default

Protected Attributes

MeasureType m_CurrentExactMetricValue { 0.0 }
unsigned int m_ExactMetricEachXNumberOfIterations { 1 }
ExactMetricSampleGridSpacingType m_ExactMetricSampleGridSpacing
ExactMetricImageSamplerPointer m_ExactMetricSampler { nullptr }
bool m_ShowExactMetricValue { false }
Protected Attributes inherited from elastix::BaseComponentSE< TElastix >
Configuration::ConstPointer m_Configuration {}
itk::WeakPointer< TElastix > m_Elastix {}
RegistrationTypem_Registration {}

Private Member Functions

 elxDeclarePureVirtualGetSelfMacro (ITKBaseType)

Additional Inherited Members

Static Public Member Functions inherited from elastix::BaseComponent
template<typename TBaseComponent>
static auto AsITKBaseType (TBaseComponent *const baseComponent) -> decltype(baseComponent->GetAsITKBaseType())
static void InitializeElastixExecutable ()
static bool IsElastixLibrary ()

Member Typedef Documentation

◆ AdvancedMetricType

template<typename TElastix>
using elastix::MetricBase< TElastix >::AdvancedMetricType = itk::AdvancedImageToImageMetric<FixedImageType, MovingImageType>

Definition at line 103 of file elxMetricBase.h.

◆ CoordinateRepresentationType

template<typename TElastix>
using elastix::MetricBase< TElastix >::CoordinateRepresentationType = typename ITKBaseType::ParametersValueType

Typedefs for point sets.

Definition at line 112 of file elxMetricBase.h.

◆ ElastixType

template<typename TElastix>
using elastix::BaseComponentSE< TElastix >::ElastixType

Elastix typedef.

Definition at line 58 of file elxBaseComponentSE.h.

◆ ExactMetricImageSamplerPointer

template<typename TElastix>
using elastix::MetricBase< TElastix >::ExactMetricImageSamplerPointer = typename ExactMetricImageSamplerType::Pointer
protected

Definition at line 214 of file elxMetricBase.h.

◆ ExactMetricImageSamplerType

template<typename TElastix>
using elastix::MetricBase< TElastix >::ExactMetricImageSamplerType = itk::ImageGridSampler<FixedImageType>
protected

The full sampler used by the GetExactValue method.

Definition at line 213 of file elxMetricBase.h.

◆ ExactMetricSampleGridSpacingType

template<typename TElastix>
using elastix::MetricBase< TElastix >::ExactMetricSampleGridSpacingType = typename ExactMetricImageSamplerType::SampleGridSpacingType
protected

Definition at line 215 of file elxMetricBase.h.

◆ FixedImageType

template<typename TElastix>
using elastix::MetricBase< TElastix >::FixedImageType = typename ElastixType::FixedImageType

Other typedef's.

Definition at line 94 of file elxMetricBase.h.

◆ FixedPointSetType

template<typename TElastix>
using elastix::MetricBase< TElastix >::FixedPointSetType
Initial value:
FixedImageDimension,
itk::DefaultStaticMeshTraits<CoordinateRepresentationType,
FixedImageDimension,
FixedImageDimension,
typename ITKBaseType::ParametersValueType CoordinateRepresentationType

Definition at line 113 of file elxMetricBase.h.

◆ FixedPointType

template<typename TElastix>
using elastix::MetricBase< TElastix >::FixedPointType = typename FixedImageType::PointType

Definition at line 95 of file elxMetricBase.h.

◆ FixedPointValueType

template<typename TElastix>
using elastix::MetricBase< TElastix >::FixedPointValueType = typename FixedPointType::ValueType

Definition at line 96 of file elxMetricBase.h.

◆ ImageSamplerBaseType

template<typename TElastix>
using elastix::MetricBase< TElastix >::ImageSamplerBaseType = typename AdvancedMetricType::ImageSamplerType

Typedefs for sampler support.

Definition at line 131 of file elxMetricBase.h.

◆ ITKBaseType

template<typename TElastix>
using elastix::MetricBase< TElastix >::ITKBaseType = itk::SingleValuedCostFunction

ITKBaseType.

Definition at line 102 of file elxMetricBase.h.

◆ MeasureType

template<typename TElastix>
using elastix::MetricBase< TElastix >::MeasureType = typename ITKBaseType::MeasureType

Return type of GetValue

Definition at line 134 of file elxMetricBase.h.

◆ MovingImageDerivativeScalesType

template<typename TElastix>
using elastix::MetricBase< TElastix >::MovingImageDerivativeScalesType = typename AdvancedMetricType::MovingImageDerivativeScalesType

Definition at line 104 of file elxMetricBase.h.

◆ MovingImageType

template<typename TElastix>
using elastix::MetricBase< TElastix >::MovingImageType = typename ElastixType::MovingImageType

Definition at line 97 of file elxMetricBase.h.

◆ MovingPointSetType

template<typename TElastix>
using elastix::MetricBase< TElastix >::MovingPointSetType
Initial value:
MovingImageDimension,
itk::DefaultStaticMeshTraits<CoordinateRepresentationType,
MovingImageDimension,
MovingImageDimension,

Definition at line 121 of file elxMetricBase.h.

◆ MovingPointType

template<typename TElastix>
using elastix::MetricBase< TElastix >::MovingPointType = typename MovingImageType::PointType

Definition at line 98 of file elxMetricBase.h.

◆ MovingPointValueType

template<typename TElastix>
using elastix::MetricBase< TElastix >::MovingPointValueType = typename MovingPointType::ValueType

Definition at line 99 of file elxMetricBase.h.

◆ ParametersType

template<typename TElastix>
using elastix::MetricBase< TElastix >::ParametersType = typename ITKBaseType::ParametersType
protected

The parameters type.

Definition at line 210 of file elxMetricBase.h.

◆ RegistrationType

template<typename TElastix>
using elastix::BaseComponentSE< TElastix >::RegistrationType

RegistrationType; NB: this is the elx::RegistrationBase not an itk::Object or something like that.

Definition at line 63 of file elxBaseComponentSE.h.

◆ Self

template<typename TElastix>
using elastix::MetricBase< TElastix >::Self = MetricBase

Standard ITK stuff.

Definition at line 83 of file elxMetricBase.h.

◆ Superclass

template<typename TElastix>
using elastix::MetricBase< TElastix >::Superclass = BaseComponentSE<TElastix>

Definition at line 84 of file elxMetricBase.h.

Constructor & Destructor Documentation

◆ MetricBase()

template<typename TElastix>
elastix::MetricBase< TElastix >::MetricBase ( )
protecteddefault

The constructor.

◆ ~MetricBase()

template<typename TElastix>
elastix::MetricBase< TElastix >::~MetricBase ( )
overrideprotecteddefault

The destructor.

Member Function Documentation

◆ AfterEachIterationBase()

template<typename TElastix>
void elastix::MetricBase< TElastix >::AfterEachIterationBase ( )
overridevirtual

Execute stuff after each iteration:

  • Optionally compute the exact metric value and plot it to screen.

Reimplemented from elastix::BaseComponent.

◆ BeforeEachResolutionBase()

template<typename TElastix>
void elastix::MetricBase< TElastix >::BeforeEachResolutionBase ( )
overridevirtual

Execute stuff before each resolution:

  • Check if the exact metric value should be computed (to monitor the progress of the registration).

Reimplemented from elastix::BaseComponent.

◆ BeforeRegistrationBase()

template<typename TElastix>
void elastix::MetricBase< TElastix >::BeforeRegistrationBase ( )
overridevirtual

Reimplemented from elastix::BaseComponent.

◆ elxDeclarePureVirtualGetSelfMacro()

template<typename TElastix>
elastix::MetricBase< TElastix >::elxDeclarePureVirtualGetSelfMacro ( ITKBaseType )
private

◆ GetAdvancedMetricImageSampler()

template<typename TElastix>
virtual ImageSamplerBaseType * elastix::MetricBase< TElastix >::GetAdvancedMetricImageSampler ( ) const
virtual

Methods to get the image sampler. The image sampler is only used when the metric is of type AdvancedMetricType, and has UseImageSampler set to true. In other cases, the function returns 0.

◆ GetAdvancedMetricUseImageSampler()

template<typename TElastix>
virtual bool elastix::MetricBase< TElastix >::GetAdvancedMetricUseImageSampler ( ) const
virtual

Returns whether the metric uses a sampler. When the metric is not of AdvancedMetricType, the function returns false immediately.

◆ GetAsITKBaseType() [1/2]

template<typename TElastix>
ITKBaseType * elastix::MetricBase< TElastix >::GetAsITKBaseType ( )
inline

Retrieves this object as ITKBaseType.

Definition at line 138 of file elxMetricBase.h.

◆ GetAsITKBaseType() [2/2]

template<typename TElastix>
const ITKBaseType * elastix::MetricBase< TElastix >::GetAsITKBaseType ( ) const
inline

Retrieves this object as ITKBaseType, to use in const functions.

Definition at line 146 of file elxMetricBase.h.

◆ GetCurrentExactMetricValue()

template<typename TElastix>
virtual MeasureType elastix::MetricBase< TElastix >::GetCurrentExactMetricValue ( ) const
inlinevirtual

Get the last computed exact metric value

Definition at line 203 of file elxMetricBase.h.

◆ GetExactValue()

template<typename TElastix>
virtual MeasureType elastix::MetricBase< TElastix >::GetExactValue ( const ParametersType & parameters)
protectedvirtual

Get the exact value. Mutual information computed over all points. It is meant in situations when you optimize using just a subset of pixels, but are interested in the exact value of the metric.

This method only works when the itkYourMetric inherits from the AdvancedMetricType. In other cases it returns 0. You may re-implement this method in the elxYourMetric, if you like.

◆ GetShowExactMetricValue()

template<typename TElastix>
virtual bool elastix::MetricBase< TElastix >::GetShowExactMetricValue ( ) const
inlinevirtual

Get if the exact metric value is computed

Definition at line 196 of file elxMetricBase.h.

◆ ITK_DISALLOW_COPY_AND_MOVE()

template<typename TElastix>
elastix::MetricBase< TElastix >::ITK_DISALLOW_COPY_AND_MOVE ( MetricBase< TElastix > )

◆ itkOverrideGetNameOfClassMacro()

template<typename TElastix>
elastix::MetricBase< TElastix >::itkOverrideGetNameOfClassMacro ( MetricBase< TElastix > )

Run-time type information (and related methods).

◆ itkStaticConstMacro() [1/2]

template<typename TElastix>
elastix::MetricBase< TElastix >::itkStaticConstMacro ( FixedImageDimension ,
unsigned int ,
FixedImageType::ImageDimension  )

Get the dimension of the fixed image.

◆ itkStaticConstMacro() [2/2]

template<typename TElastix>
elastix::MetricBase< TElastix >::itkStaticConstMacro ( MovingImageDimension ,
unsigned int ,
MovingImageType::ImageDimension  )

Get the dimension of the moving image.

◆ SelectNewSamples()

template<typename TElastix>
virtual void elastix::MetricBase< TElastix >::SelectNewSamples ( )
virtual

◆ SetAdvancedMetricImageSampler()

template<typename TElastix>
virtual void elastix::MetricBase< TElastix >::SetAdvancedMetricImageSampler ( ImageSamplerBaseType * sampler)
virtual

Method to set the image sampler. The image sampler is only used when the metric is of type AdvancedMetricType, and has UseImageSampler set to true. In other cases, the function does nothing.

Member Data Documentation

◆ m_CurrentExactMetricValue

template<typename TElastix>
MeasureType elastix::MetricBase< TElastix >::m_CurrentExactMetricValue { 0.0 }
protected

Definition at line 238 of file elxMetricBase.h.

◆ m_ExactMetricEachXNumberOfIterations

template<typename TElastix>
unsigned int elastix::MetricBase< TElastix >::m_ExactMetricEachXNumberOfIterations { 1 }
protected

Definition at line 241 of file elxMetricBase.h.

◆ m_ExactMetricSampleGridSpacing

template<typename TElastix>
ExactMetricSampleGridSpacingType elastix::MetricBase< TElastix >::m_ExactMetricSampleGridSpacing
protected
Initial value:
{ itk::MakeFilled<ExactMetricSampleGridSpacingType>(
1) }

Definition at line 239 of file elxMetricBase.h.

◆ m_ExactMetricSampler

template<typename TElastix>
ExactMetricImageSamplerPointer elastix::MetricBase< TElastix >::m_ExactMetricSampler { nullptr }
protected

Definition at line 237 of file elxMetricBase.h.

◆ m_ShowExactMetricValue

template<typename TElastix>
bool elastix::MetricBase< TElastix >::m_ShowExactMetricValue { false }
protected
Todo
the method GetExactDerivative could as well be added here.

Definition at line 236 of file elxMetricBase.h.



Generated on 26-02-2026 for elastix by doxygen 1.16.1 (669aeeefca743c148e2d935b3d3c69535c7491e6) elastix logo