PeronaMalikErrorFunction.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 Stefan Pszczolkowski Parraguez, Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_PeronaMalikErrorFunction_H
21 #define MIRTK_PeronaMalikErrorFunction_H
22 
23 #include "mirtk/RadialErrorFunction.h"
24 #include "mirtk/Math.h"
25 
26 
27 namespace mirtk {
28 
29 
30 /**
31  * Perona and Malik fiducial registration error function
32  */
34 {
35  mirtkObjectMacro(PeronaMalikErrorFunction);
36 
37  /// Squared fiducial registration error threshold
38  mirtkPublicAttributeMacro(double, SquaredThreshold);
39 
40 public:
41 
42  /// Constructor
43  PeronaMalikErrorFunction(double threshold = 1.0)
44  :
45  _SquaredThreshold(threshold * threshold)
46  {}
47 
48  /// Copy constructor
50  :
51  _SquaredThreshold(other._SquaredThreshold)
52  {}
53 
54  /// Destructor
56 
57  /// Copy construct a new instance
59  {
60  return new PeronaMalikErrorFunction(*this);
61  }
62 
63  /// Type enumeration value
64  virtual TypeId Type() const
65  {
66  return PeronaMalik;
67  }
68 
69  /// Set parameter value from string
70  bool Set(const char *name, const char *value)
71  {
72  if (strcmp(name, "Threshold") == 0) {
73  double threshold = .0;
74  if (!FromString(value, threshold) || threshold <= .0) return false;
75  _SquaredThreshold = threshold * threshold;
76  return true;
77  } else if (strcmp(name, "Squared threshold") == 0) {
78  return FromString(value, _SquaredThreshold) && _SquaredThreshold <= .0;
79  }
80  return false;
81  }
82 
83  // Import other overloads
85 
86  /// Get parameter key/value as string map
88  {
89  ParameterList params;
90  Insert(params, "Threshold", ToString(sqrt(_SquaredThreshold)));
91  return params;
92  }
93 
94  /// Evaluate radial registration error
95  virtual double Value(double d) const
96  {
97  return _SquaredThreshold * log(1.0 + d / _SquaredThreshold);
98  }
99 
100  /// Evaluate derivative of radial registration error
101  virtual double Derivative(double d) const
102  {
103  return 1.0 / (1.0 + d / _SquaredThreshold);
104  }
105 
106 };
107 
108 
109 } // namespace mirtk
110 
111 #endif // MIRTK_PeronaMalikErrorFunction_H
Perona-Malik fiducial registration error.
virtual TypeId Type() const
Type enumeration value.
ParameterList Parameter() const
Get parameter key/value as string map.
TypeId
Enumeration of available error functions.
PeronaMalikErrorFunction(double threshold=1.0)
Constructor.
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
Definition: Object.h:38
virtual RadialErrorFunction * NewInstance() const
Copy construct a new instance.
virtual double Derivative(double d) const
Evaluate derivative of radial registration error.
Definition: IOConfig.h:41
PeronaMalikErrorFunction(const PeronaMalikErrorFunction &other)
Copy constructor.
virtual double Value(double d) const
Evaluate radial registration error.
string ToString(const EnergyMeasure &value, int w, char c, bool left)
Convert energy measure enumeration value to string.
bool Set(const char *name, const char *value)
Set parameter value from string.
bool FromString(const char *str, EnergyMeasure &value)
Convert energy measure string to enumeration value.
virtual ParameterList Parameter() const
Get parameter name/value pairs.
Definition: Object.h:139
ParameterList & Insert(ParameterList &params, string name, T value)
Insert/replace value into/in parameters list.
Definition: Object.h:212