No jobs
Core 8 min 4 of 4

Lens distortion

The pinhole model is a lie about real lenses, and the correction is not invertible in closed form.

What this repairs

Assuming distortion is a small cosmetic effect, and that "undistort" and "distort" are the same operation run backwards.

A pinhole has no lens, and therefore no distortion, and also almost no light. Real cameras use lenses, and real lenses bend rays by an amount that depends on where they hit the glass. The standard model is a polynomial correction applied to the normalised coordinates, before KK :

(xdyd)=(1+k1r2+k2r4+k3r6)(xnyn)+(2p1xnyn+p2(r2+2xn2)p1(r2+2yn2)+2p2xnyn),\begin{pmatrix} x_d \\ y_d \end{pmatrix} = (1 + k_1 r^2 + k_2 r^4 + k_3 r^6) \begin{pmatrix} x_n \\ y_n \end{pmatrix} + \begin{pmatrix} 2p_1 x_n y_n + p_2(r^2 + 2x_n^2) \\ p_1(r^2 + 2y_n^2) + 2p_2 x_n y_n \end{pmatrix},

with r2=xn2+yn2r^2 = x_n^2 + y_n^2 . The first term is radial — the dominant effect, symmetric about the principal point. The second is tangential, and models a lens whose axis is not quite perpendicular to the sensor.

Check yourself

Your reprojection error is 0.3 px in the image centre and 2.5 px at the corners after calibration. What is the likely cause?

Show answer

An under-parameterised distortion model. A radially growing residual is the signature of unmodelled radial distortion — you probably fitted k1k_1 only, on a lens that needs k2k_2 as well, or you fitted a pinhole model to a wide lens. Adding parameters blindly is not the answer either: with few observations near the edge, a high-order model will fit noise and produce wild extrapolation outside the calibrated region.

Euler View - ML Experiment Monitor