Lenses and Optics

A pinhole camera makes a sharp image, but its tiny aperture starves the sensor of light. Widen the hole and the image blurs. This happens because every scene point now sprays light across many pixels. Real cameras solve this with a lens, a curved piece of glass. It bends many rays from one scene point back to one image point. This restores sharpness while admitting far more light. Understanding how a lens does this — and where it fails — is the bridge. It connects the idealized Pinhole Camera Model to the messy, physically grounded images that computer vision systems must actually process. This article develops the thin-lens model. It is the single most useful approximation for reasoning about focus, blur, and depth of field. We ask three questions that recur constantly in vision engineering. Given a lens of focal length ff and aperture diameter, what stays sharp and what blurs? How much light reaches the sensor? What systematic distortions does the lens introduce that a downstream algorithm must correct for? Autofocus systems, depth-from-defocus algorithms, camera calibration pipelines, and even the rendering of synthetic bokeh in phone cameras all rest on this model. The big picture is a trade. A pinhole trades light for sharpness by using an infinitesimal aperture. A lens trades a narrow depth of field for both light and sharpness. Widening the aperture lets in more photons and shortens exposure times. But it also shrinks the range of distances that appear in focus simultaneously. Every camera design is a negotiation. This includes a DSLR, a smartphone's tiny module, and a microscope objective. Each negotiates among focal length, aperture, sensor size, and the aberrations that appear once a lens departs from the ideal. By the end of this article you should be able to derive the thin-lens equation. You should be able to compute depth of field and circle of confusion for a given aperture. You should be able to explain why real lenses produce chromatic and spherical aberration plus radial distortion. You should also see how these effects motivate later topics such as Digital Images and Sampling, where the blur circle interacts with the pixel grid.

Key takeaways
  • A lens focuses a bundle of rays from one scene point onto one sensor point, unlike a pinhole which uses only one ray per point.
  • The thin-lens equation 1do+1di=1f\frac{1}{d_o} + \frac{1}{d_i} = \frac{1}{f} relates object distance, image distance, and focal length.
  • Points off the focused plane form a circle of confusion; its diameter sets the depth of field, the range that looks acceptably sharp.
  • Aperture size (f-number) controls both light gathering and depth of field: wider aperture means more light but shallower focus.
  • Real lenses deviate from the ideal via aberrations — spherical, chromatic, and geometric (radial) distortion — that must be calibrated out.
  • These optical effects set the physical input that later sampling and reconstruction stages, and depth-from-defocus algorithms, must model or invert.
The core insight

A lens trades the pinhole's perfect-but-dim sharpness for brightness, at the cost of a focus plane and a blur that grows with distance from it.

The idea

A pinhole camera forms an image by letting exactly one ray from each scene point pass through an infinitesimally small aperture. This guarantees perfect sharpness at any aperture size in principle, but a real pinhole must be small to avoid multiple overlapping rays, and a small hole admits very little light, forcing long exposures and motion blur. A lens replaces the pinhole with a piece of curved, transparent material that uses refraction to bend an entire cone of rays leaving one scene point back together at one point in the image plane, provided that scene point lies at the correct distance. This is the defining function of a lens: converting many rays into one point, so a wide aperture can be used without smearing the image. The thin-lens model idealizes a lens as an infinitesimally thin optical element characterized by a single number, its focal length ff. Parallel rays entering the lens (from an object infinitely far away) converge to a point at distance ff behind the lens, called the focal point. More generally, for an object at distance dod_o in front of the lens, the image forms at distance did_i behind the lens according to the thin-lens equation:

1do+1di=1f\frac{1}{d_o} + \frac{1}{d_i} = \frac{1}{f}

