Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
mirtk::ImageSimilarity Class Reference

#include <ImageSimilarity.h>

Inheritance diagram for mirtk::ImageSimilarity:
Inheritance graph
Collaboration diagram for mirtk::ImageSimilarity:
Collaboration graph

Public Types

enum  ForegroundRegion {
  FG_Domain, FG_Mask, FG_Target, FG_Overlap,
  FG_Union
}
 
typedef GenericImage< GradientTypeGradientImageType
 Type of similarity gradient image.
 
typedef double GradientType
 Type of similarity gradient components.
 
typedef RegisteredImage::VoxelType VoxelType
 Voxel type of registered images.
 
- Public Types inherited from mirtk::EnergyTerm
typedef ObjectFactory< enum EnergyMeasure, EnergyTermFactoryType
 Type of energy term factory.
 

Public Member Functions

void CopyAttributes (const ImageSimilarity &)
 Copy attributes of this class from another instance.
 
virtual void Exclude (const blocked_range3d< int > &)
 
virtual void Include (const blocked_range3d< int > &)
 
virtual void Initialize ()
 Initialize similarity measure once input and parameters have been set.
 
bool IsForeground (int) const
 Whether to evaluate similarity at specified voxel.
 
bool IsForeground (int, int, int) const
 Whether to evaluate similarity at specified voxel.
 
 mirtkAttributeMacro (bool, InitialUpdate)
 Whether Update has not been called since initialization.
 
 mirtkComponentMacro (GradientImageType, GradientWrtTarget)
 Memory for (non-parametric) similarity gradient w.r.t target transformation.
 
 mirtkComponentMacro (GradientImageType, GradientWrtSource)
 Memory for (non-parametric) similarity gradient w.r.t source transformation.
 
 mirtkComponentMacro (double, Gradient)
 Memory for (parametric) similarity gradient.
 
 mirtkLooseComponentMacro (RegisteredImage, Target)
 (Transformed) Target image
 
 mirtkLooseComponentMacro (RegisteredImage, Source)
 (Transformed) Source image
 
 mirtkPublicAggregateMacro (BinaryImage, Mask)
 
 mirtkPublicAttributeMacro (ImageAttributes, Domain)
 Finite regular domain on which to resample images and evaluate similarity.
 
 mirtkPublicAttributeMacro (ForegroundRegion, Foreground)
 Set operation used to define common foreground region of co-registered images.
 
 mirtkPublicAttributeMacro (int, NumberOfVoxels)
 Number of voxels per registered image.
 
 mirtkPublicAttributeMacro (bool, NormalizeImageGradient)
 Divide transformed image gradient by input intensity range.
 
 mirtkPublicAttributeMacro (bool, UseApproximateGradient)
 
 mirtkPublicAttributeMacro (double, VoxelWisePreconditioning)
 
 mirtkPublicAttributeMacro (double, NodeBasedPreconditioning)
 
 mirtkPublicAttributeMacro (bool, SkipTargetInitialization)
 Skip initialization of target image.
 
 mirtkPublicAttributeMacro (bool, SkipSourceInitialization)
 Skip initialization of source image.
 
virtual ParameterList Parameter () const
 Get parameter key/value as string map.
 
virtual void Print (Indent=0) const
 Print debug information.
 
void ReleaseSource ()
 Release input source image.
 
void ReleaseTarget ()
 Release input target image.
 
virtual void Update (bool=true)
 Update moving input image(s) and internal state of similarity measure.
 
virtual void WriteDataSets (const char *, const char *, bool=true) const
 Write input of data fidelity term.
 
virtual void WriteGradient (const char *, const char *) const
 Write gradient of data fidelity term w.r.t each transformed input.
 
virtual ~ImageSimilarity ()
 Destructor.
 
- Public Member Functions inherited from mirtk::DataFidelity
virtual ~DataFidelity ()
 Destructor.
 
- Public Member Functions inherited from mirtk::EnergyTerm
virtual enum EnergyMeasure EnergyMeasure () const =0
 Energy measure implemented by this term.
 
void Gradient (double *gradient, double step)
 
virtual void GradientStep (const double *gradient, double &min, double &max) const
 
double InitialValue ()
 Returns initial value of energy term.
 
void NormalizedGradient (double *gradient, double step)
 
string Prefix (const char *=NULL) const
 Prefix to be used for debug output files.
 
virtual double RawValue (double) const
 
double RawValue ()
 
void ResetInitialValue ()
 Reset initial value of energy term.
 
void ResetValue ()
 Reset cached value of energy term.
 
