Lenses and Depth of Field: What You Buy With Light, and What It Costs
Lesson 2 of the Image Formation unit. A lens buys the brightness a pinhole cannot have and charges a plane of focus for it. Worked on a published scene: 93 mm at f/4 focused at 1.52 m is sharp from 1.500 m to 1.550 m, a band 5 cm deep. Stopping down to f/22 widens it to 0.277 m, a factor of 5.54 against an aperture ratio of 5.50, and the circle of confusion behind those numbers comes out at 0.0248 mm.
A lens can bring only one distance into perfect focus, and things nearer or farther blur more the further they are from it. Below, the band of sharp focus moves from the far side of a court to the near side and back.

You have seen depth of field used on purpose:
- Portrait mode on a phone blurs the background to imitate a large lens focused on the subject.
- Tilt-shift “miniature” photographs look like models because only a thin band is sharp, as it would be for a camera very close to a small subject.
- Focus pulls in film, where the sharp distance moves from one actor to another during a shot.
A lens gathers a whole cone of light where a pinhole admits one ray, and the price is that only one distance is sharp. On a published scene at 93 mm and f/4 the sharp band is 5 cm deep; at f/22 it is 0.277 m, 5.54 times deeper for an aperture ratio of 5.50.
Where we are
Lesson 2 of image formation, and the focus question that branches off the pipeline at the ray: is a point’s light a dot or a disc? Lesson 1 ended on the reason nobody builds a pinhole camera: a hole small enough to give one ray per pixel passes almost no light. Opening it admits more, and each sensor point starts receiving a cone rather than a ray, which is blur. A lens is the way out of that trade, and it comes with a bill.
A lens bends the cone back to a point
The pinhole rejects all the light that does not travel in one direction, and the lens redirects it instead. Rays leaving one scene point in many directions are bent so they meet again at one point behind the glass. Nothing is thrown away, so the sensor receives the whole cone the aperture admits, and the exposure that took minutes takes milliseconds [1].
That convergence only works for one object distance at a time. For an object at distance in front of a lens of focal length , the rays meet at image distance given by the thin-lens equation:
The sensor sits at one fixed , so exactly one is imaged as a point. Every other distance has its cone still converging, or already diverging again, when it reaches the sensor, and it lands as a disc instead. The diameter of that disc for a point at distance is
where is the f-number, defined so that the aperture diameter is . Both places appears say the same thing: a smaller opening makes a narrower cone, and a narrower cone spreads less by the time it lands.
In focus is a tolerance, not a fact
Nothing except one plane is truly in focus, so “in focus” has to mean blurred by less than we can see. That threshold is the circle of confusion , and it is a claim about the sensor and the viewer rather than about the lens. Setting and solving gives the near and far limits, usually written through the hyperfocal distance :
That last agreement is the part worth keeping. Over a range where the subject distance is much larger than the focal length, depth of field grows in proportion to the f-number. One stop multiplies by , so a photographer who stopped down three stops (f/4 to f/11) knows the band got about times deeper without computing anything.
def dof_limits(f_mm, n, subject_m, coc_mm=0.02476):
"""Near and far limits of acceptable focus, in metres."""
f = f_mm / 1000
a = f * f / (n * coc_mm / 1000) # hyperfocal minus f
u = subject_m - f
far = float("inf") if u >= a else subject_m * a / (a - u)
return subject_m * a / (a + u), far// Near and far limits of acceptable focus, in metres.
std::pair<double, double> dof_limits(double f_mm, double n, double subject_m,
double coc_mm = 0.02476) {
const double f = f_mm / 1000.0;
const double a = f * f / (n * coc_mm / 1000.0); // hyperfocal minus f
const double u = subject_m - f;
const double far = (u >= a) ? std::numeric_limits<double>::infinity()
: subject_m * a / (a - u);
return {subject_m * a / (a + u), far};
}Now you try
Start on the scene above and stop down one aperture at a time; the green band on the depth axis grows in step with the f-number. Then drag the subject closer and watch it collapse, and switch the sensor format to see every number move without the lens changing at all.
How close is this to the published figure?
OpenCV has no depth-of-field call, so the check here is against the photograph’s own caption: the formula above, fed the two numbers recovered from the f/4 interval, must give that interval back and predict the f/22 one.
def dof_limits(f_mm, n, subject_m, coc_mm=0.02476):
"""Near and far limits of acceptable focus, in metres."""
f = f_mm / 1000
a = f * f / (n * coc_mm / 1000) # hyperfocal minus f
u = subject_m - f
far = (float("inf") if u >= a
else subject_m * a / (a - u))
return subject_m * a / (a + u), far
# DPDD prints 1.50-1.55 m at f/4; recover what it does not print
s = 2 * 1.50 * 1.55 / (1.50 + 1.55) # subject distance
for n in (4, 22):
near, far = dof_limits(93, n, s)
print(f"f/{n}: {near:.3f} to {far:.3f} m, "
f"depth {far - near:.3f} m")f/4: 1.500 to 1.550 m, depth 0.050 m f/22: 1.398 to 1.676 m, depth 0.277 m
# against the published figure and the aperture ratio
near4, far4 = dof_limits(93, 4, s)
near22, far22 = dof_limits(93, 22, s)
print("f/4 published 1.50 to 1.55, computed",
round(near4, 2), "to", round(far4, 2))
print("depth ratio:",
round((far22 - near22) / (far4 - near4), 2),
" aperture ratio:", 22 / 4)f/4 published 1.50 to 1.55, computed 1.5 to 1.55 depth ratio: 5.54 aperture ratio: 5.5
The f/4 interval comes back to the centimetre, which is a consistency check: two numbers were recovered from that interval. The f/22 prediction and the ratio of 5.54 against 5.50 are the part that was not fitted.
In the wild
Every photograph carries the numbers this lesson needs, in its own EXIF. Here is one that does, and the prediction can be checked against the picture.
A market stall shot on a Nikon D750 at 300 mm, f/4, with the camera recording a subject distance of 14.96 m. Feeding that to the depth-of-field relation, with the usual 0.030 mm circle of confusion for full frame:
What it means: at fifteen metres, a 300 mm lens at f/4 holds 59 centimetres in focus: a slice through the stall rather than the stall. And the picture agrees: measuring local sharpness in ten horizontal bands gives 19, 16, 16, 47, 124, 356, 425, 256, 168, 122. The sharpest band is 26 times sharper than the softest, and everything outside that one slice is visibly gone.