This equation is the optical analogue of the pinhole's perspective projection formula, and it reduces to the pinhole model as f→f \to the fixed image distance while the aperture shrinks to zero, which is why the pinhole model remains the correct limiting case for perspective geometry. Only object points satisfying this equation for the sensor's fixed distance did_i project to a sharp point; all other points project to a blurred disk called the circle of confusion (CoC). The aperture, usually specified by its diameter AA or by the dimensionless f-number N=f/AN = f/A, controls two things simultaneously: the amount of light collected (proportional to A2A^2) and the size of the CoC for out-of-focus points (also proportional to AA). This coupling — you cannot get more light without also getting shallower focus — is the central engineering tension in lens design and is quantified by depth of field, the range of object distances whose CoC stays below a chosen acceptable blur threshold (often tied to the sensor's pixel pitch, foreshadowing Digital Images and Sampling).

How it works

Step 1 — Focusing. Given a desired object distance dod_o (the plane you want sharp), solve the thin-lens equation for the image distance and physically position the sensor, or move the lens, so that did_i matches:

di=(1f−1do)−1d_i = \left(\frac{1}{f} - \frac{1}{d_o}\right)^{-1}

Autofocus systems repeatedly evaluate a sharpness metric (e.g., high-frequency energy in the image) while sweeping did_i mechanically, effectively performing a 1-D search over this equation.

Step 2 — Circle of confusion for off-plane points. For a scene point at true distance dd, the lens forms a sharp image at di′=(1/f−1/d)−1d_i' = (1/f - 1/d)^{-1}, but the sensor sits fixed at did_i (tuned for the focused distance dod_o). The mismatch ∣di′−di∣|d_i' - d_i| spreads light into a disk on the sensor. By similar triangles with the aperture diameter AA:

c=A⋅∣di′−di∣di′c = A \cdot \frac{|d_i' - d_i|}{d_i'}

where cc is the CoC diameter. Substituting the thin-lens relations gives cc as an explicit function of dd, dod_o, ff, and the f-number N=f/AN = f/A.

Step 3 — Depth of field bounds. Fix an acceptable CoC diameter cmaxc_{max} (tied to what a viewer or sensor can resolve). Solve c(d)=cmaxc(d) = c_{max} for the near and far distances Dn<do<DfD_n < d_o < D_f that bound the acceptably sharp range. A standard closed-form result, derived from the same similar-triangles argument, is:

Dn=dof2f2+Ncmax(do−f),Df=dof2f2−Ncmax(do−f)D_n = \frac{d_o f^2}{f^2 + N c_{max}(d_o - f)}, \qquad D_f = \frac{d_o f^2}{f^2 - N c_{max}(d_o - f)}

(with Df→∞D_f \to \infty when the denominator becomes non-positive — the hyperfocal case). Depth of field is Df−DnD_f - D_n.

Step 4 — Aberration correction (a calibration-time step). Real lenses are not ideal thin lenses; they introduce radial and tangential geometric distortion and wavelength-dependent focusing errors. A vision pipeline typically calibrates a distortion model (e.g., Brown–Conrady radial-tangential polynomial) once per lens/camera, then undistorts every subsequent image before geometric algorithms (stereo, structure-from-motion) are applied. ``` function DEPTH_OF_FIELD(f, N, d_o, c_max):

# f : focal length

# N : f-number (N = f / aperture_diameter)

# d_o : focused object distance

# c_max : acceptable circle-of-confusion diameter assert f > 0 and N > 0 and d_o > f # object must be beyond focal length denom_near = ff + N c_max (d_o - f) denom_far = ff - N c_max (d_o - f) D_n = (d_o ff) / denom_near if denom_far <= 0: D_f = INFINITY # everything past D_n is in focus else: D_f = (d_o ff) / denom_far return D_n, D_f

function CIRCLE_OF_CONFUSION(f, N, d_o, d):

# d : true distance of a scene point A = f / N d_i = 1 / (1/f - 1/d_o) # image distance for focused plane d_i2 = 1 / (1/f - 1/d) # image distance this point would need c = A * abs(d_i2 - d_i) / d_i2 return c

function AUTOFOCUS_SEARCH(sensor_positions, sharpness_metric):

# coarse-to-fine 1-D search over image distance d_i best_pos, best_score = None, -INFINITY for d_i in sensor_positions: # e.g., binary/golden-section search move_sensor_or_lens_to(d_i) img = capture_frame() score = sharpness_metric(img) # e.g., sum of squared gradients if score > best_score: best_score, best_pos = score, d_i return best_pos ```

Figure
Thin-lens ray geometry: focused plane, near/far blur limits, and circle of confusion
lens (f) object @ d_o sharp point near point (D_n) sensor (d_i) circle of confusion D_n d_o (focused plane)

Complexity & correctness

Computational complexity. All quantities of interest — image distance, circle of confusion, near/far depth-of-field bounds — are closed-form algebraic expressions in ff, NN, dod_o, and dd. Evaluating them is O(1)O(1) time and space; there is no search or iteration in the core optics. The only algorithmic component with nontrivial cost is autofocus search, which evaluates a sharpness metric at kk candidate sensor positions. A naive linear sweep is O(k)O(k) evaluations; because sharpness-vs-position is unimodal near the true focus (a single peak, falling off monotonically on each side under the thin-lens model), golden-section or ternary search finds the optimum in O(log⁡(1/ε))O(\log(1/\varepsilon)) evaluations for a desired precision ε\varepsilon, each evaluation costing O(WH)O(WH) to compute a gradient-energy score over a W×HW \times H image. Total autofocus cost is O(WHlog⁡(1/ε))O(WH \log(1/\varepsilon)), versus O(WH⋅k)O(WH \cdot k) for exhaustive search — a substantial saving for fine-grained mechanical focus ranges.

Correctness of the thin-lens equation. The derivation follows from two idealized refraction assumptions: (1) parallel rays converge exactly at the focal point ff, and (2) the lens is thin enough that ray bending is treated as happening at a single plane. Under paraxial (small-angle) approximation, similar triangles formed by a ray through the lens center (undeviated) and a ray parallel to the axis (bent through the focal point) yield 1/do+1/di=1/f1/d_o + 1/d_i = 1/f directly — this is a geometric identity, not an empirical fit, so it holds exactly within the paraxial regime and approximately outside it.

Correctness of the depth-of-field formula. The CoC formula follows from similar triangles between the aperture (diameter AA) and the mismatch disk at the sensor: a ray bundle converging at distance di′d_i' but intercepted at did_i spreads over a diameter scaled by ∣di−di′∣/di′|d_i - d_i'|/d_i', the same ratio that governs how a shadow's penumbra grows with distance from its true focus. Setting c(Dn)=c(Df)=cmaxc(D_n) = c(D_f) = c_{max} and solving the resulting linear equations in 1/d1/d gives the closed forms in Step 3; this is exact under the thin-lens/paraxial model and is the standard derivation used in photographic optics.

Honest tradeoffs.

  • The thin-lens model ignores lens thickness, multi-element compound lenses, and non-paraxial (wide-angle) rays; real zoom and wide-angle lenses require multi-element ray-tracing models for sub-pixel accuracy.
  • The CoC-based depth-of-field criterion is threshold-dependent: cmaxc_{max} is a human/engineering choice (often one to a few sensor pixels), so "depth of field" is not a physical constant but an acceptability convention.
  • Diffraction is neglected: at very small apertures (large NN), diffraction — not geometric blur — dominates and can increase blur, so depth of field does not shrink monotonically as the aperture is closed forever; extremely stopped-down lenses actually lose sharpness overall.
  • Chromatic and spherical aberrations (below) are entirely outside the thin-lens equation and require separate correction models.

Worked example

Consider a 50 mm lens (f=50 mmf = 50\text{ mm}) focused at do=3000 mmd_o = 3000\text{ mm} (3 m), aperture set to N=4N = 4 (so A=f/N=12.5 mmA = f/N = 12.5\text{ mm}), and an acceptable circle of confusion cmax=0.03 mmc_{max} = 0.03\text{ mm} (a common full-frame convention).

Step 1: image distance for the focused plane.

1di=1f−1do=150−13000=0.02−0.000333=0.019667\frac{1}{d_i} = \frac{1}{f} - \frac{1}{d_o} = \frac{1}{50} - \frac{1}{3000} = 0.02 - 0.000333 = 0.019667
di≈50.85 mmd_i \approx 50.85\text{ mm}

Step 2: near and far limits.

Dn=dof2f2+Ncmax(do−f)=3000⋅25002500+4⋅0.03⋅2950=7,500,0002500+354=7,500,0002854≈2627 mmD_n = \frac{d_o f^2}{f^2 + N c_{max}(d_o - f)} = \frac{3000 \cdot 2500}{2500 + 4 \cdot 0.03 \cdot 2950} = \frac{7{,}500{,}000}{2500 + 354} = \frac{7{,}500{,}000}{2854} \approx 2627\text{ mm}
Df=dof2f2−Ncmax(do−f)=7,500,0002500−354=7,500,0002146≈3495 mmD_f = \frac{d_o f^2}{f^2 - N c_{max}(d_o - f)} = \frac{7{,}500{,}000}{2500 - 354} = \frac{7{,}500{,}000}{2146} \approx 3495\text{ mm}

So everything between roughly 2.63 m and 3.50 m appears acceptably sharp — a depth of field of about 87 cm centered slightly behind the focused 3 m plane (typical of the thin-lens asymmetry, where Df−do>do−DnD_f - d_o > d_o - D_n).

Step 3: check a specific out-of-focus point. Suppose an object sits at d=10,000 mmd = 10{,}000\text{ mm} (10 m), well beyond DfD_f.

di′=(150−110000)−1=(0.02−0.0001)−1=10.0199≈50.25 mmd_i' = \left(\frac{1}{50} - \frac{1}{10000}\right)^{-1} = (0.02 - 0.0001)^{-1} = \frac{1}{0.0199} \approx 50.25\text{ mm}
c=A⋅∣di′−di∣di′=12.5⋅∣50.25−50.85∣50.25=12.5⋅0.6050.25≈0.149 mmc = A \cdot \frac{|d_i' - d_i|}{d_i'} = 12.5 \cdot \frac{|50.25 - 50.85|}{50.25} = 12.5 \cdot \frac{0.60}{50.25} \approx 0.149\text{ mm}

This is about 5× the acceptable threshold of 0.03 mm, confirming that a 10 m background is visibly blurred — consistent with it lying far outside [Dn,Df][D_n, D_f].

QuantitySymbolValue
Focal lengthff50 mm
F-numberNN4
Aperture diameterAA12.5 mm
Focused distancedod_o3000 mm
Image distancedid_i50.85 mm
Near limitDnD_n2627 mm
Far limitDfD_f3495 mm
CoC at 10 mcc0.149 mm (blurred)

Doubling the aperture to N=2N = 2 (twice the light, four times the collecting area) roughly halves NcmaxNc_{max} in the denominators, shrinking the depth of field substantially — a direct numerical illustration of the light-versus-sharpness trade this article opened with.

Common pitfalls & traps

PitfallWhy it happensFix
Confusing focal length with focus distanceBoth are "distances" in the equation, easy to swapRemember ff is a fixed lens property; do,did_o, d_i vary with what you focus on
Assuming depth of field is symmetric around the focused planeIntuition from a simple blur modelThe far limit extends further than the near limit; the asymmetry grows as do→d_o \to hyperfocal distance
Treating aperture and depth of field as independent controlsPhotographers often set them for exposure onlyAperture change affects both brightness (∝A2\propto A^2) and DoF simultaneously — they cannot be tuned separately
Ignoring diffraction at very small aperturesGeometric optics model has no diffraction termBeyond a lens' diffraction limit, stopping down further reduces sharpness; do not extrapolate DoF formulas indefinitely
Applying the thin-lens model to wide-angle or compound zoom lenses without correctionThin-lens is a paraxial single-element idealizationUse a calibrated distortion model (radial + tangential) before geometric vision algorithms
Forgetting units consistency (mm vs. m) across ff, dod_o, cmaxc_{max}Formulas mix a small ff (mm) with a large dod_o (often meters)Convert everything to one unit before plugging into the CoC/DoF formulas

Beyond focus and depth of field, real lenses introduce further departures from the ideal thin-lens model that a vision system must handle explicitly:

  • Spherical aberration: rays passing through the lens edge focus at a slightly different distance than rays through the center, because real lens surfaces are spherical, not the ideal parabolic shape assumed implicitly by paraxial theory. This softens focus even exactly at the nominal focal plane, especially at wide apertures.
  • Chromatic aberration: the refractive index of glass depends on wavelength, so the effective focal length differs slightly for red, green, and blue light. This produces color fringing at high-contrast edges, worst near image corners, and must be corrected either by multi-element achromatic lens design or by per-channel software warping.
  • Radial (geometric) distortion: magnification varies with distance from the optical axis, producing barrel distortion (magnification decreases outward, common in wide-angle lenses) or pincushion distortion (magnification increases outward, common in telephoto lenses). This is modeled and corrected with a polynomial in radius, e.g. rd=ru(1+k1ru2+k2ru4+… )r_d = r_u(1 + k_1 r_u^2 + k_2 r_u^4 + \dots), fit during camera calibration alongside the pinhole intrinsics.
  • Vignetting: light falloff toward image corners due to the aperture's effective shape and area shrinking off-axis, corrected by a per-pixel gain map.

Pioneers & history

The mathematics of image formation by lenses grew out of centuries of experimental and theoretical optics, long before photography or computer vision existed, and computer vision inherited the thin-lens formalism essentially unchanged from classical optics.

Origins · 1 minJohannes Kepler and how this was discovered
JK
Johannes Kepler
1571–1630 · Formalized the geometric theory of image formation through lenses, describing how the eye and telescope focus light, laying groundwork for later lens equations

CF
Carl Friedrich Gauss
1777–1855 · Developed paraxial (Gaussian) optics, the small-angle approximation underlying the thin-lens equation used throughout modern camera and computer vision optics

History
1611
— Kepler's Dioptrice describes image formation by converging lenses.
1841
— Carl Friedrich Gauss publishes his dioptrics work formalizing paraxial (Gaussian) optics.
1888
— George Eastman commercializes roll-film cameras, driving demand for compact multi-element lenses.
1966
— Duane C. Brown develops the radial-tangential distortion model still used in camera calibration today.
2000
s — Depth-from-defocus and computational photography techniques (e.g., coded aperture, light-field cameras) exploit lens blur models directly for depth estimation.

Where this matters

Autofocus systems in phones and cameras solve exactly the 1-D search over the thin-lens equation described above, using contrast-detection or phase-detection sensors as fast proxies for sharpness. Camera calibration toolchains (used before any stereo reconstruction, Structure from Motion-style pipelines, or augmented reality tracking) fit a radial-tangential distortion model per lens and undistort every frame before applying the pinhole projection geometry that later algorithms assume. Computational photography features like portrait-mode "bokeh" simulate a wide-aperture shallow depth of field on cameras with physically small apertures, by estimating a depth map and synthetically applying a spatially varying circle-of-confusion blur — directly inverting the model taught here. Depth-from-defocus and depth-from-focus algorithms in robotics and microscopy estimate scene depth by measuring the CoC size across a focal stack and inverting the depth-of-field equations. Lens design software for machine-vision cameras (used in manufacturing inspection and autonomous vehicles) optimizes multi-element systems to minimize the aberrations described above while meeting cost and size constraints. All of these downstream systems assume clean, focused, geometrically calibrated pixels — the physical layer this article describes sits directly beneath the pixel grid discussed in Digital Images and Sampling.

Ask the tutor: How does depth-from-defocus use the circle-of-confusion equation to recover scene depth from a focal stack of images?

Why can't a pinhole camera just use a bigger hole for more light, avoiding lenses entirely?

A pinhole forms an image by letting only one ray direction from each scene point reach each sensor point. Widening the hole lets multiple rays from a single scene point reach multiple sensor points simultaneously, so each image location now receives light from a range of scene points — this is blur, and it grows directly with hole size. A lens solves the problem structurally: it bends the entire cone of rays from one in-focus scene point back to a single sensor point via refraction, so a wide aperture (lots of light) and a sharp image are no longer in direct conflict, at least for points on the focused plane. The cost is that only one distance stays perfectly sharp, and the rest fall off according to the depth-of-field formulas — a fundamentally different tradeoff than the pinhole's uniform-but-dim sharpness.

What exactly is the "circle of confusion," and why is it a circle rather than a point?

When a scene point lies exactly on the focused plane, all rays through the aperture converge to a single sensor point, an idealized point image. For any other scene point, the rays converge either in front of or behind the sensor plane, so where they actually intersect the sensor, they form a small disk rather than a point — this disk is the circle of confusion. Its diameter depends on how far the point is from the focused plane and on the aperture diameter, per the similar-triangles derivation in this article. A circle (rather than some other shape) results because a standard aperture is circular; cameras with polygonal aperture blades produce polygonal "bokeh" shapes instead, visible in out-of-focus highlights.

Is depth of field a fixed physical property of a lens, or does it depend on choices the photographer or engineer makes?

It depends on a chosen threshold. Depth of field is defined as the range of distances whose circle of confusion stays below some acceptable diameter cmaxc_{max}, and that threshold is a convention, not a physical constant — commonly tied to what a human eye can resolve at a standard viewing distance and print size, or to a camera's pixel pitch in computational applications. Changing cmaxc_{max} changes DnD_n and DfD_f even though nothing about the lens or aperture changed. This is why "depth of field" values quoted by camera manufacturers assume a specific viewing condition, and why machine-vision systems typically redefine cmaxc_{max} in terms of sensor pixels rather than human perception.

How does aperture size trade off against exposure time and depth of field in practice?

The amount of light reaching the sensor per unit time scales with the aperture area, proportional to A2A^2 or equivalently 1/N21/N^2 where NN is the f-number. A wider aperture (smaller NN) gathers more light, allowing a shorter exposure time for the same total brightness — useful for freezing motion or shooting in low light. But the same wider aperture increases the circle of confusion for any given out-of-focus distance, shrinking the depth of field per the formulas derived above. Photographers and vision-system designers must jointly choose aperture, exposure time, and sensor sensitivity (ISO/gain) to satisfy brightness, motion-blur, and depth-of-field requirements simultaneously — no single setting optimizes all three.

Why do wide-angle lenses typically show barrel distortion while telephoto lenses show pincushion distortion?

Both are consequences of how magnification varies with radial distance from the optical axis in real, non-ideal lens systems, which the thin-lens model does not capture at all. Wide-angle lens designs generally compress magnification toward the edges of the frame relative to the ideal pinhole projection, causing straight lines away from the center to bow outward, which is barrel distortion. Telephoto and zoomed-in configurations often do the opposite, with edge magnification exceeding the ideal, causing lines to bow inward — pincushion distortion. Both are modeled with the same radial polynomial (e.g., the Brown–Conrady model) fit during camera calibration, with the sign and magnitude of the coefficients determining which type of distortion appears.

How does the thin-lens model relate back to the pinhole camera model used earlier?

The thin-lens model reduces to the pinhole model in a specific limiting case: as the aperture diameter shrinks toward zero, the circle of confusion shrinks toward zero for every object distance simultaneously, meaning everything becomes acceptably sharp regardless of the focused distance. In that limit, the lens behaves exactly like a pinhole, and the thin-lens equation's role in fixing did_i becomes irrelevant because there is no blur to control. The pinhole model is therefore the zero-aperture, infinite-depth-of-field special case of the more general thin-lens model, which is why perspective projection geometry (used for calibration, stereo, and 3-D reconstruction) is typically derived from the pinhole model even when the physical camera uses a real lens.

Why does this topic matter for later work on digital images and sampling?

The lens delivers a continuous, blurred irradiance pattern onto the sensor plane before any discretization happens; the circle of confusion effectively low-pass filters fine scene detail before it ever reaches a pixel. Whether that blur helps or hurts depends on its interaction with the sensor's pixel pitch: a circle of confusion smaller than a pixel is invisible, while one much larger than a pixel spreads a scene edge over many samples, and one comparable in size to the pixel pitch can interact with sampling in nontrivial ways relevant to aliasing. Understanding the lens's optical blur is therefore a prerequisite for reasoning correctly about how a continuous scene becomes a discrete image, the subject taken up next.

Before this

Where this leads