virtual bool Upgrade ()
 Update energy term after convergence.
 
double Value ()
 Evaluate energy term.
 
virtual ~EnergyTerm ()
 Destructor.
 
- Public Member Functions inherited from mirtk::Configurable
string DefaultName () const
 
virtual bool Set (const char *, const char *)
 Set parameter value from string.
 
virtual ~Configurable ()
 Destructor.
 
- Public Member Functions inherited from mirtk::Observable
void AddObserver (Observer &)
 Add observer.
 
void Broadcast (Event, const void *=NULL)
 Broadcast event to observers.
 
void ClearObservers ()
 Delete all observers.
 
void DeleteObserver (Observer &)
 Delete observer.
 
void NotifyObservers (Event, const void *=NULL)
 Notify all observers about given event if this object has changed.
 
int NumberOfObservers () const
 Number of current observers.
 
virtual ~Observable ()
 Destructor.
 
- Public Member Functions inherited from mirtk::Object
virtual const char * NameOfClass () const =0
 Get name of class, which this object is an instance of.
 
bool Parameter (const ParameterList &)
 Set parameters from name/value pairs.
 
virtual ~Object ()
 Destructor.
 

Static Public Member Functions

static ImageSimilarityNew (SimilarityMeasure, const char *="", double=1.0)
 Instantiate specified similarity measure.
 
- Static Public Member Functions inherited from mirtk::EnergyTerm
static FactoryTypeFactory ()
 Get global energy term factory instance.
 
static EnergyTermNew (EnergyMeasure, const char *="", double=1.0)
 Construct new energy term.
 
static EnergyTermTryNew (EnergyMeasure, const char *="", double=1.0)
 Construct new energy term or return nullptr if term not available.
 
- Static Public Member Functions inherited from mirtk::Object
static const char * NameOfType ()
 Get name of this class type.
 

Protected Member Functions

void ApproximateGradient (RegisteredImage *image, FreeFormTransformation *ffd, double *gradient, double step, double weight)
 
void ApproximateGradient (RegisteredImage *image, double *gradient, double step, double weight)
 
virtual void EvaluateGradient (RegisteredImage *image, GradientImageType *&np_gradient, double *gradient, double step, double weight)
 
virtual void EvaluateGradient (double *gradient, double step, double weight)
 
 ImageSimilarity (const char *="", double=1.0)
 Constructor.
 
 ImageSimilarity (const ImageSimilarity &)
 Copy constructor.
 
virtual void InitializeInput (const ImageAttributes &domain)
 
void MultiplyByImageGradient (const RegisteredImage *image, GradientImageType *gradient)
 
virtual bool NonParametricGradient (const RegisteredImage *image, GradientImageType *gradient)
 
virtual void NormalizeGradient (GradientImageType *gradient)
 
virtual void NormalizeGradient (const RegisteredImage *image, double *gradient)
 
ImageSimilarityoperator= (const ImageSimilarity &)
 Assignment operator.
 
virtual void ParametricGradient (const RegisteredImage *image, GradientImageType *np_gradient, double *gradient, double weight)
 
virtual bool SetWithoutPrefix (const char *, const char *)
 Set parameter value from string.
 
- Protected Member Functions inherited from mirtk::DataFidelity
 DataFidelity (const char *="", double=1.0)
 Constructor.
 
 DataFidelity (const DataFidelity &)
 Copy constructor.
 
DataFidelityoperator= (const DataFidelity &)
 Assignment operator.
 
virtual bool SetWithPrefix (const char *, const char *)
 Set parameter value from string.
 
- Protected Member Functions inherited from mirtk::EnergyTerm
 EnergyTerm (const char *="", double=1.0)
 Constructor.
 
 EnergyTerm (const EnergyTerm &)
 Copy constructor.
 
virtual double Evaluate ()=0
 Evaluate unweighted energy term.
 
EnergyTermoperator= (const EnergyTerm &)
 Assignment operator.
 
- Protected Member Functions inherited from mirtk::Configurable
 Configurable (const char *="")
 Constructor.
 
 Configurable (const Configurable &)
 Copy constructor.
 
string DefaultPrefix () const
 Get default object name prefix (if any)
 
bool HasName () const
 Whether this object has an explicit name.
 
bool HasPrefix () const
 Whether this object has either an explicit name or default prefix.
 
template<class T >
bool InsertWithPrefix (ParameterList &, string, T) const
 Insert parameter into name/value list with object name prefix.
 
bool InsertWithPrefix (ParameterList &, const ParameterList &) const
 Insert parameters into name/value list with object name prefix.
 
