1 #ifndef ldpk_generic_distortion_base_sdv 2 #define ldpk_generic_distortion_base_sdv 20 template <
class VEC2,
class MAT2,
int N>
24 typedef VEC2 vec2_type;
25 typedef MAT2 mat2_type;
37 mutable int _k_max_iter;
45 if((i < 0) || (i >= N))
64 _n_max_iter = n_max_iter;
65 _n_post_iter = n_post_iter;
73 virtual double get_coeff(
int i)
const = 0;
74 virtual void set_coeff(
int i,
double) = 0;
90 {
return _n_max_iter; }
94 {
return _n_post_iter; }
102 virtual vec2_type
operator()(
const vec2_type& p)
const = 0;
104 vec2_type
eval(
const vec2_type& p)
const 105 {
return (*
this)(p); }
109 virtual mat2_type
jacobi(
const vec2_type& p_dn)
const 111 const double epsilon = 1e-4;
112 return trans(mat2_type((
eval(p_dn + vec2_type(epsilon,0)) -
eval(p_dn - vec2_type(epsilon,0))) / (2.0 * epsilon),
113 (
eval(p_dn + vec2_type(0,epsilon)) -
eval(p_dn - vec2_type(0,epsilon))) / (2.0 * epsilon)));
116 virtual void derive(
double* dg,
int n_parameters,
const vec2_type& p_dn)
const 118 std::cout <<
"ldpk::generic_distortion_base::derive: not implemented" << std::endl;
124 vec2_type p = q - ((*this)(q) - q);
128 for(
int i = 0;i < _n_max_iter;++i)
130 vec2_type q_iter = (*this)(p);
133 _diff = norm2(q_iter - q);
140 for(
int i = 0;i < _n_post_iter;++i)
142 vec2_type q_iter = (*this)(p);
146 if(_k_iter > _k_max_iter)
148 _k_max_iter = _k_iter;
153 vec2_type
map_inverse(
const vec2_type& q,
const vec2_type& p_start)
const 155 vec2_type p = p_start;
156 for(_k_iter = 0;_k_iter < 20;++_k_iter)
160 vec2_type q_cmp(
eval(p));
163 p += invert(g) * (q - q_cmp);
169 if(norm2(q - q_cmp) < 1e-8)
175 if(_k_iter > _k_max_iter)
177 _k_max_iter = _k_iter;
184 virtual std::ostream&
out(std::ostream& cout)
const int get_num_parameters() const
Number of parameters, that is N.
Definition: ldpk_generic_distortion_base.h:58
int get_n_max_iter() const
User-defined maximum number of iterations applied in map_inverse in order to fulfill the termination ...
Definition: ldpk_generic_distortion_base.h:89
int get_n_post_iter() const
User-defined number of additional iterations to be applied when the termination condition is fulfille...
Definition: ldpk_generic_distortion_base.h:93
Exception classes for ldpk.
Base class for a distortion model with N parameters. You may find it useful to derive your own distor...
Definition: ldpk_generic_distortion_base.h:21
virtual mat2_type jacobi(const vec2_type &p_dn) const
Jacobi-Matrix. The result is a matrix g_{ij} = d/dp_j f(p)_i, where f represents the undistort-functi...
Definition: ldpk_generic_distortion_base.h:109
Some index was out of range.
Definition: ldpk_error.h:30
void check_range(int i) const
A derived class may check if the index is valid.
Definition: ldpk_generic_distortion_base.h:43
vec2_type map_inverse(const vec2_type &q, const vec2_type &p_start) const
For given q, we are looking for p so that f(p) = q. p_start is near to p.
Definition: ldpk_generic_distortion_base.h:153
vec2_type eval(const vec2_type &p) const
Same as method instead of operator.
Definition: ldpk_generic_distortion_base.h:104
virtual double get_coeff(int i) const =0
There must be methods to address coefficients by one single index i in [0,N[.
The namespace of (most of the) things related to the Lens Distortion Plugin Kit.
Definition: ldpk.h:180
virtual void done()
After changing one or more coefficients of the model, call this (future use). The derived class may p...
Definition: ldpk_generic_distortion_base.h:70
int get_k_iter() const
Number of iterations until epsilon was reached. This value is reset at the beginning of each iterativ...
Definition: ldpk_generic_distortion_base.h:81
virtual vec2_type operator()(const vec2_type &p) const =0
Remove distortion. This method is non-iterative.
virtual void derive(double *dg, int n_parameters, const vec2_type &p_dn) const
Not all distortion functions will support this.
Definition: ldpk_generic_distortion_base.h:116
int get_k_max_iter() const
By this value you can check how much iterations per pixel were required to warp an entire image or se...
Definition: ldpk_generic_distortion_base.h:85
virtual vec2_type map_inverse(const vec2_type &q) const
Inverse mapping by solving the fixed point equation without providing initial values. Virtual, because the derived class might use some smart data structure for calculating an initial value.
Definition: ldpk_generic_distortion_base.h:122
double get_diff() const
Difference between is-value and should-be-value in map_inverse(). Inverse mapping is implemented as f...
Definition: ldpk_generic_distortion_base.h:99
virtual std::ostream & out(std::ostream &cout) const
The derived class implements a method for printing values inside 3DE4's matrix tool dialog...
Definition: ldpk_generic_distortion_base.h:184
void setup_map_inverse(int n_max_iter, int n_post_iter, double epsilon)
Configure iterative procedure for map_inverse(). Call this, if you don't agree with the default value...
Definition: ldpk_generic_distortion_base.h:62
void reset_k_max_iter()
Reset k_max_iter for debugging purposes.
Definition: ldpk_generic_distortion_base.h:77