Lens distortion correction division model 1p
 All Classes Files Functions Variables
lens_distortion.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010-2013, AMI RESEARCH GROUP <lalvarez@dis.ulpgc.es>
3  License : CC Creative Commons "Attribution-NonCommercial-ShareAlike"
4  see http://creativecommons.org/licenses/by-nc-sa/3.0/es/deed.en
5  */
6 
7 
8  #ifndef AMI_DLL_H
9  #define AMI_DLL_H
10 #endif
11 
17 #ifndef LENS_DISTORTION_H
18 #define LENS_DISTORTION_H
19 
20 #ifdef __AMIDEBUG__
21  #include "wxAmiDebugLog.h"
22 #endif
23 
24 /*****************************************************************************************/
25 /*COMPUTES THE STRAIGHT LINE WITH THE BEST FIT TO A 2D POINTS SET AND ERASE DISTANT POINTS
26  CONSIDERING THE DISTORTION MODEL */
27 /*****************************************************************************************/
29  double *a, int Na, double xc,double yc,
30  double *x,double *y,int *N,
31  double line[3],
32  double outlier_elimination_factor);
33 
34 /****************************************************************/
35 /*COMPUTES THE STRAIGHT LINE WITH THE BEST FIT TO A 2D POINTS SET
36  INCLUDING THE POLINOMIAL DISTORTION MODEL */
37 /****************************************************************/
38 AMI_DLL_H double ami_points_to_line_equation(double *a, int Na, double xc,
39  double yc, double *x,double *y,
40  int N, double line[3]);
41 
42 
43 //=====================================================================
44 // DISTORTION MODEL ESTIMATION FROM A SET OF LINES
45 //=====================================================================
46 AMI_DLL_H double ami_distortion_model_estimation_2p(double xc,double yc,
47  double **x,double **y,
48  int Nl,int *Np,double **a,
49  int *Na);
50 
51 // ====================================================================
52 // COMPUTE THE LENS DISTORTION MODEL IN A POINT
53 // ====================================================================
54 AMI_DLL_H void ami_lens_distortion_model_evaluation(double *a,int Na, double xc,
55  double yc,double x_input,
56  double y_input,
57  double *x_output,
58  double *y_output);
59 
60 
61 /***************************************************************************
62  FUNCTION TO ADD THE INFORMATION OF A LINE POINT SEQUENCE TO THE 4 DEGREE
63  POLYNOMIAL TO COMPUTE THE LENS DISTORTION MODEL
64 ***************************************************************************/
66  double *x, double *y,int Np,double *a,
67  int Na,double x0,double y0,int k1,
68  int k2,double **pol,double alfa);
69 
70 /*****************************************************************************
71 UPDATE OF THE LENS DISTORTION POLYNOMIAL MODEL FOR 2 VARIABLES. IF alfa>0
72 WE ADAPT a[0] TO MINIMIZE THE SQUARE DISTANCE BEEWTEN DISTORTED AND
73 UNDISTORTED POINTS AND WE ADD A TERM TO THE POLYNOMIAL ALSO MINIMIZING SUCH
74 DISTANCE WITH WEIGHT alfa
75 ****************************************************************************/
76 AMI_DLL_H double ami_lens_distortion_estimation_2v(double **x,double **y,int Nl,
77  int *Np,double x0,double y0,
78  double *a,int Na,int k1,
79  int k2,double alfa);
80 
81 /***************************************************************************
82  FUNCTION TO UPDATE THE LENS DISTORTION MODEL BY MINIMIZING A 4 DEGREE
83  2 VARIABLE POLYNOM
84 ***************************************************************************/
85 AMI_DLL_H int ami_lens_distortion_model_update_2v(double *a,int k1,int k2,
86  double **pol);
87 
88 /***************************************************************************
89  FUNCTION TO ADD THE INFORMATION OF A LINE POINT SEQUENCE TO THE 4 DEGREE
90  POLYNOMIAL TO COMPUTE THE LENS DISTORTION MODEL
91 ***************************************************************************/
92 AMI_DLL_H int ami_lens_distortion_polynomial_update_2v(double *x, double *y,
93  int Np,double *a,int Na,
94  double x0,double y0,
95  int k1,int k2,
96  double **pol);
97 
98 /****************************************************************************
99  FUNCTION TO COMPUTE THE PARTIAL DERIVATIVES OF A 2 VARIABLE POLYNOM
100 THE DEGREE OF THE DERIVATIVE POLYNOMs IS ASSUMED TO BE THE SAME THAT
101 THE ORIGINAL ONE
102 ****************************************************************************/
103 AMI_DLL_H void ami_2v_polynom_derivatives(double **p,int N,double **p_x,
104  double **p_y);
105 
106 /**********************************************************************
107  FUNCTION TO EVALUATE THE DETERMINANT OF A MATRIX
108  *********************************************************************/
109 AMI_DLL_H double ami_determinante(double **A,int N);
110 AMI_DLL_H double ami_determinante(double A[3][3]);
111 
112 /************************************************************
113  FUNCTION TO COMPUTE THE DETERMINANT OF A POLYNOM MATRIX
114  ************************************************************/
115 AMI_DLL_H void ami_polynom_determinant(double p[6][6][19],int Np,int Nd,
116  double *q);
117 
118 /************************************************************************
119  FUNCTION TO EVALUATE A 2 VARIABLE POLYNOM IN ONE POINT
120  ***********************************************************************/
121 AMI_DLL_H double ami_2v_polynom_evaluation(double **pt1,int N1,double x,
122  double y);
123 
124 /**********************************************************************
125  FUNCTION TO EVALUATE A 2 VARIABLE POLYNOM IN ONE OF THE VARIABLE VALUE. THE OUTPUT
126 IS A 1 DEGREE POLYNOM
127 *****************************************************************************/
128 AMI_DLL_H void ami_2v_polynom_to_1v_polynom(double **pt1,int N1,double *p3,
129  double z,int flat);
130 
131 /*****************************************************************************
132  FUNCTION TO MULTIPLY POLINOMS OF 1 VARIABLE. THE RESULT IS ADDED TO THE OUTPUT
133 POLYNOM COEFICIENTS
134 *****************************************************************************/
135 AMI_DLL_H double* ami_1v_polynom_multiplication(double *pt1,int N1,double *pt2,
136  int N2,double *pt3);
137 
138 /*****************************************************************************
139  FUNCTION TO MULTIPLY POLINOMS OF 2 VARIABLES.
140 *****************************************************************************/
141 AMI_DLL_H void ami_2v_polynom_multiplication(double **pt1,int N1,double **p2,
142  int N2,double **p3);
143 
144 /***********************************************************************
145  FUNCTION TO COMPUTE THE REAL ROOTS OF A CUBIC POLYNOMIAL. IT RETURNS
146  THE NUMBER OF ROOTS FOUND SORTED BY MAGNITUD
147 ************************************************************************/
148 AMI_DLL_H int ami_RootCubicPolynomial(double *a,int N,double *x);
149 
150 /**************************************************************
151  EVALUATION OF A POLYNOM USING HORNER ALGORITHM
152  ************************************************************/
153 AMI_DLL_H double ami_polynomial_evaluation(double *a,int Na,double x);
154 
155 /***************************************************************************
156  FUNCTION TO ADD THE INFORMATION OF A LINE POINT SEQUENCE TO THE 4 DEGREE
157  POLYNOMIAL TO COMPUTE THE LENS DISTORTION MODEL
158 ***************************************************************************/
159 AMI_DLL_H int ami_lens_distortion_polynomial_update(double *x, double *y,int Np,
160  double *a,int Na,double x0,
161  double y0,int k,double *pol);
162 
163 /***************************************************************************
164  FUNCTION TO UPDATE THE LENS DISTORTION MODEL BY MINIMIZING A 4 DEGREE
165  POLYNOM
166 ***************************************************************************/
167 AMI_DLL_H int ami_lens_distortion_model_update(double *a,int k,double *pol);
168 
169 /****************************************************************************
170  FUNCTION TO COMPUTE THE LENS DISTORTION ENERGY ERROR (THE RESIDUAL VARIANCE
171  OF THE POINT DISTRIBUTION
172 *****************************************************************************/
173 AMI_DLL_H double ami_LensDistortionVarianceError(double *x,double *y,int Np,
174  double x0,double y0,double *a,
175  int Na);
176 
177 /****************************************************************************
178  FUNCTION TO COMPUTE THE LENS DISTORTION ENERGY ERROR
179 *****************************************************************************/
180 AMI_DLL_H double ami_LensDistortionEnergyError(double *x,double *y,int Np,
181  double x0,double y0,double *a,
182  int Na);
183 
184 /*************************************************************************
185  FUNCTION TO INVERSE THE LENS DISTORTION TRANSFORMATION
186 ***********************************************************************/
187 AMI_DLL_H int ami_inverse_lens_distortion(double x,double y,double x0,double y0,
188  double *xt,double *yt,double *a,
189  int Na);
190 
191 /*************************************************************************
192  FUNCTION TO COMPUTE THE LENS DISTORTION MODEL
193 *************************************************************************/
194 AMI_DLL_H double ami_lens_distortion_estimation(double **x,double **y,int Nl,
195  int *Np,double x0,double y0,
196  double *a,int Na,int k,
197  double alfa);
198 
199 AMI_DLL_H void ami_lens_distortion_zoom_normalization(double **x,double **y,
200  int Nl,int *Np,double x0,
201  double y0,double *a,int Na);
202 
203 int ami_inverse_lens_distortion_fast(double x,double y,double x0,double y0,
204  double *xt,double *yt, double *a, int Na,
205  double dl1r);
206 
207 double ami_inverse_lens_distortion_newton_raphson(
208  double x,double y, /* POINT TO INVERSE (INPUT)*/
209  double x0,double y0, /* CENTER OF THE IMAGE (INPUT)*/
210  double *xt,double *yt, /* INVERVE POINT TRANSFORMED (OUTPUT) */
211  double *a, /* LENS DISTORTION MODEL POLYNOM */
212  int Na); /* DEGREE OF THE LENS DISTORTION MODEL POLYNOM */
213 #endif
AMI_DLL_H void ami_2v_polynom_to_1v_polynom(double **pt1, int N1, double *p3, double z, int flat)
Function to evaluate a 2 variable polynom in one of the variable value.
Definition: lens_distortion.cpp:536
AMI_DLL_H double ami_polynomial_evaluation(double *a, int Na, double x)
Evaluation of a polynom using horner algorithm.
Definition: lens_distortion.cpp:688
AMI_DLL_H int ami_RootCubicPolynomial(double *a, int N, double *x)
Function to compute the real roots of a cubic polynomial.
Definition: lens_distortion.cpp:635
AMI_DLL_H void ami_polynom_determinant(double p[6][6][19], int Np, int Nd, double *q)
Function to compute the determinant of a polynom matrix.
Definition: lens_distortion.cpp:471
AMI_DLL_H void ami_2v_polynom_derivatives(double **p, int N, double **p_x, double **p_y)
Function to compute the partial derivatives of a 2 variable polynom the degree of the derivative poly...
Definition: lens_distortion.cpp:380
AMI_DLL_H double ami_lens_distortion_estimation(double **x, double **y, int Nl, int *Np, double x0, double y0, double *a, int Na, int k, double alfa)
Function to compute the lens distortion model.
Definition: lens_distortion.cpp:1588
AMI_DLL_H double ami_LensDistortionVarianceError(double *x, double *y, int Np, double x0, double y0, double *a, int Na)
Function to compute the lens distortion energy error (the residual variance of the point distribution...
Definition: lens_distortion.cpp:839
AMI_DLL_H double ami_points_to_line_equation(double *a, int Na, double xc, double yc, double *x, double *y, int N, double line[3])
COMPUTATION OF THE LINE EQUATION INCLUDING THE POLINOMIAL DISTORTION MODEL.
Definition: lens_distortion.cpp:937
AMI_DLL_H int ami_inverse_lens_distortion(double x, double y, double x0, double y0, double *xt, double *yt, double *a, int Na)
Function to inverse the lens distortion transformation.
Definition: lens_distortion.cpp:1413
AMI_DLL_H int ami_lens_distortion_polynomial_update(double *x, double *y, int Np, double *a, int Na, double x0, double y0, int k, double *pol)
Function to add the information of a line point sequence to the 4 degree polynomial to compute the le...
Definition: lens_distortion.cpp:713
AMI_DLL_H double ami_distortion_model_estimation_2p(double xc, double yc, double **x, double **y, int Nl, int *Np, double **a, int *Na)
DISTORTION MODEL ESTIMATION FROM A SET OF LINES.
Definition: lens_distortion.cpp:1211
AMI_DLL_H int ami_lens_distortion_polynomial_update_2v(double *x, double *y, int Np, double *a, int Na, double x0, double y0, int k1, int k2, double **pol)
Function to add the information of a line point sequence to the 4 degree polynomial to compute the le...
Definition: lens_distortion.cpp:278
AMI_DLL_H double ami_points_to_line_equation_outlier_elimination(double *a, int Na, double xc, double yc, double *x, double *y, int *N, double line[3], double outlier_elimination_factor)
COMPUTES THE LINE WITH THE BEST FIT TO A SET OF 2D POINTS AND ERASE DISTANT POINTS TAKING INTO ACCOUN...
Definition: lens_distortion.cpp:1062
AMI_DLL_H void ami_lens_distortion_model_evaluation(double *a, int Na, double xc, double yc, double x_input, double y_input, double *x_output, double *y_output)
COMPUTE THE LENS DISTORTION MODEL IN A POINT.
Definition: lens_distortion.cpp:1309
AMI_DLL_H void ami_2v_polynom_multiplication(double **pt1, int N1, double **p2, int N2, double **p3)
Function to multiply polinoms of 2 variables.
Definition: lens_distortion.cpp:604
AMI_DLL_H int ami_lens_distortion_polynomial_update_distance_2v(double *x, double *y, int Np, double *a, int Na, double x0, double y0, int k1, int k2, double **pol, double alfa)
Function to add the information of a line point sequence to the 4 degree polynomial to compute the le...
Definition: lens_distortion.cpp:39
AMI_DLL_H double * ami_1v_polynom_multiplication(double *pt1, int N1, double *pt2, int N2, double *pt3)
Function to multiply polinoms of 1 variable.
Definition: lens_distortion.cpp:573
AMI_DLL_H double ami_2v_polynom_evaluation(double **pt1, int N1, double x, double y)
Function to evaluate a 2 variable polynom in one point.
Definition: lens_distortion.cpp:506
AMI_DLL_H void ami_lens_distortion_zoom_normalization(double **x, double **y, int Nl, int *Np, double x0, double y0, double *a, int Na)
Not described.
Definition: lens_distortion.cpp:1644
AMI_DLL_H double ami_determinante(double **A, int N)
Function to evaluate the determinant of a matrix.
Definition: lens_distortion.cpp:409
AMI_DLL_H double ami_lens_distortion_estimation_2v(double **x, double **y, int Nl, int *Np, double x0, double y0, double *a, int Na, int k1, int k2, double alfa)
Update of the lens distortion polynomial model for 2 variables. If alfa>0 we adapt a[0] to minimize t...
Definition: lens_distortion.cpp:123
AMI_DLL_H double ami_LensDistortionEnergyError(double *x, double *y, int Np, double x0, double y0, double *a, int Na)
Function to compute the lens distortion energy error.
Definition: lens_distortion.cpp:889