Configurableoperator= (const Configurable &)
 Assignment operator.
 
string ParameterNameWithoutPrefix (const char *) const
 Get name of parameter without object name prefix.
 
string ParameterNameWithPrefix (const string &) const
 Get name of parameter with default object name prefix.
 
string ParameterNameWithPrefix (const char *) const
 Get name of parameter with default object name prefix.
 
- Protected Member Functions inherited from mirtk::Observable
 Observable ()
 Default constructor.
 
 Observable (const Observable &)
 Copy constructor.
 
Observableoperator= (const Observable &)
 Assignment operator.
 
- Protected Member Functions inherited from mirtk::Object
template<typename... Args>
void Throw (ErrorType err, const char *func, Args... args) const
 

Additional Inherited Members

- Static Protected Member Functions inherited from mirtk::Object
template<typename... Args>
static void ThrowStatic (ErrorType err, const char *cls, const char *func, Args... args)
 

Detailed Description

Base class for image similarity measures

The lower the value of the similarity measure, the more similar the images are. It may therefore more precisely be referred to as dissimilarity measure, but both terms are for historic reasons used interchangeably in this framework.

If the transformed image has a foreground region defined, we assume that this corresponds to the region which needs to be matched with the untransformed image. Therefore we make use of the entire transformed foreground region to evaluate similarity and in particular the gradient forces defined within this region. Note that outside this source foreground region, the gradient is always zero and thus cannot be used to drive the image registration.

Otherwise, the region of interest is generally defined by the foreground of the untransformed image. For each such target voxel we want to find a suitable corresponding voxel in the other image. Therefore, we restrict the similarity evaluation to this region. In case of a symmetric transformation of both images, the union of the foreground of both images defines the region for which similarity is evaluated and forces are computed.

Subclasses which implement a particular similarity measure should call the IsForeground member function to decide whether or not to consider a given voxel of the grid on which the registered images are defined.

Note
The similarity measure owns the registered input images and may thus modify these to improve the runtime of each Update step.

Definition at line 61 of file ImageSimilarity.h.

Member Enumeration Documentation

§ ForegroundRegion

Enumeration of available set operations to define region within which to evaluate the image similarity given the two foreground regions of the two co-registered input images. The resulting foreground region is further intersected with the specified binary mask. When no mask is given, a mask with constant value 1 is assumed.

Enumerator
FG_Domain 

Evaluate similarity for all voxels in image domain, ignore mask.

FG_Mask 

Evaluate similarity for all voxels in domain or with non-zero mask value.

FG_Target 

Evaluate similarity for foreground of untransformed image.

FG_Overlap 

Evaluate similarity for intersection of foreground regions.

FG_Union 

Evaluate similarity for union of foreground regions.

Definition at line 83 of file ImageSimilarity.h.

Member Function Documentation

§ ApproximateGradient() [1/2]

void mirtk::ImageSimilarity::ApproximateGradient ( RegisteredImage image,
FreeFormTransformation ffd,
double *  gradient,
double  step,
double  weight 
)
protected

Approximate similarity gradient using finite differences

If the image similarity does not provide an implementation of the NonParametricGradient function, the similarity gradient is approximated instead using finite differences.

Parameters
[in]imageTransformed image.
[in]ffdFree-form deformation.
[in,out]gradientGradient to which the computed parametric gradient is added, after multiplication by the given weight.
[in]stepStep size to use for finite differences.
[in]weightWeight of image similarity.

§ ApproximateGradient() [2/2]

void mirtk::ImageSimilarity::ApproximateGradient ( RegisteredImage image,
double *  gradient,
double  step,
double  weight 
)
protected

Approximate similarity gradient using finite differences

If the image similarity does not provide an implementation of the NonParametricGradient function, the similarity gradient is approximated instead using finite differences.

Parameters
[in]imageTransformed image.
[in,out]gradientGradient to which the computed parametric gradient is added, after multiplication by the given weight.
[in]stepStep size to use for finite differences.
[in]weightWeight of image similarity.

§ EvaluateGradient() [1/2]

virtual void mirtk::ImageSimilarity::EvaluateGradient ( RegisteredImage image,
GradientImageType *&  np_gradient,
double *  gradient,
double  step,
double  weight 
)
protectedvirtual

Evaluate similarity gradient

This function calls the virtual NonParametricGradient function to be implemented by subclasses for each transformed input image to obtain the voxel-wise similarity gradient. It then converts this gradient into a gradient w.r.t the transformation parameters using the ParametricGradient.

