template<typename TFixedImage, typename TMovingImage, typename TVirtualImage = TFixedImage, typename TInternalComputationValueType = double, typename TMetricTraits = DefaultImageToImageMetricTraitsv4<TFixedImage, TMovingImage, TVirtualImage, TInternalComputationValueType>>
class itk::ImageToImageMetricv4< TFixedImage, TMovingImage, TVirtualImage, TInternalComputationValueType, TMetricTraits >
Computes similarity between regions of two images, using two user-supplied transforms, a 'fixed' transform and a 'moving' transform.
- Warning
- Integer-type images are not yet supported. See concept-checking in DefaultImageToImageMetricTraitsv4.
Templated over the fixed and moving image types, as well as an optional VirtualImage type to define the virtual domain. The VirtualImage type defaults to TFixedImage.
- Note
- If TFixedImage is type VectorImage, then TVirtualImage must be set separately to a non-VectorImage type, e.g. Image<unsigned char, dimension>.
If the user does not set the virtual domain explicitly, then it is created during the call to Initialize
from the fixed image by copying its information. See ObjectToObjectMetric for more discussion on the virtual domain.
At a minimum, the user must: 1) Set images using SetFixedImage and SetMovingImage. 2) Call Initialize.
Image gradient calculations
Image gradients can be calculated in one of two ways: 1) Using a gradient image filter, by setting Use
[Fixed|Moving]ImageGradientFilter to true. By default this is set as an itkGradientRecursiveGaussianImageFilter, a smoothed gradient filter. A filter uses more memory, because it calculates all gradients at once and stores them in an image. The advantage of pre-calculation is for the fixed image gradients, since they only need be calculated once, and for metrics that need to access image gradients more than once for a particular point. The fixed image gradients are only calculated once when this option is set, during Initialize
. 2) Otherwise, an image gradient calculator based on ImageFunction is used. By default the CentralDifferenceImageFunction is used. This calculation is not smoothed and gives different results than GradientRecursiveGaussianImageFilter. The advantage is that less memory is used. However for the fixed image, it means needlessly computing the image gradients at each iteration of a registration instead of just computing once at the beginning. The user can supply a different function by calling SetFixedImageGradientCalculator and/or SetMovingImageGradientCalculator.
Both image gradient calculation methods are threaded. Generally it is not recommended to use different image gradient methods for the fixed and moving images because the methods return different results.
Image Masks
Image masks are supported using SetMovingImageMask or SetFixedImageMask. If the image mask is sparse, see the comments for use of sparse point sets.
Sparse Sampling
Sparse sampling is performed by supplying an arbitrary point list over which to evaluate the metric. It's presumed that the user will be working in terms of the fixed image domain, and thus the point list is expected to be in the fixed domain. Internally, the points are transformed into the virtual domain as needed.
- Note
- The attributes/data of each point in the set are not used, but rather the point's geometric coordinates. Point sets are enabled by calling UseSampledPointSet, then the SetFixedSampledPointSet is called or SetVirtualSampledPointSet along with SetUseVirtualSampledPointSet.
-
If the point set is sparse, the option SetUse[Fixed|Moving]ImageGradientFilter typically should be disabled to avoid excessive computation. However, the gradient values of the fixed image are not cached when using a point set (there are plans for this in the future), so depending on the number of iterations (when used during optimization) and the level of sparsity, it may be more efficient to use a gradient image filter for it because it will only be calculated once.
Vector Images
To support vector images, the class must be declared using the VectorImageToImageMetricTraitsv4 class in the template declaration, as described above. Derived classes must provide special handling for vector pixel types. MeanSquaresImageToImageMetricv4 can be used as an example.
Threading
This class is threaded. Threading is handled by friend classes ImageToImageMetricv4GetValueAndDerivativeThreaderBase and ImageToImageMetricv4GetValueAndDerivativeThreader. Dense and sparse evaluation are handled by template specialization of the ImageToImageMetricv4GetValueAndDerivativeThreader::ThreadedExecution method, in order to iterate over either all points in the virtual space in the case of dense evaluation, or a list of points in the sparse case.
Methods and members of ImageToImageMetricv4 are accessed by the threading class using its m_Associate member, which points to the containing instance of ImageToImageMetricv4.
Pre- and post-processing for threaded operation is handled in ImageToImageMetricv4GetValueAndDerivativeThreaderBase::BeforeThreadedExecution, and ImageToImageMetricv4GetValueAndDerivativeThreaderBase::AfterThreadedExecution, respectively.
Derived classes:
The GetValue method may be overridden to provide better-optimized or otherwise different behavior as needed. Otherwise, the m_ComputeDerivative member should be checked to avoid computing derivatives when the caller has called GetValue(). See GetComputeDerivative() in this class and in this metric's threader class.
Derived classes must derive a threader class from ImageToImageMetricv4GetValueAndDerivativeThreader, from which a DenseGetValueAndDerivativeThreader and SparseGetValueAndDerivativeThreader must be defined. Then,
must be called in the constructor.
The ProcessPoint method of the derived threader must be overridden to provide the metric-specific evaluation.
To access methods and members within the derived metric class from the derived threader class, the user must cast m_Associate to the type of the derived metric class.
See ImageToImageMetricv4Test
for a clear example of what a derived class must implement and do.
Definition at line 174 of file itkImageToImageMetricv4.h.
|
using | ConstPointer = SmartPointer< const Self > |
|
using | DefaultFixedImageGradientCalculator = typename MetricTraits::DefaultFixedImageGradientCalculator |
|
using | DefaultFixedImageGradientFilter = typename MetricTraits::DefaultFixedImageGradientFilter |
|
using | DefaultMovingImageGradientCalculator = typename MetricTraits::DefaultMovingImageGradientCalculator |
|
using | DefaultMovingImageGradientFilter = typename MetricTraits::DefaultMovingImageGradientFilter |
|
using | DerivativeValueType = typename DerivativeType::ValueType |
|
using | FixedGradientPixelType = typename MetricTraits::FixedGradientPixelType |
|
using | FixedImageComponentGradientType = CovariantVector< typename FixedImageGradientType::ValueType, FixedImageDimension > |
|
using | FixedImageConstPointer = typename FixedImageType::ConstPointer |
|
using | FixedImageGradientCalculatorPointer = typename FixedImageGradientCalculatorType::Pointer |
|
using | FixedImageGradientCalculatorType = typename MetricTraits::FixedImageGradientCalculatorType |
|
using | FixedImageGradientFilterPointer = typename FixedImageGradientFilterType::Pointer |
|
using | FixedImageGradientFilterType = typename MetricTraits::FixedImageGradientFilterType |
|
using | FixedImageGradientImagePointer = typename FixedImageGradientImageType::Pointer |
|
using | FixedImageGradientImageType = typename MetricTraits::FixedImageGradientImageType |
|
using | FixedImageGradientType = typename MetricTraits::FixedImageGradientType |
|
using | FixedImageIndexType = typename FixedImageType::IndexType |
|
using | FixedImageMaskConstPointer = typename FixedImageMaskType::ConstPointer |
|
using | FixedImageMaskPointer = typename FixedImageMaskType::Pointer |
|
using | FixedImageMaskType = SpatialObject< Self::FixedImageDimension > |
|
using | FixedImagePixelType = typename FixedImageType::PixelType |
|
using | FixedImagePointer = typename FixedImageType::Pointer |
|
using | FixedImagePointType = typename FixedImageType::PointType |
|
using | FixedImageType = TFixedImage |
|
using | FixedInterpolatorPointer = typename FixedInterpolatorType::Pointer |
|
using | FixedInterpolatorType = InterpolateImageFunction< FixedImageType, CoordinateRepresentationType > |
|
using | FixedPixelType = FixedImagePixelType |
|
using | FixedRealType = typename MetricTraits::FixedRealType |
|
using | FixedSampledPointSetConstPointer = typename FixedSampledPointSetType::ConstPointer |
|
using | FixedSampledPointSetPointer = typename FixedSampledPointSetType::Pointer |
|
using | FixedSampledPointSetType = PointSet< typename FixedImageType::PixelType, Self::FixedImageDimension > |
|
using | FixedScalarRealType = typename NumericTraits< FixedRealType >::ScalarRealType |
|
using | ImageDimensionType = typename Superclass::DimensionType |
|
using | InternalComputationValueType = TInternalComputationValueType |
|
using | MetricTraits = TMetricTraits |
|
using | MovingGradientPixelType = typename MetricTraits::MovingGradientPixelType |
|
using | MovingImageComponentGradientType = CovariantVector< typename MovingImageGradientType::ValueType, MovingImageDimension > |
|
using | MovingImageConstPointer = typename MovingImageType::ConstPointer |
|
using | MovingImageGradientCalculatorPointer = typename MovingImageGradientCalculatorType::Pointer |
|
using | MovingImageGradientCalculatorType = typename MetricTraits::MovingImageGradientCalculatorType |
|
using | MovingImageGradientFilterPointer = typename MovingImageGradientFilterType::Pointer |
|
using | MovingImageGradientFilterType = typename MetricTraits::MovingImageGradientFilterType |
|
using | MovingImageGradientImagePointer = typename MovingImageGradientImageType::Pointer |
|
using | MovingImageGradientImageType = typename MetricTraits::MovingImageGradientImageType |
|
using | MovingImageGradientType = typename MetricTraits::MovingImageGradientType |
|
using | MovingImageIndexType = typename MovingImageType::IndexType |
|
using | MovingImageMaskConstPointer = typename MovingImageMaskType::ConstPointer |
|
using | MovingImageMaskPointer = typename MovingImageMaskType::Pointer |
|
using | MovingImageMaskType = SpatialObject< Self::MovingImageDimension > |
|
using | MovingImagePixelType = typename MovingImageType::PixelType |
|
using | MovingImagePointer = typename MovingImageType::Pointer |
|
using | MovingImagePointType = typename MovingImageType::PointType |
|
using | MovingImageRegionType = typename MovingImageType::RegionType |
|
using | MovingImageType = TMovingImage |
|
using | MovingInterpolatorPointer = typename MovingInterpolatorType::Pointer |
|
using | MovingInterpolatorType = InterpolateImageFunction< MovingImageType, CoordinateRepresentationType > |
|
using | MovingPixelType = MovingImagePixelType |
|
using | MovingRealType = typename MetricTraits::MovingRealType |
|
using | MovingScalarRealType = typename NumericTraits< MovingRealType >::ScalarRealType |
|
using | ObjectType = typename Superclass::ObjectType |
|
using | Pointer = SmartPointer< Self > |
|
using | Self = ImageToImageMetricv4 |
|
using | Superclass = ObjectToObjectMetric< TFixedImage::ImageDimension, TMovingImage::ImageDimension, TVirtualImage, TInternalComputationValueType > |
|
using | VirtualImageComponentGradientType = CovariantVector< typename VirtualImageGradientType::ValueType, VirtualImageDimension > |
|
using | VirtualImageGradientType = typename MetricTraits::VirtualImageGradientType |
|
using | VirtualImageType = typename Superclass::VirtualImageType |
|
using | VirtualOriginType = typename Superclass::VirtualPointType |
|
using | VirtualRadiusType = typename Superclass::VirtualSizeType |
|
using | ConstPointer = SmartPointer< const Self > |
|
using | CoordinateRepresentationType = TInternalComputationValueType |
|
using | DimensionType = SizeValueType |
|
using | FixedInputPointType = typename FixedTransformType::InputPointType |
|
using | FixedOutputPointType = typename FixedTransformType::OutputPointType |
|
using | FixedTransformJacobianType = typename FixedTransformType::JacobianType |
|
using | FixedTransformParametersType = typename FixedTransformType::ParametersType |
|
using | FixedTransformPointer = typename FixedTransformType::Pointer |
|
using | FixedTransformType = Transform< TInternalComputationValueType, TVirtualImage::ImageDimension, TFixedDimension > |
|
using | InternalComputationValueType = TInternalComputationValueType |
|
using | JacobianType = typename FixedTransformType::JacobianType |
|
using | MetricCategoryType = typename Superclass::MetricCategoryEnum |
|
using | MovingDisplacementFieldTransformType = DisplacementFieldTransform< CoordinateRepresentationType, Self::MovingDimension > |
|
using | MovingInputPointType = typename MovingTransformType::InputPointType |
|
using | MovingOutputPointType = typename MovingTransformType::OutputPointType |
|
using | MovingTransformJacobianType = typename MovingTransformType::JacobianType |
|
using | MovingTransformParametersType = typename MovingTransformType::ParametersType |
|
using | MovingTransformPointer = typename MovingTransformType::Pointer |
|
using | MovingTransformType = Transform< TInternalComputationValueType, TVirtualImage::ImageDimension, TMovingDimension > |
|
using | ObjectType = typename Superclass::Object |
|
using | Pointer = SmartPointer< Self > |
|
using | Self = ObjectToObjectMetric |
|
using | Superclass = ObjectToObjectMetricBaseTemplate< TInternalComputationValueType > |
|
using | VirtualDirectionType = typename VirtualImageType::DirectionType |
|
using | VirtualImageConstPointer = typename VirtualImageType::ConstPointer |
|
using | VirtualImagePointer = typename VirtualImageType::Pointer |
|
using | VirtualImageType = TVirtualImage |
|
using | VirtualIndexType = typename VirtualImageType::IndexType |
|
using | VirtualOriginType = typename VirtualImageType::PointType |
|
using | VirtualPixelType = typename VirtualImageType::PixelType |
|
using | VirtualPointSetPointer = typename VirtualPointSetType::Pointer |
|
using | VirtualPointSetType = PointSet< VirtualPixelType, Self::VirtualDimension > |
|
using | VirtualPointType = typename VirtualImageType::PointType |
|
using | VirtualRadiusType = typename VirtualImageType::SizeType |
|
using | VirtualRegionType = typename VirtualImageType::RegionType |
|
using | VirtualSizeType = typename VirtualRegionType::SizeType |
|
using | VirtualSpacingType = typename VirtualImageType::SpacingType |
|
using | ConstPointer = SmartPointer< const Self > |
|
using | CoordinateRepresentationType = TInternalComputationValueType |
|
using | DerivativeValueType = typename DerivativeType::ValueType |
|
using | GradientSourceEnum = itk::ObjectToObjectMetricBaseTemplateEnums::GradientSource |
|
using | MetricCategoryEnum = itk::ObjectToObjectMetricBaseTemplateEnums::MetricCategory |
|
using | NumberOfParametersType = unsigned int |
|
using | ObjectConstPointer = typename ObjectType::ConstPointer |
|
using | ObjectType = Object |
|
using | ParametersValueType = TInternalComputationValueType |
|
using | Pointer = SmartPointer< Self > |
|
using | Self = ObjectToObjectMetricBaseTemplate |
|
using | Superclass = SingleValuedCostFunctionv4Template< TInternalComputationValueType > |
|
using | ConstPointer = SmartPointer< const Self > |
|
using | DerivativeType = Array< TInternalComputationValueType > |
|
using | MeasureType = TInternalComputationValueType |
|
using | Pointer = SmartPointer< Self > |
|
using | Self = SingleValuedCostFunctionv4Template |
|
using | Superclass = CostFunctionTemplate< TInternalComputationValueType > |
|
using | ConstPointer = SmartPointer< const Self > |
|
using | ParametersType = OptimizerParameters< TInternalComputationValueType > |
|
using | ParametersValueType = TInternalComputationValueType |
|
using | Pointer = SmartPointer< Self > |
|
using | Self = CostFunctionTemplate |
|
using | Superclass = Object |
|
using | ConstPointer = SmartPointer< const Self > |
|
using | Pointer = SmartPointer< Self > |
|
using | Self = Object |
|
using | Superclass = LightObject |
|
using | ConstPointer = SmartPointer< const Self > |
|
using | Pointer = SmartPointer< Self > |
|
using | Self = LightObject |
|
|
virtual void | FinalizeThread (const ThreadIdType) |
|
void | GetDerivative (DerivativeType &) const override |
|
virtual const FixedImageType * | GetFixedImage () const |
|
MetricCategoryType | GetMetricCategory () const override |
|
virtual FixedImageGradientImageType * | GetModifiableFixedImageGradientImage () |
|
virtual FixedInterpolatorType * | GetModifiableFixedInterpolator () |
|
virtual MovingImageGradientImageType * | GetModifiableMovingImageGradientImage () |
|
virtual MovingInterpolatorType * | GetModifiableMovingInterpolator () |
|
const char * | GetNameOfClass () const override |
|
SizeValueType | GetNumberOfDomainPoints () const |
|
virtual const SizeValueType & | GetNumberOfSkippedFixedSampledPoints () const |
|
virtual ThreadIdType | GetNumberOfWorkUnitsUsed () const |
|
MeasureType | GetValue () const override |
|
void | GetValueAndDerivative (MeasureType &value, DerivativeType &derivative) const override |
|
void | Initialize () override |
|
virtual void | SetFixedImage (const FixedImageType *_arg) |
|
virtual void | SetFixedInterpolator (FixedInterpolatorType *_arg) |
|
virtual void | SetMovingInterpolator (MovingInterpolatorType *_arg) |
|
bool | SupportsArbitraryVirtualDomainSamples () const override |
|
|
void | SetFixedObject (const ObjectType *object) override |
|
|
void | SetMovingObject (const ObjectType *object) override |
|
|
virtual void | SetMovingImage (const MovingImageType *_arg) |
|
virtual const MovingImageType * | GetMovingImage () const |
|
|
virtual void | SetMovingImageMask (const MovingImageMaskType *_arg) |
|
virtual const MovingImageMaskType * | GetMovingImageMask () const |
|
|
virtual void | SetFixedImageMask (const FixedImageMaskType *_arg) |
|
virtual const FixedImageMaskType * | GetFixedImageMask () const |
|
|
virtual void | SetFixedSampledPointSet (const FixedSampledPointSetType *_arg) |
|
virtual const FixedSampledPointSetType * | GetFixedSampledPointSet () const |
|
|
virtual void | SetVirtualSampledPointSet (VirtualPointSetType *_arg) |
|
virtual const VirtualPointSetType * | GetVirtualSampledPointSet () const |
|
|
virtual void | SetUseSampledPointSet (bool _arg) |
|
virtual const bool & | GetUseSampledPointSet () const |
|
virtual void | UseSampledPointSetOn () |
|
|
virtual void | SetUseVirtualSampledPointSet (bool _arg) |
|
virtual const bool & | GetUseVirtualSampledPointSet () const |
|
virtual void | UseVirtualSampledPointSetOn () |
|
|
virtual void | SetFixedImageGradientFilter (FixedImageGradientFilterType *_arg) |
|
virtual FixedImageGradientFilterType * | GetModifiableFixedImageGradientFilter () |
|
virtual void | SetMovingImageGradientFilter (MovingImageGradientFilterType *_arg) |
|
virtual MovingImageGradientFilterType * | GetModifiableMovingImageGradientFilter () |
|
|
virtual void | SetFixedImageGradientCalculator (FixedImageGradientCalculatorType *_arg) |
|
virtual FixedImageGradientCalculatorType * | GetModifiableFixedImageGradientCalculator () |
|
virtual void | SetMovingImageGradientCalculator (MovingImageGradientCalculatorType *_arg) |
|
virtual MovingImageGradientCalculatorType * | GetModifiableMovingImageGradientCalculator () |
|
|
virtual void | SetUseFixedImageGradientFilter (bool _arg) |
|
virtual const bool & | GetUseFixedImageGradientFilter () const |
|
virtual void | UseFixedImageGradientFilterOn () |
|
|
virtual void | SetUseMovingImageGradientFilter (bool _arg) |
|
virtual const bool & | GetUseMovingImageGradientFilter () const |
|
virtual void | UseMovingImageGradientFilterOn () |
|
|
virtual void | SetMaximumNumberOfWorkUnits (const ThreadIdType number) |
|
virtual ThreadIdType | GetMaximumNumberOfWorkUnits () const |
|
|
virtual void | SetUseFloatingPointCorrection (bool _arg) |
|
virtual const bool & | GetUseFloatingPointCorrection () const |
|
virtual void | UseFloatingPointCorrectionOn () |
|
|
virtual void | SetFloatingPointCorrectionResolution (DerivativeValueType _arg) |
|
virtual DerivativeValueType | GetFloatingPointCorrectionResolution () const |
|
OffsetValueType | ComputeParameterOffsetFromVirtualIndex (const VirtualIndexType &index, const NumberOfParametersType &numberOfLocalParameters) const |
|
OffsetValueType | ComputeParameterOffsetFromVirtualPoint (const VirtualPointType &point, const NumberOfParametersType &numberOfLocalParameters) const |
|
MetricCategoryType | GetMetricCategory () const override |
|
virtual FixedTransformType * | GetModifiableFixedTransform () |
|
virtual MovingTransformType * | GetModifiableMovingTransform () |
|
virtual VirtualImageType * | GetModifiableVirtualImage () |
|
const char * | GetNameOfClass () const override |
|
NumberOfParametersType | GetNumberOfLocalParameters () const override |
|
NumberOfParametersType | GetNumberOfParameters () const override |
|
virtual SizeValueType | GetNumberOfValidPoints () const |
|
const ParametersType & | GetParameters () const override |
|
const MovingTransformType * | GetTransform () |
|
VirtualDirectionType | GetVirtualDirection () const |
|
virtual const TimeStamp & | GetVirtualDomainTimeStamp () const |
|
VirtualOriginType | GetVirtualOrigin () const |
|
const VirtualRegionType & | GetVirtualRegion () const |
|
VirtualSpacingType | GetVirtualSpacing () const |
|
bool | HasLocalSupport () const override |
|
void | Initialize () override |
|
virtual void | SetFixedTransform (FixedTransformType *_arg) |
|
virtual void | SetMovingTransform (MovingTransformType *_arg) |
|
void | SetParameters (ParametersType ¶ms) override |
|
void | SetTransform (MovingTransformType *transform) |
|
void | SetVirtualDomain (const VirtualSpacingType &spacing, const VirtualOriginType &origin, const VirtualDirectionType &direction, const VirtualRegionType ®ion) |
|
void | SetVirtualDomainFromImage (const VirtualImageType *virtualImage) |
|
void | UpdateTransformParameters (const DerivativeType &derivative, TInternalComputationValueType factor) override |
|
bool | IsInsideVirtualDomain (const VirtualPointType &point) const |
|
bool | IsInsideVirtualDomain (const VirtualIndexType &index) const |
|
MeasureType | GetCurrentValue () const |
|
virtual GradientSourceEnum | GetGradientSource () const |
|
bool | GetGradientSourceIncludesFixed () const |
|
bool | GetGradientSourceIncludesMoving () const |
|
virtual void | SetGradientSource (GradientSourceEnum _arg) |
|
virtual const ObjectType * | GetFixedObject () const |
|
virtual const ObjectType * | GetMovingObject () const |
|
unsigned long | AddObserver (const EventObject &event, Command *cmd) const |
|
unsigned long | AddObserver (const EventObject &event, std::function< void(const EventObject &)> function) const |
|
LightObject::Pointer | CreateAnother () const override |
|
virtual void | DebugOff () const |
|
virtual void | DebugOn () const |
|
Command * | GetCommand (unsigned long tag) |
|
bool | GetDebug () const |
|
MetaDataDictionary & | GetMetaDataDictionary () |
|
const MetaDataDictionary & | GetMetaDataDictionary () const |
|
virtual ModifiedTimeType | GetMTime () const |
|
virtual const TimeStamp & | GetTimeStamp () const |
|
bool | HasObserver (const EventObject &event) const |
|
void | InvokeEvent (const EventObject &) |
|
void | InvokeEvent (const EventObject &) const |
|
virtual void | Modified () const |
|
void | Register () const override |
|
void | RemoveAllObservers () |
|
void | RemoveObserver (unsigned long tag) const |
|
void | SetDebug (bool debugFlag) const |
|
void | SetReferenceCount (int) override |
|
void | UnRegister () const noexcept override |
|
void | SetMetaDataDictionary (const MetaDataDictionary &rhs) |
|
void | SetMetaDataDictionary (MetaDataDictionary &&rrhs) |
|
virtual void | SetObjectName (std::string _arg) |
|
virtual const std::string & | GetObjectName () const |
|
Pointer | Clone () const |
|
virtual void | Delete () |
|
virtual int | GetReferenceCount () const |
|
void | Print (std::ostream &os, Indent indent=0) const |
|