# Distortion model used in VidSync

To correct for non-linear distortion, such as the bulging "barrel" distortion characteristic of fisheye lenses (and present to a less obvious degree in most other wide-angle lenses), Vidsync uses a version of the Brown-Conrady distortion model with seven radial (k1, k2, k3, k4, k5, k6, k7) distortion coefficients (increased in version 1.62 from the previous and, widely-used three) and three tangential (p1, p2, p3) distortion coefficients as well as a flexible center of distortion (x0, y0).

It fits the model based on trying to straighten the plumblines by:

- Calculating an orthogonal regression through the points defining each plumbline.
- Calculating the squared distance between each point and the corresponding orthogonal regression line.
- Adding up all these squared distances to get the "Cost function" value, which we are trying to minimize.
- Adjusting the distortion parameters and corresponding plumbline point positions, and repeat until there is no more improvement between iterations.

As of version 1.62, VidSync reports two diagnostics to summarize the performance of the distortion correction:

- The
**remaining distortion per point**is root mean square error of all the plumbline points; in other words, it's roughly the average distance (in pixels) between the corrected position of a plumbline point and a straight orthogonal regression line through that corrected plumbline. - The
**distortion reduction achieved**is the initial value of the root mean square error (before any correction was applied), minus its final value after the correction, all divided by the initial value and given as a percentage. Reductions very close to 100 % are impossible because some of the root mean square error comes from random variation in the point positions, not correctable distortion. Values in the 80-90 % range are good.