1 #ifndef ldpk_radial_decentered_distortion_sdv 2 #define ldpk_radial_decentered_distortion_sdv 14 template <
class VEC2,
class MAT2>
19 typedef VEC2 vec2_type;
20 typedef MAT2 mat2_type;
35 _c2 = _u1 = _v1 = 0.0;
36 _c4 = _u3 = _v3 = 0.0;
61 x_dn = x * (1.0 + _c2 * r2 + _c4 * r4)
62 + (r2 + 2.0 * x2) * (_u1 + _u3 * r2)
63 + 2.0 * xy * (_v1 + _v3 * r2);
65 y_dn = y * (1.0 + _c2 * r2 + _c4 * r4)
66 + (r2 + 2.0 * y2) * (_v1 + _v3 * r2)
67 + 2.0 * xy * (_u1 + _u3 * r2);
68 return vec2_type(x_dn,y_dn);
72 mat2_type
jacobi(
const vec2_type& p_dn)
const 101 double u1x = _u1 * x;
102 double v1y = _v1 * y;
103 double c4r2 = _c4 * r2;
104 m[0][0] = 1.0 + _c2 * (3.0 * x2 + y2) + c4r2 * (5.0 * x2 + y2)
105 + 6.0 * u1x + _u3 * (8.0 * xy2 + 12.0 * x3)
106 + 2.0 * v1y + _v3 * (2.0 * y3 + 6.0 * x2y);
107 m[1][1] = 1.0 + _c2 * (x2 + 3.0 * y2) + c4r2 * (x2 + 5.0 * y2)
108 + 6.0 * v1y + _v3 * (8.0 * x2y + 12.0 * y3)
109 + 2.0 * u1x + _u3 * (2.0 * x3 + 6.0 * xy2);
111 double m_off_diag_common = 2.0 * _c2 * xy + 4.0 * _c4 * xy * r2
112 + 2.0 * _u1 * y + 2.0 * _v1 * x;
113 m[0][1] = m_off_diag_common
114 + _u3 * (8.0 * x2y + 4.0 * y3)
115 + _v3 * (2.0 * x3 + 6.0 * xy2);
116 m[1][0] = m_off_diag_common
117 + _u3 * (6.0 * x2y + 2.0 * y3)
118 + _v3 * (4.0 * x3 + 8.0 * xy2);
124 void derive(
double* dg,
int n_parameters,
const vec2_type& p_dn)
const 126 int size = 2 * n_parameters;
129 double x2 = p_dn[0] * p_dn[0];
130 double y2 = p_dn[1] * p_dn[1];
131 double xy = p_dn[0] * p_dn[1];
139 if(k == size)
return;
141 dg[k++] = r2 + 2.0 * x2;
143 if(k == size)
return;
146 dg[k++] = r2 + 2.0 * y2;
147 if(k == size)
return;
151 if(k == size)
return;
153 dg[k++] = r2 * (r2 + 2.0 * x2);
154 dg[k++] = 2.0 * r2 * xy;
155 if(k == size)
return;
157 dg[k++] = 2.0 * r2 * xy;
158 dg[k++] = r2 * (r2 + 2.0 * y2);
159 if(k == size)
return;
161 std::cerr <<
"radial_decentered_distortion: n_parameters out of range" << std::endl;
163 std::ostream&
out(std::ostream& cout)
const 165 int p = int(cout.precision());
167 cout <<
"c2: " << _c2 << std::endl;
168 cout <<
"u1: " << _u1 << std::endl;
169 cout <<
"v1: " << _v1 << std::endl;
170 cout <<
"u3: " << _u3 << std::endl;
171 cout <<
"c4: " << _c4 << std::endl;
172 cout <<
"v3: " << _v3 << std::endl;
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
void check_range(int i) const
A derived class may check if the index is valid.
Definition: ldpk_generic_distortion_base.h:43
The namespace of (most of the) things related to the Lens Distortion Plugin Kit.
Definition: ldpk.h:169
Base class for distortion models.
std::ostream & out(std::ostream &cout) const
The derived class implements a method for printing values inside 3DE4's matrix tool dialog...
Definition: ldpk_radial_decentered_distortion.h:163
void derive(double *dg, int n_parameters, const vec2_type &p_dn) const
Derivative wrt distortion coefficients. dg points to an array with N / 2 Elements.
Definition: ldpk_radial_decentered_distortion.h:124
mat2_type jacobi(const vec2_type &p_dn) const
Analytic version of the Jacobi-matrix, about two times faster than the base class version which uses ...
Definition: ldpk_radial_decentered_distortion.h:72
void set_coeff(int i, double q)
Set coefficient c[i], 0 <= i < 6.
Definition: ldpk_radial_decentered_distortion.h:45
double get_coeff(int i) const
Get coefficient c[i], 0 <= i < 6.
Definition: ldpk_radial_decentered_distortion.h:39
vec2_type operator()(const vec2_type &p_dn) const
Remove distortion. p_dn is a point in diagonally normalized coordinates.
Definition: ldpk_radial_decentered_distortion.h:51
A polynomial radially symmetric model of degree 4 with decentering. This is the distortion model for ...
Definition: ldpk_radial_decentered_distortion.h:15