20 #ifndef MIRTK_ImageSimilarity_H 21 #define MIRTK_ImageSimilarity_H 23 #include "mirtk/DataFidelity.h" 24 #include "mirtk/SimilarityMeasure.h" 25 #include "mirtk/Parallel.h" 26 #include "mirtk/FreeFormTransformation.h" 27 #include "mirtk/RegisteredImage.h" 178 const char * =
"",
double = 1.0);
222 virtual void Update(
bool =
true);
272 GradientImageType *gradient);
288 GradientImageType *gradient);
312 GradientImageType *np_gradient,
392 GradientImageType *&np_gradient,
394 double step,
double weight);
421 virtual void EvaluateGradient(
double *gradient,
double step,
double weight);
432 virtual void WriteDataSets(
const char *,
const char *,
bool =
true)
const;
435 virtual void WriteGradient(
const char *,
const char *)
const;
454 default: str =
"Unknown";
break;
464 if (lstr ==
"domain" || lstr ==
"including background" || lstr ==
"incl. background") {
466 }
else if (lstr ==
"mask") {
468 }
else if (lstr ==
"target" || lstr ==
"target foreground" || lstr ==
"excluding target background" || lstr ==
"excl. target background") {
470 }
else if (lstr ==
"overlap" || lstr ==
"intersection" || lstr ==
"excluding background" || lstr ==
"excl. background") {
472 }
else if (lstr ==
"union") {
483 if (_Foreground ==
FG_Domain || !_Mask || _Mask->Get(idx)) {
484 switch (_Foreground) {
488 if ((_Source->Transformation() ==
nullptr) != (_Target->Transformation() ==
nullptr)) {
490 return _Source->IsForeground(idx) || _Target->IsForeground(idx);
493 if (_Target->Transformation())
return _Source->IsForeground(idx);
494 else return _Target->IsForeground(idx);
496 return _Source->IsForeground(idx) && _Target->IsForeground(idx);
498 return _Source->IsForeground(idx) || _Target->IsForeground(idx);
514 #endif // MIRTK_ImageSimilarity_H mirtkPublicAttributeMacro(ImageAttributes, Domain)
Finite regular domain on which to resample images and evaluate similarity.
virtual void Update(bool=true)
Update moving input image(s) and internal state of similarity measure.
Evaluate similarity for union of foreground regions.
void MultiplyByImageGradient(const RegisteredImage *image, GradientImageType *gradient)
virtual void EvaluateGradient(RegisteredImage *image, GradientImageType *&np_gradient, double *gradient, double step, double weight)
mirtkAttributeMacro(bool, InitialUpdate)
Whether Update has not been called since initialization.
RegisteredImage::VoxelType VoxelType
Voxel type of registered images.
virtual void Print(Indent=0) const
Print debug information.
virtual void Include(const blocked_range3d< int > &)
void CopyAttributes(const ImageSimilarity &)
Copy attributes of this class from another instance.
mirtkLooseComponentMacro(RegisteredImage, Target)
(Transformed) Target image
double GradientType
Type of similarity gradient components.
ImageSimilarity & operator=(const ImageSimilarity &)
Assignment operator.
void ReleaseSource()
Release input source image.
virtual void InitializeInput(const ImageAttributes &domain)
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
virtual bool NonParametricGradient(const RegisteredImage *image, GradientImageType *gradient)
bool IsForeground(int) const
Whether to evaluate similarity at specified voxel.
void ReleaseTarget()
Release input target image.
virtual ParameterList Parameter() const
Get parameter key/value as string map.
string ToLower(const string &)
Convert string to lowercase letters.
Evaluate similarity for all voxels in domain or with non-zero mask value.
virtual void NormalizeGradient(GradientImageType *gradient)
virtual bool SetWithoutPrefix(const char *, const char *)
Set parameter value from string.
mirtkComponentMacro(GradientImageType, GradientWrtTarget)
Memory for (non-parametric) similarity gradient w.r.t target transformation.
virtual ParameterList Parameter() const
Get parameter key/value as string map.
ImageSimilarity(const char *="", double=1.0)
Constructor.
virtual void Initialize()
Initialize similarity measure once input and parameters have been set.
virtual void ParametricGradient(const RegisteredImage *image, GradientImageType *np_gradient, double *gradient, double weight)
Evaluate similarity for foreground of untransformed image.
void ApproximateGradient(RegisteredImage *image, FreeFormTransformation *ffd, double *gradient, double step, double weight)
string ToString(const EnergyMeasure &value, int w, char c, bool left)
Convert energy measure enumeration value to string.
Evaluate similarity for intersection of foreground regions.
bool FromString(const char *str, EnergyMeasure &value)
Convert energy measure string to enumeration value.
virtual void WriteDataSets(const char *, const char *, bool=true) const
Write input of data fidelity term.
GenericImage< GradientType > GradientImageType
Type of similarity gradient image.
virtual void Exclude(const blocked_range3d< int > &)
static ImageSimilarity * New(SimilarityMeasure, const char *="", double=1.0)
Instantiate specified similarity measure.
mirtkPublicAggregateMacro(BinaryImage, Mask)
virtual void WriteGradient(const char *, const char *) const
Write gradient of data fidelity term w.r.t each transformed input.
void Gradient(double *gradient, double step)
virtual ~ImageSimilarity()
Destructor.
Evaluate similarity for all voxels in image domain, ignore mask.