If both target and source are transformed by different transformations, the resulting gradient vector contains first the derivative values w.r.t the parameters of the target transformation followed by those computed w.r.t the parameters of the source transformation. If both images are transformed by the same transformation, the sum of the derivative values is added to the resulting gradient vector. This is in particular the case for a velocity based transformation model which is applied to deform both images "mid-way". Otherwise, only one input image is transformed (usually the source) and the derivative values of only the respective transformation parameters added to the gradient vector.

See also
NonParametricGradient, ParametricGradient
Parameters
[in]imageTransformed image.
[in,out]np_gradientMemory for voxel-wise non-parametric gradient.
[in,out]gradientGradient to which the computed gradient of the image similarity is added after multiplying by the given similarity weight.
[in]stepStep size to use for finite differences.
[in]weightWeight of image similarity.

§ EvaluateGradient() [2/2]

virtual void mirtk::ImageSimilarity::EvaluateGradient ( double *  gradient,
double  step,
double  weight 
)
protectedvirtual

Evaluate similarity gradient

This function calls the virtual NonParametricGradient function to be implemented by subclasses for each transformed input image to obtain the voxel-wise similarity gradient. It then converts this gradient into a gradient w.r.t the transformation parameters using the ParametricGradient.

If both target and source are transformed by different transformations, the resulting gradient vector contains first the derivative values w.r.t the parameters of the target transformation followed by those computed w.r.t the parameters of the source transformation. If both images are transformed by the same transformation, the sum of the derivative values is added to the resulting gradient vector. This is in particular the case for a velocity based transformation model which is applied to deform both images "mid-way". Otherwise, only one input image is transformed (usually the source) and the derivative values of only the respective transformation parameters added to the gradient vector.

See also
NonParametricGradient, ParametricGradient
Parameters
[in,out]gradientGradient to which the computed gradient of the image similarity is added after multiplying by the given similarity weight.
[in]stepStep size to use for finite differences.
[in]weightWeight of image similarity.

Implements mirtk::EnergyTerm.

§ Exclude()

virtual void mirtk::ImageSimilarity::Exclude ( const blocked_range3d< int > &  )
virtual

Exclude region from similarity evaluation

Called by ApproximateGradient before the registered image region of the transformed image is updated.

Override in subclass for more efficient ApproximateGradient evaluation If the analytic derivation is possible and thus the NonParametericGradient function is overriden instead, this function is not used. Otherwise, if this function is not overriden to update the similarity measure, the Evaluate function must re-evaluate the similarity for all voxels.

See also
ApproximateGradient, Include

Reimplemented in mirtk::NormalizedIntensityCrossCorrelation, mirtk::HistogramImageSimilarity, and mirtk::SumOfSquaredIntensityDifferences.

§ Include()

virtual void mirtk::ImageSimilarity::Include ( const blocked_range3d< int > &  )
virtual

Include region in similarity evaluation

Called by ApproximateGradient after the registered image region of the transformed image is updated.

Override in subclass for more efficient ApproximateGradient evaluation If the analytic derivation is possible and thus the NonParametericGradient function is overriden instead, this function is not used. Otherwise, if this function is not overriden to update the similarity measure, the Evaluate function must re-evaluate the similarity for all voxels.

See also
ApproximateGradient, Exclude

Reimplemented in mirtk::NormalizedIntensityCrossCorrelation, mirtk::HistogramImageSimilarity, and mirtk::SumOfSquaredIntensityDifferences.

§ InitializeInput()

virtual void mirtk::ImageSimilarity::InitializeInput ( const ImageAttributes domain)
protectedvirtual

Initialize similarity measure once input and parameters have been set

Parameters
[in]domainImage domain on which the similarity is evaluated.

Reimplemented in mirtk::GradientFieldSimilarity.

§ mirtkPublicAggregateMacro()

mirtk::ImageSimilarity::mirtkPublicAggregateMacro ( BinaryImage  ,
Mask   
)

Mask which defines arbitrary domain on which the similarity is evaluated

Intensities outside the mask (i.e., mask value is zero) are excluded from the similarity comparison. The foreground domain of the registered image is the intersection of the domain defined by non-zero mask entries with the foreground domain used when no mask is set.

§ mirtkPublicAttributeMacro() [1/3]

mirtk::ImageSimilarity::mirtkPublicAttributeMacro ( bool  ,
UseApproximateGradient   
)

Approximate gradient using finite differences even if the similarity measure implements the NonParametricGradient function

§ mirtkPublicAttributeMacro() [2/3]

