Skip to content
AI360Xpert
Beta

Lens Distortion: Radial and Tangential

Real lenses bend straight lines, so every photo carries a small warp. Lens distortion names that warp with a few coefficients, and undistortion removes it before you measure anything.

A negative k1 bends straight lines outward into barrel distortion; undistortion multiplies each radius back
A negative k1 bends straight lines outward into barrel distortion; undistortion multiplies each radius back

Why Does This Exist?

The pinhole model pretends light travels in perfectly straight lines onto a flat sensor. Real glass is curved, so hallway edges bow outward in a wide-angle shot and inward at full zoom. Any measurement taken on the raw pixels inherits that bend: a straight wall reads as curved, and a projection matrix fitted to bent pixels absorbs the error into the wrong focal length.

The fix is a small parametric warp applied before the pinhole math. The pinhole half is intrinsic parameters; the procedure that estimates both halves is camera calibration. This page names the warp, works one corner through it, and says when to apply it.

Think of It Like This

A peephole in a hotel door

Look through a door peephole and the corridor stays recognizable but wrong: the center reads fine while the edges balloon outward. One number captures most of it, how strongly the rim stretches relative to the center.

That number is k1k_1. The analogy stops at sensor tilt: a peephole is symmetric by construction, while a real lens can sit slightly crooked on its sensor, adding the tangential terms below.

How It Actually Works

Work in normalized coordinates (xn,yn)(x_n, y_n), meaning pixel offsets from the principal point divided by focal length. Let r2=xn2+yn2r^2 = x_n^2 + y_n^2 be the squared radius. With radial coefficients k1,k2k_1, k_2 and tangential coefficients p1,p2p_1, p_2, the distorted point is:

xd=xn(1+k1r2+k2r4)+2p1xnyn+p2(r2+2xn2)x_d = x_n (1 + k_1 r^2 + k_2 r^4) + 2 p_1 x_n y_n + p_2 (r^2 + 2 x_n^2)

and symmetrically for ydy_d. Negative k1k_1 pulls points toward the center (barrel distortion, typical of wide lenses); positive k1k_1 pushes them outward (pincushion, typical at telephoto). Undistortion inverts this map, usually by iteration, and only then does the pinhole projection apply. Stereo vision depends on this order: rectification assumes already-straight rays.

Worked numbers

Take the normalized corner (0.5,0.5)(0.5, 0.5) with k1=−0.3k_1 = -0.3, k2=0.08k_2 = 0.08, and no tangential terms. Then r2=0.5r^2 = 0.5 and r4=0.25r^4 = 0.25:

factor=1−0.3×0.5+0.08×0.25=1−0.15+0.02=0.87\text{factor} = 1 - 0.3 \times 0.5 + 0.08 \times 0.25 = 1 - 0.15 + 0.02 = 0.87

so (xd,yd)=(0.435,0.435)(x_d, y_d) = (0.435, 0.435). The corner renders at 8787 percent of its ideal radius: textbook barrel, strongest exactly where wide photos look most bent.

Code

def distort(xn: float, yn: float, k1: float, k2: float) -> tuple[float, float]:    r2 = xn * xn + yn * yn  # squared radius from the optical center    f = 1.0 + k1 * r2 + k2 * r2 * r2    return (round(f * xn, 3), round(f * yn, 3))

print(distort(0.5, 0.5, -0.3, 0.08))  # -> (0.435, 0.435)

Watch Out For

Calibrating distortion with center-only boards

k1k_1 is nearly unobservable if the checkerboard never visits the frame rim, because the warp is tiny near the center. The fit then reports success while straight edges still bow at the corners. The fix is coverage, not more shots: tilt the board and push it into every corner of the frame so the optimizer actually sees the bend.

Measuring before undistorting

The pipeline order is undistort, then project. Measuring raw pixels against the pinhole model folds the lens bend into the focal length and principal point, and the resulting KK quietly fits one depth while failing the next. Warp the pixels straight first; only straight rays obey u=fxXc/Zc+cxu = f_x X_c / Z_c + c_x.

The Quick Version

  • Radial distortion scales each point by 1+k1r2+k2r41 + k_1 r^2 + k_2 r^4 around the optical center.
  • Negative k1k_1 gives barrel distortion; positive k1k_1 gives pincushion.
  • Tangential terms p1,p2p_1, p_2 cover a lens sitting crooked on its sensor.
  • Undistortion runs before projection, never after measurement.
  • Distortion coefficients are only observable where the board visits, so cover the frame corners.