I'm having a hard time understanding the distortion model of OpenCV. They use "radial" coefficients $k_n$ and "tangential" coefficients $p_n$ among others that I am not interested in.
$$ x' = x (1 + k_1 r^2 + k_2 r^4 + k_3 r^6) + 2 p_1 x y + p_2(r^2 + 2 x^2) \\ y' = y (1 + k_1 r^2 + k_2 r^4 + k_3 r^6) + p_1 (r^2 + 2 y^2) + 2 p_2 x y $$
To understand this, I separated the two terms into what $\Delta$ offset they produce, here's how that looks for $x$:
$$ \begin{array}{rlcccc} x' &= x &+ &\underbrace{x(k_1 r^2 + k_2 r^4 + k_3 r^6)} &+ &\underbrace{2 p_1 x y + p_2(r^2 + 2 x^2)}\\ &= x &+ &\Delta x_{radial} &+ &\Delta x_{tangential} \end{array} $$
Then I plotted those values as a vector field with octave (similar to Matlab).
Radial Distortion
function radialDistortion (k1, k2, k3)
max = 10;
[x, y] = meshgrid(-max:.5:max);
r2 = x.**2 + y.**2;
k = k1*r2 .+ k2*r2.**2 .+ k3*r2.**3;
quiver(x, y, x.*k, y.*k, 0);
axis("square");
endfunction
Called with
radialDistortion(0.0002, 0, 0)
produces the following
I get it, this is radial to the optical axis, thus being point symmetric to the center (where the optical axis is). This wasn't too difficult.
Tangential Distortion
function tangentialDistortion (p1, p2)
max = 10;
[x, y] = meshgrid(-max:.5:max);
r = x.**2 + y.**2;
xy = x.*y*2;
quiver(x, y, xy*p1 + (r+2*x.**2)*p2, xy*p2 + (r+2*y.**2)*p1, 0);
axis("square");
endfunction
Called with
tangentialDistortion(-.0007, .0007)
produces this
How is this "tangential" to anything? To me, it looks like it is correcting for a lens that's tilted (rotated around the bottom-left-to-top-right diagonal) which agrees with the reason for this distortion given in the literature: lens misalignment.
Does that mean it's tangential to the surface of the lens?
In the end, it's some mathematical model that describes some optical phenomenon in order to correct it. But I'd like to understand why this is called "tangential".
If the position of P' is also displaced tangentially relative to CP (along the tangent to the circle of radius CP), the distortion is said to be tangential.
No, it isn't. I modified the above function to show the "tangential" displacement of points that are on a circle.
function tangentialDistortionOnCircle (p1, p2)
radius = 10;
x = radius * cos(0:2*pi/20:2*pi);
y = radius * sin(0:2*pi/20:2*pi);
r = x.**2 + y.**2;
xy = x.*y*2;
quiver(x, y, xy*p1 + (r+2*x.**2)*p2, xy*p2 + (r+2*y.**2)*p1, 0);
axis([-radius-5 radius+5 -radius-5 radius+5 ], "square");
endfunction
Called with these parameters:
tangentialDistortionOnCircle(.007, .007)
gives this result
This doesn't look like a tangential displacement to me at all. If it was, it would look like a swirl around the center. But that's not the case.