Depth of Field in Machine Vision: Aperture Trade-Offs
Balance focus range, light, aberrations, diffraction, and motion limits instead of treating the iris as a depth-of-field knob.
The top of a component is sharp and its lower shoulder is blurred. The first reaction is to close the iris. Depth of field improves, but exposure becomes longer, motion blur appears, gain rises, and fine edges soften again at the smallest aperture.
Depth of field is a system trade-off. Aperture, magnification, wavelength, pixel pitch, lens quality, lighting, object height, and the algorithm’s acceptable blur all contribute.
What you will learn
Distinguish depth of field from depth of focus.
Understand how f-number changes light, aberrations, and diffraction.
Estimate diffraction scale at the sensor.
Design a focus sweep around the real part-height range.
Decide when optics, mechanics, or multiple images should replace a smaller aperture.
Technical foundation
Depth of field and depth of focus
Depth of field (DoF) is the range of object positions that appear acceptably sharp. Depth of focus refers to tolerance near the sensor/image plane. Machine-vision specifications normally care about object-space DoF.
“Acceptably sharp” is task-dependent. A blurred edge may still support presence detection but fail a tight measurement or small-scratch inspection. DoF therefore needs an application-specific criterion.
F-number
For a lens focused near infinity:
f-number N = focal length / entrance-pupil diameter
A larger f-number means a smaller aperture. Each full stop reduces the light by approximately a factor of two. Moving from f/4 to f/8 is two full stops, so only about one quarter as much light reaches the sensor for the same scene.
At close focus, effective or working f-number is higher than the marked value. This matters in macro and telecentric imaging.
Aperture trade-offs
Opening the aperture increases light and reduces diffraction but usually decreases DoF and can expose aberrations.
Closing the aperture increases geometric DoF and may reduce aberrations, but it requires more light and eventually increases diffraction blur.
There is usually a middle operating region rather than one universally best f-number.
Diffraction scale
For a circular aperture, the approximate Airy-disk diameter to the first dark ring at the sensor is:
d ≈ 2.44 × wavelength × f-number
This is a physical reference, not a complete lens-resolution model. At a 0.55 µm wavelength:
At f/4: d ≈ 2.44 × 0.55 × 4 = 5.4 µm
At f/8: d ≈ 10.7 µm
At f/16: d ≈ 21.5 µm
With 3.45 µm sensor pixels, these diameters span roughly 1.6, 3.1, and 6.2 pixels respectively. Actual image contrast depends on the complete optical transfer function, sampling, aberrations, defocus, and processing, but the trend explains why the smallest iris is not automatically the sharpest setting.
[Suggested visual: aperture trade-off triangle]
Purpose: Show the competing effects of DoF, light, and diffraction/aberrations.
Required elements: f/2.8, f/8, and f/16 examples; light throughput arrows; shallow-to-deep DoF; aberration and diffraction labels.
Suggested caption: “Aperture trades focus range against photon budget and optical blur.”
Accessible alt text: “Three aperture settings compare depth of field, amount of light, aberrations, and diffraction.”
Engineering workflow
1. Define the required object-space range
Measure the actual height and position variation of the inspected surfaces, including part tolerance, fixture variation, conveyor lift, robot presentation, and thermal movement.
Why it matters: nominal CAD height is not the same as the production focus range.
2. Define an image-quality criterion
Choose a metric connected to the task: edge gradient, line-pair contrast, smallest-defect detection, measurement repeatability, OCR confidence, or barcode module contrast.
Common failure: deciding focus by how the full image looks on a monitor.
3. Establish the optical geometry
Record FOV, sensor, pixel pitch, lens, magnification, WD, wavelength, and object plane. DoF changes strongly with magnification; a setup that is forgiving at 0.03× can become sensitive at 0.3×.
4. Test a practical aperture range
Start near the lens’s stronger operating region rather than at either mechanical limit. For each aperture, restore brightness with light intensity or strobe energy before increasing exposure beyond the motion limit.
Trade-off: closing from f/4 to f/8 needs about four times the light for the same exposure and sensor response.
5. Run a calibrated focus sweep
Move a target or representative part through the required z-range. Capture repeated images at each position. Plot the chosen sharpness or inspection metric against height for every candidate aperture.
6. Check the entire FOV
Field curvature and alignment can make the centre and corners focus at different object positions. Repeat the analysis in relevant regions.
7. Choose a system-level correction if aperture is insufficient
Options include reducing part-height variation, changing camera angle, increasing WD, reducing magnification with a higher-resolution sensor, using suitable telecentric or focus-tunable optics, acquiring multiple focus planes, or using separate cameras for different surfaces.
Worked example: f/4 versus f/8 on a moving part
Hypothetical application: a feature can appear over an 8 mm height range. At f/4, a focus sweep shows the edge-gradient requirement is met over only 5 mm. At f/8 it is met over 9 mm, so f/8 covers the geometric range.
The current exposure at f/4 is 80 µs. Closing to f/8 loses two stops, requiring approximately four times the light for the same exposure:
Required exposure without more light ≈ 80 µs × 4 = 320 µs
If object speed is 600 mm/s and image scale is 0.05 mm/px:
Smear at 80 µs = 600 × 0.000080 / 0.05 = 0.96 px
Smear at 320 µs = 600 × 0.000320 / 0.05 = 3.84 px
The f/8 setting solves focus but creates unacceptable motion blur unless the lighting provides roughly four times the useful exposure energy, the speed is reduced, or a shorter strobe freezes motion.
The diffraction reference at 0.55 µm also grows from about 5.4 µm at f/4 to 10.7 µm at f/8. The actual lens and edge test determine whether that loss of high-frequency contrast is acceptable.
[Suggested visual: measured focus curves at f/4, f/8, and f/16]
Purpose: Replace vague DoF judgement with an application-specific acceptance plot.
Required elements: Object height on x-axis, edge contrast on y-axis, acceptance threshold, and curves showing shallow, adequate, and diffraction-limited cases.
Suggested caption: “Define usable depth of field by the inspection metric, not by a generic circle of confusion.”
Accessible alt text: “Three focus curves show edge contrast across object height, with f/8 staying above the acceptance line over the required range.”
Aperture decision table
| Observation | Likely interpretation | Next action |
|---|---|---|
| Centre sharp, corners soft at same height | Field curvature or tilt | Check alignment and field focus |
| DoF improves but edges remain soft | Diffraction or lens limit | Compare wider aperture and better geometry |
| Closing iris causes line-speed failure | Photon budget forced longer exposure | Increase/strobe light or change optics |
| One surface never shares focus | Height range exceeds useful DoF | Reduce variation or use multiple optical planes |
| Focus changes after maintenance | Unlocked focus or mount movement | Add locks, datum, and check standard |
| DoF differs by colour channel | Chromatic focus shift | Control wavelength or use suitable optics |
Common mistakes
Closing the iris to its minimum. Diffraction and light loss can outweigh the geometric DoF gain.
Compensating with longer exposure on moving parts. Focus improves while motion blur destroys detail.
Using a visual focus judgement. Tie DoF to a measured inspection metric.
Testing only the image centre. Field curvature and camera tilt affect corners.
Ignoring working f-number at close focus. The effective aperture differs from the marked value.
Using nominal part height. Fixture, conveyor, robot, and thermal variation add to the range.
Moving focus after calibration. Measurement geometry and distortion may change.
Assuming software sharpening recovers lost detail. It can amplify edges and noise but cannot restore information that was never transferred.
Validate under production conditions
Capture repeated images at the full height range, FOV positions, temperatures, line speeds, and representative surface conditions. Use the final enclosure window, lighting, exposure, and gain.
For measurement, report bias and repeatability versus height. For defect inspection, repeat the smallest rejectable features at every z-position. For OCR or codes, trend exact-read rate and confidence, not only visual sharpness.
Lock the iris and focus after approval. Create a check-standard procedure that detects focus drift and define recalibration or service triggers.
Key takeaways
Depth of field is defined by the inspection’s acceptable blur, not a universal number.
Closing the aperture increases geometric DoF but reduces light and increases diffraction.
Motion limits turn aperture selection into a lighting problem.
A calibrated focus sweep is more useful than a generic DoF estimate.
When the height range is too large, change the system architecture instead of forcing the iris.
Follow this Hashnode blog for more practical optics guidance, and connect with Kivanc Ekici on LinkedIn. For related engineering information, visit the ITAGE Türkiye website.
Frequently asked questions
Does a higher f-number always increase useful depth of field?
Geometric DoF generally increases, but diffraction and loss of light can reduce usable detail. The inspection metric must decide.
Why did closing the aperture make my image worse?
The system may have entered a diffraction-limited region, required excessive gain, or lengthened exposure enough to add motion blur.
What is the best f-number for machine vision?
There is no universal value. Many lenses perform well in a middle range, but magnification, wavelength, pixel pitch, DoF, and motion requirements govern the choice.
Can a telecentric lens solve every depth-of-field problem?
No. It can stabilize magnification with object-height changes, but the image still becomes defocused outside its usable range.
How should depth of field be measured?
Move a calibrated target or part through the required object-space range and plot a task-relevant sharpness or inspection metric at several FOV positions.