mirtk::ImageSimilarity::mirtkPublicAttributeMacro ( double  ,
VoxelWisePreconditioning   
)

Voxel-wise gradient preconditioning sigma used to supress noise. A non-positive value disables the voxel-wise preconditioning all together.

Zikic, D., Baust, M., Kamen, A., & Navab, N. A General Preconditioning Scheme for Difference Measures in Deformable Registration. In ICCV 2011.

§ mirtkPublicAttributeMacro() [3/3]

mirtk::ImageSimilarity::mirtkPublicAttributeMacro ( double  ,
NodeBasedPreconditioning   
)

Node-based (M)FFD control point gradient preconditioning sigma used to supress noise. A non-positive value disables the node-based preconditioning all together.

Zikic, D., Baust, M., Kamen, A., & Navab, N. A General Preconditioning Scheme for Difference Measures in Deformable Registration. In ICCV 2011.

§ MultiplyByImageGradient()

void mirtk::ImageSimilarity::MultiplyByImageGradient ( const RegisteredImage image,
GradientImageType gradient 
)
protected

Multiply voxel-wise similarity gradient by transformed image gradient

This function is intended for use by subclass implementations to compute the NonParametericGradient. It applies the chain rule to compute \(\frac{dSimilarity}{dy} = \frac{dSimilarity}{dI} * \frac{dI}{dy}\), given \(\frac{dSimilarity}{dI}\) as input, where \(y = T(x)\).

Parameters
[in]imageTransformed image.
[in,out]gradientInput must be the gradient of the image similarity w.r.t. the transformed image in x. Output is the voxel-wise gradient of the similarity w.r.t. T(x).

§ NonParametricGradient()

virtual bool mirtk::ImageSimilarity::NonParametricGradient ( const RegisteredImage image,
GradientImageType gradient 
)
protectedvirtual

Compute voxel-wise non-parametric similarity gradient w.r.t the given image

Must be implemented by subclasses to compute the similarity gradient. The base class implementation can be used to convert the similarity gradient computed w.r.t transformed image (i.e., dSimilarity/dI) to a voxel-wise non-parametric gradient (i.e., dSimilarity/dT). Note that the input must be a scalar field only. The base class copies the x component of the input gradient image to the y and z components before applying the chain rule.

Parameters
[in]imageTransformed image
[out]gradientNon-parametric similarity gradient.
Returns
Whether voxel-wise similarity gradient has been computed.

Reimplemented in mirtk::NormalizedIntensityCrossCorrelation, mirtk::SumOfSquaredIntensityDifferences, mirtk::NormalizedMutualImageInformation, and mirtk::CosineOfNormalizedGradientField.

§ NormalizeGradient() [1/2]

virtual void mirtk::ImageSimilarity::NormalizeGradient ( GradientImageType gradient)
protectedvirtual

Normalize voxel-wise non-parametric similarity gradient

Zikic, D., Baust, M., Kamen, A., & Navab, N. A General Preconditioning Scheme for Difference Measures in Deformable Registration. In ICCV 2011.

Parameters
[in,out]gradientNon-parametric similarity gradient.

§ NormalizeGradient() [2/2]

virtual void mirtk::ImageSimilarity::NormalizeGradient ( const RegisteredImage image,
double *  gradient 
)
protectedvirtual

Normalize node-based similarity gradient

Zikic, D., Baust, M., Kamen, A., & Navab, N. A General Preconditioning Scheme for Difference Measures in Deformable Registration. In ICCV 2011.

This function applies the normalization for FFD transformations to the gradient vectors of the control point coefficients. It does nothing for non-FFD transformations. In case of a multi-level FFD with more than one active level, it furthermore normalizes the gradient vectors across levels.

Parameters
[in]imageTransformed image.
[in,out]gradientParametric similarity gradient.

§ ParametricGradient()

virtual void mirtk::ImageSimilarity::ParametricGradient ( const RegisteredImage image,
GradientImageType np_gradient,
double *  gradient,
double  weight 
)
protectedvirtual

Convert non-parametric similarity gradient into gradient w.r.t transformation parameters

This function calls Transformation::ParametricGradient of the transformation to apply the chain rule in order to obtain the similarity gradient w.r.t the transformation parameters. It adds the weighted gradient to the final registration energy gradient.

Parameters
[in]imageTransformed image.
[in]np_gradientVoxel-wise non-parametric gradient.
[in,out]gradientGradient to which the computed parametric gradient is added, after multiplication by the given weight.
[in]weightWeight of image similarity.

Reimplemented in mirtk::GradientFieldSimilarity.


The documentation for this class was generated from the following file: