algebraic lens distortion
 All Classes Namespaces Files Functions Variables Defines
Defines | Functions
lens_distortion.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <malloc.h>
#include <string.h>
#include <time.h>
#include <vector>
#include "ami_pol.h"
#include "point2d.h"
#include "image.h"
Include dependency graph for lens_distortion.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define PI   3.1415927
#define ABS(x)   (((x)>0)?(x):-(x))
#define Normalize(x)   ((x)<0?0:((x)>255?255:x))
#define Max(a, b)   ((a>b)?a:b)
#define ami_abs(x)   ((x)>0?(x):(-(x)))
#define ami_calloc2d(address, datatype, height, width)
#define ami_malloc2d(address, datatype, height, width)
#define ami_malloc2d_pointers(address, simple_pointer, datatype, height, width)
#define ami_free2d(address)   { free(address[0]); free(address); }
#define ami_free2d_pointers(address)   { free(address); }
#define ami_malloc1d(address, datatype, size)   {address=(datatype *) malloc(sizeof(datatype)*(size));}
#define ami_calloc1d(address, datatype, size)
#define ami_max_iter   1000
#define ami_tol   0.0000001
#define line_length   80 /* LENGTH OF LINE (TO READ A LINE FOR A FILE) */
#define max_itera   100 /* MAXIMUM NUMBER OF GRADIENT ITERATIONS */
#define delta   1.0e-10 /* DERIVATIVE STEP (FINITE DIFFERENCES) */
#define max_itera_lambda   10 /* MAXIMUM NUMBER OF ITERATIONS IN UNIDIMENSIONAL SEARCH */
#define tol_f   1.0e-6 /* TOLERANCE TO STOP THE GRADIENT ITERATIONS */
#define tol_norma   1.0e-16 /* NORM OF GRADIENT TO STOP THE GRADIENT ALGORITHM */
#define patch_size   20
#define max_itera_patch   20 /* MAXIMUM NUMBER OF SEARCH-OF-DISTORTION-CENTER ITERATIONS */

Functions

int test_compatibility_lens_distortion_model (double *a, int Na, double max_radius)
 function checks if the lens distortion model is an increasing function in [0,max_radius]
int ami_line2d_calculation (double line[3], double **Points2D, int N)
 function to compute a line equation by minimizing the distance to a point collection
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 alpha)
 function to add the information of a line point sequence to the 4 degree polynomial to compute the lens distortion model
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 alpha, double max_radius)
int ami_lens_distortion_model_update_2v (double *a, int Na, int k1, int k2, double **pol, double max_radius)
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)
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 polynoms is assumed to be the same that the original one
void ami_polynom_determinant (double p[6][6][19], int Np, int Nd, double *q)
 function to compute the determinant of a polynom matrix
double ami_2v_polynom_evaluation (double **p1, int N1, double x, double y)
 function to evaluate a 2 variable polynom in one point
void ami_2v_polynom_to_1v_polynom (double **p1, int N1, double *p3, double z, int flat)
 function to evaluate a 2 variable polynom in one of the variable value. The output is a 1 degree polynom
double * ami_1v_polynom_multiplication (double *p1, int N1, double *p2, int N2, double *p3)
 function to multiply polinoms of 1 variable. the result is added to the output polynom COEFFICIENTs
void ami_2v_polynom_multiplication (double **p1, int N1, double **p2, int N2, double **p3)
 function to multiply polynoms of 2 variables
int ami_RootCubicPolynomial (double *a, int N, double *x)
 function to compute the real roots of a cubic polynomial. It returns the number of roots found sorted by magnitud
double ami_polynomial_evaluation (double *a, int Na, double x)
 function to evaluate a polynom using the Horner algorithm
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 lens distortion model
int ami_lens_distortion_model_update (double *a, int Na, int k, double *pol)
 function to update the lens distortion model by minimizing a 4 degree polynom
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 (the residual variance of the point distribution
double ami_LensDistortionEnergyError_Vmin (double *x, double *y, int Np, double x0, double y0, double *a, int Na)
 function to compute the lens distortion vmin energy error of the point distribution
double ami_lens_distortion_estimation (double **x, double **y, int Nl, int *Np, double x0, double y0, double *a, int Na, int k, double alpha)
 function to compute the lens distortion model
void ami_lens_distortion_zoom_normalization (double **x, double **y, int Nl, int *Np, double *solution, int Na)
int calculate_points (double *amin, double **points_2D_modified, int N, int Na, double x0, double y0)
 function to estimate the position of 2D points (pixels) for the actual lens distortion model
double distance_function (double *solution, double **x, double **y, int Nl, int *Np, int Na)
double find_lambda (double lambda1, double lambda2, double lambda3, double f_1, double f_2, double f_3, double *amin_copy, double *amin, double **x, double **y, int Nl, int *Np, int Na, double *grad_f, int *change_k)
double minimize_cuadratic_polynom (double lambda1, double lambda2, double lambda3, double f_1, double f_2, double f_3, double *amin_copy, double *amin, double **x, double **y, int Nl, int *Np, int Na, double *grad_f, int *change_k)
double cuadratic_fitting (double *amin_copy, double *amin, double **x, double **y, int Nl, int *Np, int Na, double lambda1, double lambda2, double lambda3, double f_1, double f_2, double f_3, double *grad_f, int *change_k)
double minimize_lambda (double *amin, double **x, double **y, int Nl, int *Np, int Na, double *grad_f, double f, int *change_k)
double gradient_method (double *solution, double **x, double **y, int Nl, int *Np, int Na, int *change_k, int zoom, int optimize_center)
double calculate_factor_n (double **x, double **y, int Nl, int *Np, double x0, double y0)
 function to calculate the factor_n, needed for transforming k (lens distortion model) from normalized coordinates to pixels
int optimize (double *solution, double **x, double **y, double **xx, double **yy, int Nl, int *Np, int Na, double factor_n, int zoom, FILE *fp1, int optimize_center)
int algebraic_method_pre_gradient (int Nl, int *Np, double *a, double **x, double **y, double **xx, double **yy, double factor_n, int zoom, FILE *fp1, int optimize_center, double max_radius)
int trivial_solution (int Nl, int *Np, double *a, double **xx, double **yy, double factor_n, FILE *fp1, double *trivial, int optimize_center)
int read_line_primitives (char filename[300], int *Nl, int **Np, double ***x, double ***y)
 function to read point line primitives
int search_for_best_center (int N, int *Np, double *a, double **xx, double **yy, int width, int height, double max_radius)
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.
double ami_inverse_lens_distortion_newton_raphson (double x, double y, double x0, double y0, double *xt, double *yt, double *a, int Na)
 COMPUTE THE INVERSE OF LENS DISTORTION MODEL IN A POINT USING NEWTON-RAPHSON.
int ami_inverse_lens_distortion_fast (double x, double y, double x0, double y0, double *xt, double *yt, double *a, int Na, double dl1r)
int build_l1r_vector (std::vector< double > &l1r, ami::point2d< double > &dc, double max_distance_corner, int Na, double *a)
ami::image< unsigned char > undistort_image_inverse_fast (ami::image< unsigned char > input_image, int Na, double *a, ami::point2d< double > dc, const double &image_amplification_factor)

Define Documentation

#define ABS (   x)    (((x)>0)?(x):-(x))

Definition at line 29 of file lens_distortion.h.

#define ami_abs (   x)    ((x)>0?(x):(-(x)))

Definition at line 32 of file lens_distortion.h.

#define ami_calloc1d (   address,
  datatype,
  size 
)
Value:
{int ml; address=(datatype *) malloc(sizeof(datatype)*(size)); \
          for(ml=0;ml<size;ml++) address[ml]=0;\
        }

Definition at line 52 of file lens_distortion.h.

#define ami_calloc2d (   address,
  datatype,
  height,
  width 
)
Value:
{int ml,mk; \
          address=(datatype **) malloc(sizeof(datatype *)*(height)); \
          address[0]=(datatype *)malloc(sizeof(datatype)*(width)*(height)); \
          for(ml=0;ml<(height);ml++) address[ml]=&(address[0][ml*(width)]); \
          for(ml=0;ml<height;ml++) for(mk=0;mk<width;mk++) address[ml][mk]=0; \
        }

Definition at line 33 of file lens_distortion.h.

#define ami_free2d (   address)    { free(address[0]); free(address); }

Definition at line 49 of file lens_distortion.h.

#define ami_free2d_pointers (   address)    { free(address); }

Definition at line 50 of file lens_distortion.h.

#define ami_malloc1d (   address,
  datatype,
  size 
)    {address=(datatype *) malloc(sizeof(datatype)*(size));}

Definition at line 51 of file lens_distortion.h.

#define ami_malloc2d (   address,
  datatype,
  height,
  width 
)
Value:
{int ml; \
          address=(datatype **) malloc(sizeof(datatype *)*(height)); \
          address[0]=(datatype *)malloc(sizeof(datatype)*(width)*(height)); \
          for(ml=0;ml<(height);ml++) address[ml]=&(address[0][ml*(width)]);\
        }

Definition at line 39 of file lens_distortion.h.

#define ami_malloc2d_pointers (   address,
  simple_pointer,
  datatype,
  height,
  width 
)
Value:
{int ml; \
          address=(datatype **) malloc(sizeof(datatype *)*(height)); \
          address[0]=(datatype *) simple_pointer; \
          for(ml=0;ml<(height);ml++) address[ml]=&(address[0][ml*(width)]);\
        }

Definition at line 44 of file lens_distortion.h.

#define ami_max_iter   1000

BEGIN: ALGEBRAIC CONTROL PARAMETERS

Definition at line 60 of file lens_distortion.h.

#define ami_tol   0.0000001

Definition at line 61 of file lens_distortion.h.

#define delta   1.0e-10 /* DERIVATIVE STEP (FINITE DIFFERENCES) */

Definition at line 75 of file lens_distortion.h.

#define line_length   80 /* LENGTH OF LINE (TO READ A LINE FOR A FILE) */

END: ALGEBRAIC CONTROL PARAMETERS

Definition at line 68 of file lens_distortion.h.

#define Max (   a,
 
)    ((a>b)?a:b)

Definition at line 31 of file lens_distortion.h.

#define max_itera   100 /* MAXIMUM NUMBER OF GRADIENT ITERATIONS */

BEGIN: GRADIENT CONTROL PARAMETERS

Definition at line 74 of file lens_distortion.h.

#define max_itera_lambda   10 /* MAXIMUM NUMBER OF ITERATIONS IN UNIDIMENSIONAL SEARCH */

Definition at line 76 of file lens_distortion.h.

#define max_itera_patch   20 /* MAXIMUM NUMBER OF SEARCH-OF-DISTORTION-CENTER ITERATIONS */

Definition at line 88 of file lens_distortion.h.

#define Normalize (   x)    ((x)<0?0:((x)>255?255:x))

Definition at line 30 of file lens_distortion.h.

#define patch_size   20

END: GRADIENT CONTROL PARAMETERS BEGIN: SEARCH-OF-DISTORTION-CENTER PARAMETERS

Definition at line 87 of file lens_distortion.h.

#define PI   3.1415927

Coded by Luis Alvarez and Luis Gomez, AMI Research Group, University of Las Palmas de Gran Canaria, Canary Islands, SPAIN First version: February 2010, Second Version: January 2012 (this is the second version) In this version, we optimize the center of distortion using a search patch pattern strategy

Definition at line 28 of file lens_distortion.h.

#define tol_f   1.0e-6 /* TOLERANCE TO STOP THE GRADIENT ITERATIONS */

Definition at line 77 of file lens_distortion.h.

#define tol_norma   1.0e-16 /* NORM OF GRADIENT TO STOP THE GRADIENT ALGORITHM */

Definition at line 78 of file lens_distortion.h.


Function Documentation

int algebraic_method_pre_gradient ( int  Nl,
int *  Np,
double *  a,
double **  x,
double **  y,
double **  xx,
double **  yy,
double  factor_n,
int  zoom,
FILE *  fp1,
int  optimize_center,
double  max_radius 
)
Parameters:
NlNumber of lines
NpNumber of points/line
aLens distortion model polynom
xCoordinates of points (normalized)
yCoordinates of points (normalized)
xxCoordinates of points
yyCoordinates of points
factor_nFactor to normalize coordinates
zoomZoom strategy
fp1Pointer to the output file
optimize_centerTo optimize the center of distortion
max_radiusMAXIMUM RADIAL DISTANCE IN PHOTO