The hyperfocal distance is the other half of the story. Focused at infinity, the near limit is , so this lens would leave everything closer than about 750 m soft; focused at itself, the sharp zone would start at , 375 m. A 300 mm lens does not do “everything in focus”, and no aperture on this body changes that by much.
Where this breaks
Depth of field depends on the sensor as much as the lens. The same 93 mm at f/4 gives a five-centimetre band on this camera and a different one on any other, because changes. Switch the lab to the phone format at 0.005 mm and the band shrinks by a factor of five without touching a single optical parameter. Any depth-of-field number quoted without its sensor and its viewing assumptions is incomplete.
The threshold hides a choice nobody states. The 0.030 mm that full-frame tables use comes from assuming a print of a particular size viewed from a particular distance by an eye of particular acuity. Look at the same file at 100% on a monitor and the tolerance you have is closer to one photosite (5.5 µm on the camera that sampling the pixel grid measures), so the true band is narrower than the table says.
And one row of the source figure does not reconcile. The same DPDD caption gives a f/22 depth of field of 0.70–5.80 m, which the formula cannot produce from that figure’s own 93 mm at 1.52 m. Reproducing 0.70–5.80 m needs a 29.1 mm lens at 1.249 m. Whether that row describes a different scene, a range across the dataset, or an error is not something the figure settles, so this lesson reports both the prediction and the discrepancy rather than choosing.
The blur here is geometry only. Every formula above treats light as rays. Stop down far enough and diffraction takes over, spreading a point regardless of how well the cone converges, so past roughly f/16 on this sensor the extra depth comes with a softer image everywhere. Blur of either kind spreads an edge over more pixels, which is what what is an edge has to cope with when it looks for one.
Exercises
- The hyperfocal distance. Write
hyperfocal(f_mm, n, coc_mm), in metres. At 93 mm and f/4 it must give the worked example’s 87.42 m.
def hyperfocal(f_mm, n, coc_mm=0.02476):
return 0.0 # metres
print(hyperfocal(93, 4))- Predict, then run. How many times deeper than at f/4 is the band at f/8, and at f/11?
- Step back. Same lens at f/4, subject at 3 m instead of 1.52 m: how deep is the band?
What you should see
These come from the “Lesson 2” cells of the unit notebook, image_formation.ipynb, and are
the same on OpenCV 4.11 (this page) and 5.0.
- 87.42 m.
- 2.00 times at f/8 and 2.75 at f/11, close to the f-number ratios of 2 and 2.75.
- 2.903 to 3.103 m, 0.200 m deep: four times the 0.050 m at 1.52 m. Doubling the distance roughly quadruples the depth while the subject is far closer than the hyperfocal distance.
Check yourself
Four questions on this lesson. Pick an answer to see why it is right or wrong.
What does a lens buy over a pinhole, and what does it cost?
A lens gathers a whole cone of light from each point and brings it back to a point only at one distance.
What is the circle of confusion?
"In focus" has to mean blurred by less than we can see, and that threshold is the circle of confusion.
Going from f/4 to f/22 on the DPDD bench, how does the depth in focus change?
From 0.050 m to 0.277 m. Far from the hyperfocal distance, depth of field grows in proportion to the f-number.
A photographer stops down three stops, from f/4 to f/11. Roughly how much deeper is the band?
One stop multiplies N by √2, so three stops multiply it by 2^1.5 ≈ 2.8, and the band grows with N.
Next
The thin-lens model still assumes every ray bends by the right amount. Real glass does not oblige, and it misses by more the further from the axis a ray arrives, which is the residual lesson 1 measured and could not explain. Distortion, vignetting and aberration is where that goes.
Run it: every code block on this page has a cell in the unit’s notebook: open it in Colab.
References
[1] Forsyth, D. A., & Ponce, J. (2012). Computer Vision: A Modern Approach (2nd ed.), ch. 1 “Geometric Camera Models”, §1.1.3 “Cameras with Lenses” (p. 8). Pearson.
[2] Abuolaim, A., & Brown, M. S. (2020). Defocus Deblurring Using Dual-Pixel Data. European Conference on Computer Vision (ECCV) 2020. arXiv:2005.00305