How to calculate the inverse of a known optical distortion function?

6.6k Views Asked by At

Assume I have the following lens distortion function:

$$ x' = x (1 + k_1 r^2 + k_2 r^4) \\ y' = y (1 + k_1 r^2 + k_2 r^4) $$

where $r^2 = x^2 + y^2$. Given coefficients $k_1$ and $k_2$, I need to calculate the inverse function:

$$ x = f(x') = \, ?\\ y = f(y') = \, ? $$

This inverse function can be an estimate as well, e.g., a polynomial function whose coefficients can be calculated with numerical methods.

My problem is the following:

Given a picture, generate another picture by simulating lens distortion. I want to create another program, which given the output of the first one and the coefficients of the lens distortion function used, will calculate the original image.

First I tried:

$$ x = { x' \over 1 + k_1r'^2 + k_2r'^4}\\ y = { y' \over 1 + k_1r'^2 + k_2r'^4} $$

However, since $r'^2=x'^2+y'^2\neq r^2$, this won't give the original values of $x$ and $y$.

I was thinking then if I can use a similar formula, but different coefficients:

$$ x = x' (1 + k'_1r'^2 + k'_2r'^4)\\ y = y' (1 + k'_1r'^2 + k'_2r'^4) $$

where $k'_1$ and $k'_2$ would be calculated from $k_1$ and $k_2$.

But I'm open to any suggestion.

3

There are 3 best solutions below

3
On

please see this link (http://www.mdpi.com/1424-8220/16/6/807/pdf).

In this article, the authors present a new approach to calculating the inverse of radial distortions. The method presented there provides a model of reverse radial distortion, currently modeled by a polynomial expression, that proposes another polynomial expression where the new coefficients are a function of the original ones.

2
On

The map $f:\>(x,y)\mapsto(x',y')$ is rotationally symmetric: It maps concentric circles of radius $r$ to concentric circles of radius $r'=r(1+c_1 r^2+c_2 r^4)$, and ${\rm arg}(x',y')={\rm arg}(x,y)$. We therefore just have to invert the function $$\psi:\quad r\mapsto s=r(1+c_1 r^2+c_2 r^4)\ ,$$ where I have written $s$ instead of $r'$. This can be done with a power series to any desired accuracy. One obtains $$r=s\bigl(1-c_1 s^2+(3c_1^2-c_2)s^4-4(3c_1^3-2c_1c_2)s^6+ \ ?s^8\bigr)\ ,$$ so that $f^{-1}$ appears as $$\eqalign{x&=x'(1-c_1r'^2+(3c_1^2-c_2)r'^4-\ldots) \cr y&=y'(1-c_1r'^2+(3c_1^2-c_2)r'^4-\ldots) \ .\cr}$$

1
On

For moderate distortion, you can use a single step of Newton, starting with the approximation $r'_0\approx r=\sqrt{x^2+y^2}$.

Then

$$r'_1={r'_0}-\frac{r'_0(1+k_1{r'_0}^2+k_2{r'_0}^4)-r}{1+3k_1{r'_0}^2+5k_2{r'_0}^4}.$$

Then as there is no tangential distortion,

$$x'_1=x\frac{r'_1}r,y'_1=y\frac{r'_1}r.$$

For stronger distortion, you can add a few iterations (or change lens :-) )