Definition at line 1771 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

double* ami_1v_polynom_multiplication ( double *  p1,
int  N1,
double *  p2,
int  N2,
double *  p3 
)

function to multiply polinoms of 1 variable. the result is added to the output polynom COEFFICIENTs

Author:
Luis Alvarez
Returns:
return the calculation
Parameters:
p1POLYNOM 1 (INPUT)
N1DEGREE OF POLYNOM 1 (INPUT)
p2POLYNOM 2 (INPUT)
N2DEGREE OF POLYNOM 2 (INPUT)
p3OUTPUT POLYNOM (INPUT-OUTPUT)

Definition at line 744 of file lens_distortion.cpp.

Here is the caller graph for this function:

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 polynoms is assumed to be the same that the original one

Author:
Luis Alvarez
Returns:
return void
Parameters:
pORIGINAL POLYNOM (INPUT)
NDEGREE OF THE ORIGINAL POLYNOM (INPUT)
p_xDERIVATIVE OF THE POLYNOM WITH RESPECT TO THE FIRST VARIABLE (OUTPUT)
p_yDERIVATIVE OF THE POLYNOM WITH RESPECT TO THE SECOND VARIABLE(OUTPUT)

Definition at line 600 of file lens_distortion.cpp.

Here is the caller graph for this function:

double ami_2v_polynom_evaluation ( double **  p1,
int  N1,
double  x,
double  y 
)

function to evaluate a 2 variable polynom in one point

Author:
Luis Alvarez
Returns:
return the evaluation
Parameters:
p12 VARIABLE POLYNOM (INPUT)
N1DEGREE OF POLYNOM 1 (INPUT)
yPOINT COORDINATE WHERE THE POLYNOM WILL BE EVALUATED (INPUT)

Definition at line 676 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void ami_2v_polynom_multiplication ( double **  p1,
int  N1,
double **  p2,
int  N2,
double **  p3 
)

function to multiply polynoms of 2 variables

Author:
Luis Alvarez
Returns:
return void
Parameters:
p1POLYNOM 1 (INPUT)
N1DEGREE OF POLYNOM 1 (INPUT)
p2POLYNOM 2 (INPUT)
N2DEGREE OF POLYNOM 2 (INPUT)
p3OUTPUT POLYNOM (INPUT - OUTPUT)

Definition at line 771 of file lens_distortion.cpp.

Here is the caller graph for this function:

void ami_2v_polynom_to_1v_polynom ( double **  p1,
int  N1,
double *  p3,
double  z,
int  flat 
)

function to evaluate a 2 variable polynom in one of the variable value. The output is a 1 degree polynom

VARIABLE WHERE THE POLYNOM IS GOING TO BE EVALUATED

Author:
Luis Alvarez
Returns:
return void
Parameters:
p12 VARIABLE POLYNOM (INPUT)
N1DEGREE OF POLYNOM 1 (INPUT)
p3OUTPUT 1 VARIABLE POLYNOM (OUTPUT)
zPOINT WHERE THE 2 VARIABLE POLYNOM IS GOING TO BE EVALUATED

Definition at line 708 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int ami_inverse_lens_distortion_fast ( double  x,
double  y,
double  x0,
double  y0,
double *  xt,
double *  yt,
double *  a,
int  Na,
double  dl1r 
)
double ami_inverse_lens_distortion_newton_raphson ( double  x,
double  y,
double  x0,
double  y0,
double *  xt,
double *  yt,
double *  a,
int  Na 
)

COMPUTE THE INVERSE OF LENS DISTORTION MODEL IN A POINT USING NEWTON-RAPHSON.

Parameters:
[in]x,yPOINT TO INVERSE (INPUT)
[in]x0,y0LENS DISTORTION MODEL CENTER (INPUT)
[out]*xt,*ytUNDISTORTED POINT (INVERSE POINT TRANSFORMED) (OUTPUT)
[in]*aLENS DISTORTION MODEL COEFFICIENTS
[in]NaDEGREE OF THE LENS DISTORTION MODEL POLYNOM
Author:
Luis Alvarez

Definition at line 2182 of file lens_distortion.cpp.

Here is the call graph for this function:

double ami_lens_distortion_estimation ( double **  x,
double **  y,
int  Nl,
int *  Np,
double  x0,
double  y0,
double *  a,
int  Na,
int  k,
double  alpha 
)

function to compute the lens distortion model

Author:
Luis Alvarez
Returns:
return (Error/Nl)
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  alpha,
double  max_radius 
)
Parameters:
yDISTORTED LINE COORDINATES (INPUT)
NlNUMBER OF LINES (RECTS)
NpNUMBER OF POINTS (INPUT)
y0COORDINATES OF THE IMAGE CENTER
aPOLYNOMIAL DEFINING THE LENS DISTORTION MODEL (INPUT)
NaDEGREE OF POLYNOMIAL MODEL FOR LENS DISTORTION
k1COEFFICIENT 1 OF THE POLYNOMIAL TO BE UPDATED
k2COEFFICIENT 2 OF THE POLYNOMIAL TO BE UPDATED
alphaWEIGHT OF THE DISTANCE IN THE POLYNOM ENERGY
max_radiusMAXIMUM RADIAL DISTANCE IN PHOTO

Definition at line 289 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Precondition:
Any parameter can be null.
Na has to be positive.
Parameters:
[in]aINPUT POLYNOMIAL DISTORTION MODEL
[in]NaINPUT DEGREE OF POLYNOMIAL DISTORTION MODEL
[in]xc,ycINPUT CENTER OF DISTORTION
[in]x_input,y_inputINPUT POINT
[out]x_output,y_outputOUTPUT UNDISTORTED POINT
Author:
Luis Alvarez

Definition at line 2156 of file lens_distortion.cpp.

Here is the call graph for this function:

int ami_lens_distortion_model_update ( double *  a,
int  Na,
int  k,
double *  pol 
)

function to update the lens distortion model by minimizing a 4 degree polynom

Author:
Luis Alvarez
Returns:
return 0 if the function finishes properly
int ami_lens_distortion_model_update_2v ( double *  a,
int  Na,
int  k1,
int  k2,
double **  pol,
double  max_radius 
)
Parameters:
aPOLYNOMIAL DEFINING THE LENS DISTORTION MODEL (INPUT-OUTPUT)
NaDEGREE OF POLYNOMIAL MODEL FOR LENS DISTORTION (INPUT)
k1COEFFICIENT 1 OF THE POLYNOMIAL TO BE UPDATED (INPUT)
k2COEFFICIENT 2 OF THE POLYNOMIAL TO BE UPDATED (INPUT)
pol4 DEGREE POLYNOM TO MINIMIZE (INPUT)
max_radiusMAXIMUM RADIAL DISTANCE IN PHOTO

Definition at line 346 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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 lens distortion model

Author:
Luis Alvarez
Returns:
return 0 if the function finishes properly
Parameters:
yDISTORTED LINE COORDINATES (INPUT)
NpNUMBER OF POINTS (INPUT)
aPOLYNOMIAL DEFINING THE LENS DISTORTION MODEL (INPUT)
NaDEGREE OF POLYNOMIAL MODEL FOR LENS DISTORTION
y0COORDINATES OF THE IMAGE CENTER
kCOEFFICIENT OF THE POLYNOMIAL TO BE UPDATED
pol4 DEGREE POLYNOM TO MINIMIZE (INPUT-OUTPUT)

Definition at line 881 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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 
)
Parameters:
yDISTORTED LINE COORDINATES (INPUT)
NpNUMBER OF POINTS (INPUT)
aPOLYNOMIAL DEFINING THE LENS DISTORTION MODEL (INPUT)
NaDEGREE OF POLYNOMIAL MODEL FOR LENS DISTORTION
y0COORDINATES OF THE IMAGE CENTER
k1COEFFICIENT 1 OF THE POLYNOMIAL TO BE UPDATED
k2COEFFICIENT 2 OF THE POLYNOMIAL TO BE UPDATED
pol4 DEGREE 2 VARIABLE POLYNOM TO MINIMIZE (INPUT-OUTPUT)

Definition at line 474 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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  alpha 
)

function to add the information of a line point sequence to the 4 degree polynomial to compute the lens distortion model

WEIGHT OF THE DISTANCE IN THE POLYNOM ENERGY

Author:
Luis Alvarez
Returns:
return 0 if function finishes properly
Parameters:
yDISTORTED LINE COORDINATES (INPUT)
NpNUMBER OF POINTS (INPUT)
aPOLYNOMIAL DEFINING THE LENS DISTORTION MODEL (INPUT)
NaDEGREE OF POLYNOMIAL MODEL FOR LENS DISTORTION
y0COORDINATES OF THE IMAGE CENTER
k1COEFFICIENT 1 OF THE POLYNOMIAL TO BE UPDATED
k2COEFFICIENT 2 OF THE POLYNOMIAL TO BE UPDATED
pol4 DEGREE 2 VARIABLE POLYNOM TO MINIMIZE (INPUT-OUTPUT)

Definition at line 203 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void ami_lens_distortion_zoom_normalization ( double **  x,
double **  y,
int  Nl,
int *  Np,
double *  solution,
int  Na 
)
Parameters:
yORIGINAL COLECCION OF LINES DISTRIBUTION (INPUT)
NlNUMBER OF LINES
NpNUMBER OF POINTS FOR EACH LINE(INPUT)
[in,out]solution
NaDegree of Polynomial model (INPUT)

Definition at line 1205 of file lens_distortion.cpp.

Here is the caller graph for this function:

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 (the residual variance of the point distribution

Author:
Luis Alvarez
Returns:
return the evaluation
Parameters:
yORIGINAL POINT DISTRIBUTION (INPUT)
NpNUMBER OF POINTS (INPUT)
y0CENTER OF THE IMAGE (INPUT)
aLens Distortion Polynomial model (INPUT)
NaDegree of Polynomial model (INPUT)

Definition at line 1038 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

double ami_LensDistortionEnergyError_Vmin ( double *  x,
double *  y,
int  Np,
double  x0,
double  y0,
double *  a,
int  Na 
)

function to compute the lens distortion vmin energy error of the point distribution

Author:
Luis Alvarez
Returns:
return the evaluation
Parameters:
yORIGINAL POINT DISTRIBUTION (INPUT)
NpNUMBER OF POINTS (INPUT)
y0CENTER OF THE IMAGE (INPUT)
aLens Distortion Polynomial model (INPUT)
NaDegree of Polynomial model (INPUT)

Definition at line 1093 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int ami_line2d_calculation ( double  line[3],
double **  Points2D,
int  N 
)

function to compute a line equation by minimizing the distance to a point collection

Author:
Luis Alvarez and Luis Gomez
Returns:
return 0 if function finishes properly and !0 otherwise
Parameters:
lineline coefficients (ax+by+c=0)
Points2Dset of 2D points
Nnumber of points

Definition at line 79 of file lens_distortion.cpp.

Here is the caller graph for this function:

void ami_polynom_determinant ( double  p[6][6][19],
int  Np,
int  Nd,
double *  q 
)

function to compute the determinant of a polynom matrix

Author:
Luis Alvarez
Returns:
return void

Definition at line 630 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

double ami_polynomial_evaluation ( double *  a,
int  Na,
double  x 
)

function to evaluate a polynom using the Horner algorithm

Author:
Luis Alvarez
Returns:
return the evaluation
Parameters:
aPOLYNOM COEFFICIENT
NaPOLYNOM DEGREE
xPOINT WHERE THE POLYNOM IS EVALUATED

Definition at line 860 of file lens_distortion.cpp.

Here is the caller graph for this function:

int ami_RootCubicPolynomial ( double *  a,
int  N,
double *  x 
)

function to compute the real roots of a cubic polynomial. It returns the number of roots found sorted by magnitud

Author:
Luis Alvarez
Returns:
return 3 if the function finishes properly
Parameters:
aPOLYNOMIAL COEFFICIENTS a[0]+a[1]x+a[2]x^2 +...
NDEGREE OF POLYNOMIAL (IT HAS TO BE 3)
xPOLYNOMIAL ROOTS

Definition at line 799 of file lens_distortion.cpp.

Here is the caller graph for this function:

int build_l1r_vector ( std::vector< double > &  l1r,
ami::point2d< double > &  dc,
double  max_distance_corner,
int  Na,
double *  a 
)

Definition at line 2243 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

double calculate_factor_n ( double **  xx,
double **  yy,
int  Nl,
int *  Np,
double  x0,
double  y0 
)

function to calculate the factor_n, needed for transforming k (lens distortion model) from normalized coordinates to pixels

Returns:
the factor_n value (double)
Author:
Luis Alvarez & Luis Gomez
Parameters:
xxx-Coordinates of points (pixels)
yyy-Coordinates of points (pixels)
NlNumber of lines
NpNumber of points/line
x0x center of the image (pixels)
y0y center of the image (pixels)

Definition at line 2093 of file lens_distortion.cpp.

Here is the caller graph for this function:

int calculate_points ( double *  amin,
double **  points_2D_modified,
int  N,
int  Na,
double  x0,
double  y0 
)

function to estimate the position of 2D points (pixels) for the actual lens distortion model

   GRADIENT PART
Author:
Luis Alvarez and Luis Gomez
Returns:
return 0 if the function finishes properly
Parameters:
aminLens distortion model polynom
points_2D_modifiedCloud of points to be fitted to a line
NNumber of points
NaDegree of the lens distortion model
x0x center of the image
y0y center of the image

Definition at line 1246 of file lens_distortion.cpp.

Here is the caller graph for this function:

double cuadratic_fitting ( double *  amin_copy,
double *  amin,
double **  x,
double **  y,
int  Nl,
int *  Np,
int  Na,
double  lambda1,
double  lambda2,
double  lambda3,
double  f_1,
double  f_2,
double  f_3,
double *  grad_f,
int *  change_k 
)
Parameters:
amin_copyCopy of amin
aminLens distortion model polynom
xCoordinates of points
yCoordinates of points
NlNumber of lines
NpNumber of points/line
NaDegree of the lens distortion model polynomial
lambda1First TTP point
lambda2Second TTP point
lambda3Third TTP point
f_1f_objective(lambda1)
f_2f_objective(lambda2)
f_3f_objective(lambda3)
grad_fGradient vector at amin
change_kto indicate what variable optimize (1: optimize, 0: no optimize)

Definition at line 1447 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

double distance_function ( double *  solution,
double **  x,
double **  y,
int  Nl,
int *  Np,
int  Na 
)
Parameters:
solution[Lens distortion model polynom;x0,y0]
xCoordinates of points
yCoordinates of points
NlNumber of lines
NpNumber of points/line
NaDegree of the lens distortion model

Definition at line 1278 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

double find_lambda ( double  lambda1,
double  lambda2,
double  lambda3,
double  f_1,
double  f_2,
double  f_3,
double *  amin_copy,
double *  amin,
double **  x,
double **  y,
int  Nl,
int *  Np,
int  Na,
double *  grad_f,
int *  change_k 
)
Parameters:
lambda1First TTP point
lambda2Second TTP point
lambda3Third TTP point
f_1f_objective(lambda1)
f_2f_objective(lambda2)
f_3f_objective(lambda3)
amin_copyCopy of amin
aminLens distortion model polynom
xCoordinates of points
yCoordinates of points
NlNumber of lines
NpNumber of points/line
NaDegree of the lens distortion model polynomial
grad_fGradient vector at amin
change_kTo indicate what variable optimize (1: optimize, 0: no optimize)

Definition at line 1338 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

double gradient_method ( double *  solution,
double **  x,
double **  y,
int  Nl,
int *  Np,
int  Na,
int *  change_k,
int  zoom,
int  optimize_center 
)

ZOOM UPDATE amin[0]

Parameters:
solution[Lens distortion model polynom;x0,y0]
xCoordinates of points
yCoordinates of points
NlNumber of lines
NpNumber of points/line
NaDegree of the lens distortion model polynomial
change_kto indicate what variable optimize (1: optimize, 0: no optimize)
zoomZoom strategy
optimize_centerTo optimize the center of distortion

Definition at line 1601 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

double minimize_cuadratic_polynom ( double  lambda1,
double  lambda2,
double  lambda3,
double  f_1,
double  f_2,
double  f_3,
double *  amin_copy,
double *  amin,
double **  x,
double **  y,
int  Nl,
int *  Np,
int  Na,
double *  grad_f,
int *  change_k 
)
Parameters:
lambda1First TTP point
lambda2Second TTP point
lambda3Third TTP point
f_1f_objective(lambda1)
f_2f_objective(lambda2)
f_3f_objective(lambda3)
amin_copyCopy of amin
aminLens distortion model polynom
xCoordinates of points
yCoordinates of points
NlNumber of lines
NpNumber of points/line
NaDegree of the lens distortion model polynomial
grad_fGradient vector at amin
change_kTo indicate what variable optimize (1: optimize, 0: no optimize)

Definition at line 1396 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

double minimize_lambda ( double *  amin,
double **  x,
double **  y,
int  Nl,
int *  Np,
int  Na,
double *  grad_f,
double  f,
int *  change_k 
)
Parameters:
amin[Lens distortion model polynom;x0,y0]
xCoordinates of points
yCoordinates of points
NlNumber of lines
NpNumber of points/line
NaDegree of the lens distortion model polynomial
grad_fGradient vector at amin
ffunction value at amin
change_kTo indicate what variable optimize (1: optimize, 0: no optimize)

Definition at line 1520 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int optimize ( double *  solution,
double **  x,
double **  y,
double **  xx,
double **  yy,
int  Nl,
int *  Np,
int  Na,
double  factor_n,
int  zoom,
FILE *  fp1,
int  optimize_center 
)
Parameters:
solution[Lens distortion model polynom; x0,y0]
xCoordinates of points (normalized)
yCoordinates of points (normalized)
xxCoordinates of points
yyCoordinates of points
NlNumber of lines
NpNumber of points/line
NaDegree of the lens distortion model polynomial
factor_nFactor to normalize coordinates
zoomZoom strategy
fp1Pointer to the output file
optimize_centerTo optimize the center of distortion

Definition at line 1660 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int read_line_primitives ( char  filename[300],
int *  Nl,
int **  Np,
double ***  x,
double ***  y 
)

function to read point line primitives

Author:
Luis Alvarez
Parameters:
filenameINPUT FILE NAME
NlOUTPUT NUMBER OF LINES
NpOUTPUT NUMBER OF POINTS FOR EACH LINE
xOUTPUT POINT X COORDINATES
yOUTPUT POINT X COORDINATES

Definition at line 2044 of file lens_distortion.cpp.

Here is the caller graph for this function:

int search_for_best_center ( int  N,
int *  Np,
double *  a,
double **  xx,
double **  yy,
int  width,
int  height,
double  max_radius 
)
Parameters:
NNumber of lines
NpNumber of points/line
aLens distortion model polynom
xxCoordinates of points (pixels)
yyCoordinates of points (pixels)
widthImage size: width (pixels)
heightImage size: height (pixels)
max_radiusMAXIMUM RADIAL DISTANCE IN PHOTO

Definition at line 1934 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int test_compatibility_lens_distortion_model ( double *  a,
int  Na,
double  max_radius 
)

function checks if the lens distortion model is an increasing function in [0,max_radius]

END: SEARCH-OF-DISTORTION-CENTER PARAMETERS

TOLERANCE FOR THE LAMBDA SEARCHING

Author:
Luis Alvarez
Returns:
return 0 if the test is satisfied

Definition at line 52 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int trivial_solution ( int  Nl,
int *  Np,
double *  a,
double **  xx,
double **  yy,
double  factor_n,
FILE *  fp1,
double *  trivial,
int  optimize_center 
)
Parameters:
NlNumber of lines
NpNumber of points/line
aLens distortion model polynom
xxCoordinates of points
yyCoordinates of points
factor_nFactor to normalize coordinates
fp1Pointer to the output file
trivialTrivial Emin,Vmin,Dmin values
optimize_centerTo optimize the center of distortion

Definition at line 1852 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

ami::image<unsigned char> undistort_image_inverse_fast ( ami::image< unsigned char >  input_image,
int  Na,
double *  a,
ami::point2d< double >  dc,
const double &  image_amplification_factor 
)

Definition at line 2299 of file lens_distortion.cpp.

Here is the call graph for this function:

Here is the caller graph for this function: