Depth of Field in Machine Vision: Aperture, Working Distance, and the Circle of Confusion
How aperture, focal length, working distance, and circle of confusion set the sharp zone, when stopping down stops helping, and how depth of focus differs from depth of field.
Depth of field (DOF) in machine vision is the range of object distances that produce acceptably sharp images on the sensor. Four variables control it: f-number, focal length, working distance, and the permissible circle of confusion, which machine vision sets from pixel pitch rather than photographic convention. Shorter focal lengths and longer working distances extend DOF quadratically; stopping down helps linearly until diffraction cancels the gain. Run your own numbers in the camera depth of field calculator.
What is depth of field in machine vision?
Depth of field is the range of object distances, measured in object space, over which a lens holds blur below the permissible circle of confusion on the sensor. In machine vision the blur limit comes from pixel pitch rather than print sharpness, so practical DOF is far shallower than photography rules of thumb suggest.
The sharpness limit is the circle of confusion (CoC): the largest blur-spot diameter on the sensor still counted as in focus. Photography sets CoC from human perception of prints, typically 0.02-0.03mm on a full-frame camera. Machine vision sensors commonly carry pixel pitches of 1.5-3.5µm, and the detector is an algorithm, not an eye. A preview image that looks well focused to a person can still carry blur that degrades edge localization on the actual sensor.
A plain-language version: the lens renders nominally one plane at peak sharpness (in a real lens, a slightly curved surface of best focus), and everything nearer or farther with steadily growing blur. DOF is the slab of space where that blur stays under the limit you chose. Nothing physical happens at the DOF boundaries; the blur simply crosses your threshold there. That is why two teams with the same lens and sensor can report different DOF numbers: they chose different thresholds.
DOF is a range, not a single number. It runs from a near limit to a far limit on either side of the focus distance, with peak sharpness at the focus plane itself. The far side is typically longer than the near side, and at long working distances the far limit extends to infinity, which is the hyperfocal condition covered below. For close-up inspection work, the near and far limits are roughly symmetric. The asymmetry has a fixture-design consequence: centering the expected part-height stack on the focus distance leaves some far-side range unused, so mid-range setups often benefit from biasing focus slightly toward the near side of the stack.
Lens datasheets rarely publish DOF numbers, and when they do, the assumed CoC is often photographic. DOF is a system property, not a lens property: the same lens paired with a 2.8µm-pixel sensor and a 1.85µm-pixel sensor has two different usable depth ranges. Treat any published DOF figure as unusable until the CoC behind it is known.
The formula shows the leverage directly: f-number and CoC act linearly, while the working-distance-to-focal-length ratio acts quadratically. It also shows why upgrading to a higher-resolution sensor, which tightens c, shrinks the working DOF even though nothing about the lens changed. The depth of field calculator computes near limit, far limit, and hyperfocal distance from these inputs, and the working distance guide covers how WD interacts with the rest of the optical stack.
What determines depth of field in a machine vision system?
Four variables set depth of field: f-number, focal length, working distance, and the permissible circle of confusion. DOF grows linearly with f-number and CoC, and with the square of the working-distance-to-focal-length ratio. Focal length and working distance are the strongest levers because they act quadratically.
Aperture (f-number)
Closing the iris shrinks the light cone entering the lens, which shrinks the blur circles from out-of-focus points. Doubling the f-number roughly doubles DOF, all else equal. The cost is light: each full stop halves the exposure on the sensor, so two stops, for example F/2.8 to F/5.6, cost a factor of 4. Machine vision illumination is usually programmable, with LED rings, backlights, and strobes, so the light penalty can often be paid, but diffraction sets a hard ceiling covered in the next section. The f-number guide works through the full aperture tradeoff.
Many M12 lenses operate at a single fixed f-number, so the aperture decision is made at lens selection. Adjustable-iris C-mount lenses, such as the CIL561 with an F/2.4-F/16 range, let engineers tune aperture at the bench against both DOF and illumination budget.
Focal length
DOF scales with the inverse square of focal length. A 6mm lens at 500mm working distance holds roughly 7 times more DOF than a 16mm lens at the same distance and aperture, because (16/6)² ≈ 7.1. This is the strongest single lever available during lens selection. The tradeoff is pixel density on the target: shorter focal length spreads the pixels over a wider field of view. The focal length selection guide covers that side of the tradeoff.
The numbers make the tension concrete. At 300mm working distance on a 1/1.7" sensor (7.6mm active width), a 6mm lens covers roughly 380mm of scene width and a 16mm lens roughly 143mm, from FOV = WD × sensor width / EFL, which is exact for rectilinear projection. If the feature size demands the 16mm lens's pixel density, the extra DOF has to come from aperture or working distance instead.
Working distance
DOF scales with the square of working distance. Moving the camera from 300mm to 600mm while keeping focal length and aperture constant roughly quadruples DOF. Restoring the original field of view requires a longer focal length, which gives some of the gain back, so the two changes must be modeled together in the depth of field calculator rather than estimated separately.
Working distance is a design consideration rather than a firm constraint. Early in a project, brackets and gantries can move, and a DOF problem is cheap to fix by relocating the camera. Once the mechanical design is committed, WD is effectively fixed and the remaining levers are optical.
Permissible blur (circle of confusion)
Relaxing the CoC directly increases calculated DOF, but the physical blur in the near and far zones does not change; only the label of acceptable moves. The right CoC is the largest blur the detection algorithm still tolerates at full reliability, which is application specific. The circle of confusion section below gives per-task starting values.
| Change | Effect on DOF | Side effect | Compensatable? |
|---|---|---|---|
| Increase f-number (stop down) | Increases linearly | Less light; diffraction at high f-numbers | Light: yes, more illumination. Diffraction: no. |
| Decrease focal length | Increases (inverse square) | Wider FOV, lower pixel density on target | FOV: adjust working distance. Pixel density: higher-resolution sensor. |
| Increase working distance | Increases (square) | Wider FOV at same focal length | Longer focal length restores FOV but offsets part of the gain. |
| Relax CoC | Increases linearly | More blur admitted in near/far zones | Only if the algorithm verifiably tolerates it. |
Working distance limits are not published on every lens datasheet, and published DOF figures rarely state their CoC assumption. When comparing candidate lenses, request the assumed CoC or recompute DOF from f-number, focal length, and your own pixel-pitch CoC so the comparison is like for like.
Does stopping down the aperture increase depth of field?
Stopping down increases depth of field roughly linearly with f-number, but it costs light and eventually adds diffraction blur that outweighs the gain. For sensors with 1.5-2µm pixels, diffraction typically becomes visible around F/2.8-F/4 and dominates by F/5.6-F/8. It also does not remove field curvature; off-axis aberrations persist at every aperture.
Light loss
Each full stop halves the light through the lens. Going from F/2.8 to F/11 is four stops, so the sensor receives 16 times less light at the same exposure time. Strobe power must rise proportionally or the exposure must lengthen, which risks motion blur on moving targets. At some point the illumination system hits its power limit, and further stopping down forces exposure times incompatible with line speed. In machine vision this cost is often payable because illumination is controlled programmatically, but it must be budgeted, not assumed.
Diffraction
Light passing a small aperture diffracts. The point image on the sensor becomes an Airy disk whose diameter grows with f-number:
On a sensor with 1.85µm pixels, an F/8 Airy disk spans nearly 6 pixels. That blur floor sits under the entire image, so closing the iris past this point erases the resolution the extra DOF was supposed to protect. The limit is sensor dependent: a 3.45µm-pixel sensor tolerates roughly F/5.6-F/8, while a 1.5µm-pixel sensor loses pixel-scale contrast entirely near F/5.6. The diffraction limit guide covers the resolution side in detail.
Stopping down increases depth of field and reduces visible blur from residual focus mismatch. It does not remove field curvature or astigmatism. If corners are soft because of off-axis aberrations, a smaller aperture masks the symptom without correcting the underlying focal surface; see the field curvature guide.
Where this leaves the aperture decision
Set exposure and aperture together. On a moving line, exposure time is capped by motion blur: a conveyor at 0.5m/s with a 100µs exposure moves the part 50µm during capture, already several pixels of smear at high magnification. That cap fixes how much light the aperture must pass, which in turn caps the usable f-number for a given strobe. If the required DOF does not close inside that window, change the geometry rather than fighting the illumination budget.
The practical operating band for typical machine vision sensors is F/2.8-F/8. Before going past F/8, compute the Airy disk against your pixel pitch. If diffraction already dominates, the remaining DOF levers are focal length, working distance, and the CoC requirement.
What circle of confusion should I use in machine vision?
Use a circle of confusion derived from pixel pitch, typically 1-2 pixel pitches depending on the task. The photographic convention, CoC = sensor diagonal / 1500, is calibrated to human print viewing and is usually several times too large for machine vision sensors. The pixel-pitch criterion is the one that applies.
The d/1500 convention gives about 0.029mm on a full-frame camera and scales to roughly 0.005mm on a 1/2.3" sensor. Both numbers describe what a human eye resolves in a print at 250-300mm viewing distance. Machine vision algorithms detect blur well below that threshold: edge localization, gradient matching, and barcode decoding degrade at levels a monitor image hides. The format-based scaling also ignores pixel pitch entirely. A 1/1.7" sensor at 8MP has roughly 2.3µm pixels; the same format at 12MP has 1.85µm pixels. The photographic formula assigns both the same CoC, while the 12MP system genuinely needs a tighter one. Pixel pitch comes from the sensor datasheet, not the format name; see the sensor size guide.
The machine vision criterion is CoC = k × pixel pitch, where k is the number of pixels of blur the task tolerates:
| Task | Typical CoC (pixels) | Rationale |
|---|---|---|
| Metrology, dimensional measurement | 1 | Blur past 1 pixel shifts edge locations at the measurement threshold |
| Fine surface inspection | 1 | Defects may span only 1-2 pixels; blur masks them |
| Barcode, 2D code, OCR | 1-2 | Narrowest bar, cell edge, or stroke must stay resolved |
| Pick-and-place localization | 1-3 | Placement accuracy sets the tolerance |
| Presence detection, robot navigation | 2-4 | Features are large relative to pixel scale |
A generous CoC inflates the calculated DOF without changing the optics. The blur at the zone edges is identical; only the label of acceptable has moved. If that blur exceeds what the algorithm tolerates, the system fails in production regardless of what the calculation promised.
The definitive test is empirical: expose the real algorithm to controlled defocus at the working aperture and find the blur level where output error crosses the acceptance threshold. Enter that value, not a photography default, into the depth of field calculator.
What is hyperfocal distance in machine vision?
Hyperfocal distance is the closest focus distance at which the far depth-of-field limit reaches infinity: H = f² / (N × c). Focused at H, everything from H/2 to infinity stays within the circle-of-confusion budget. It suits navigation and monitoring cameras with variable object distances, not fixed-distance inspection.
Two worked examples with c = 6µm, which is 2 pixel pitches on a 3µm sensor. The CIL036 3.3mm M12 lens at F/2.2 gives H = 3.3² / (2.2 × 0.006) ≈ 825mm, so everything from about 412mm to infinity holds within budget. That is a workable fixed-focus setup for a robot navigation camera. The CIL160 16mm M12 lens at F/1.9 gives H ≈ 22.5m, with a near limit around 11m; even its F/5.6 fixed-aperture variant still puts H at about 7.6m. Hyperfocal focus is not viable for the 16mm lens at close range, and it should be focused at the working plane instead.
Hyperfocal focus fits AMR and drone navigation, wide-area monitoring, and factory-set fixed-focus embedded modules, where object distances vary continuously and no plane deserves peak sharpness. It is the wrong strategy for inspection, metrology, and barcode reading: at the near limit H/2, blur equals the full CoC, and that sharpness loss is a pure liability when the target sits at one controlled distance. If your system needs both range coverage and peak sharpness at a plane, a fixed-focus compromise cannot deliver both; see the focusing guide for setting focus at either target, and verify the numbers in the depth of field calculator.
The calculation is only as good as its CoC. Tightening c from 6µm to 3µm doubles H, which can silently push the near limit beyond the closest object the system must see. Before committing a factory focus setting on an embedded module, verify the algorithm's detection rate on test images captured at H/2, where blur sits at the full CoC limit; visual impression is not sufficient evidence.
What is the difference between depth of focus and depth of field?
Depth of field is the object-side tolerance: how far the scene can move while lens and sensor stay fixed. Depth of focus is the image-side tolerance: how far the sensor can shift along the optical axis, with lens and object fixed, before blur exceeds the permissible circle of confusion. They are conjugates, not synonyms.
| Parameter | Depth of field | Depth of focus |
|---|---|---|
| Side of the system | Object side | Image side (sensor plane) |
| What moves | Object distance | Sensor position |
| Typical range | Millimeters to meters | Tens of micrometers |
| Failure signature | Parts at the wrong distance are blurry, others sharp | Entire image uniformly soft after assembly |
Because depth of focus scales with M², low-magnification systems with comfortable depth of field carry the tightest image-plane budgets. That 40µm window at F/4 must absorb every sensor-position error in the build: PCB thickness variation, sensor package height, flange tolerance, shims, and thermal drift. Combined sensor-position stack-up can reach tens of micrometers in compact camera assemblies, so a lens that passes bench testing can still produce soft images after integration. Thermal drift adds to the stack: a 20°C swing across a 10ppm/°C CTE mismatch over a 20mm optical path shifts the image plane by roughly 4µm.
Sensor tilt consumes the budget fastest at the field edges. The axial error across the sensor is approximately (sensor diagonal / 2) × sin(θ); a 0.1° tilt on a 17.6mm image circle produces about 15µm of corner-to-center error, a large fraction of a tight window. The sensor alignment guide covers measurement and correction.
The correction paths differ by mount. A C-mount lens with a lockable focus ring compensates for modest sensor-plane offsets through its cam, which moves groups relative to each other and rebalances aberrations as it refocuses. An M12 lens is a rigid assembly: compensation means threading the whole lens in or out of its holder before the set screw is locked, with no internal rebalancing. Neither adjustment corrects tilt. Validate focus in the assembled camera at the working aperture, not on a bench at nominal flange distance.
How do you increase depth of field without degrading the image?
Change the geometry first. A shorter focal length or a longer working distance extends depth of field quadratically without cutting light. Then stop down only as far as the diffraction limit for your pixel pitch. An adjustable-iris C-mount lens lets you tune that balance at the bench.
1. Use a shorter focal length
Switching from 16mm to 6mm at the same working distance increases DOF by roughly (16/6)² ≈ 7 times. The cost is a wider field of view and lower pixel density on the target, which a higher-resolution sensor can recover if the budget allows. When resolution headroom exists, this is usually the cleanest DOF improvement available.
2. Increase working distance and adjust focal length
Moving the camera back and lengthening the focal length to restore the field of view often nets a DOF gain, but the two changes partially cancel in the formula, so the outcome depends on the exact numbers. Model both simultaneously in the depth of field calculator and confirm scene coverage in the field of view calculator before changing hardware.
3. Stop down to the diffraction limit, not past it
The strictest criterion sets the f-number where the Airy disk radius equals one pixel: N ≈ pixel pitch / (1.22 × λ), which gives about F/3.0 for a 2µm pixel at 550nm. The hard ceiling is the Nyquist cutoff, N ≈ 2 × pixel pitch / λ, about F/7 for 2µm pixels at 550nm, where diffraction erases contrast at pixel-scale detail entirely. Between those two f-numbers sharpness degrades progressively; take the DOF gain only as far as the algorithm verifiably tolerates, then stop.
4. Use an adjustable-iris C-mount lens
A fixed-aperture M12 lens locks the aperture decision at selection time, which keeps the system small, light, and mechanically simple. When production conditions vary between runs, an adjustable iris such as the CIL561's F/2.4-F/16 range lets the installer set aperture against the actual illumination, part-height variation, and line speed. Browse C-mount lenses for adjustable-iris options.
5. Validate on the real system
Calculated DOF is a geometric estimate. Real lenses carry residual aberrations that shift the usable focus range at each aperture, sometimes better than the formula predicts, sometimes worse. Focus at the working distance, image a tilted flat target or depth standard, and measure where your algorithm's output crosses its acceptance threshold. The calculator provides the starting point; the bench test provides the number you ship with.
How do you select a lens when depth of field is the constraint?
Define the required DOF from part-height variation, set the CoC from pixel pitch, then iterate focal length and aperture in the calculator until the DOF closes at an f-number inside the diffraction and illumination budgets. The eight steps below cover the full decision in order.
- Define the required DOF. Measure the height variation of parts at the working plane and add 20-30% margin for camera-mounting tolerance.
- Set the CoC from pixel pitch. Confirm the pitch from the sensor datasheet, then apply the per-task multiplier from the circle of confusion section.
- Calculate DOF for candidate focal lengths. Run two or three candidates through the depth of field calculator at your working distance and CoC.
- Check the aperture against diffraction. Compute the Airy disk (2.44 × 550nm × f-number). If it exceeds 1-2 pixel pitches, reduce the f-number and revisit step 3 with a shorter focal length.
- Verify the illumination budget. Confirm the required strobe power or continuous light level at the chosen aperture and exposure time. If it does not close, open the aperture or increase working distance.
- Select the lens. Pick the nearest available focal length that meets the DOF at an aperture inside both budgets. Fixed-aperture M12: order to the f-number. Adjustable-iris C-mount: set aperture at the bench.
- Validate on hardware. Image a depth target at the working distance and find where the algorithm fails on the near and far sides. Compare against step 1.
- Document the setup. Record f-number, focus distance, and illumination in the build record, and confirm the M12 set screw or C-mount lock ring is tightened after validation.
Related tools and guides
- Depth of field calculator Near limit, far limit, hyperfocal distance, and depth of focus from your lens, sensor, and CoC
- Field of view calculator Scene coverage when working distance or focal length changes
- EFL calculator Required focal length from working distance, sensor, and scene width
- Angle of view calculator Conversion between angular and linear FOV
- Image sensor reference Active area and pixel pitch for common formats
- F-number in machine vision Aperture, light throughput, and the stopping-down tradeoff
- Spatial resolution guide Diffraction limits, Airy disk, and megapixel lens ratings
- How to focus a camera Setting and locking focus on M12 and C-mount lenses
Which lenses fit depth-of-field-critical applications?
Short focal lengths give forgiving DOF at fixed apertures, long focal lengths trade DOF for pixel density, and adjustable-iris C-mount lenses let the aperture be tuned on site. The three Commonlands lenses below cover those cases; in-stock lenses ship same day on orders placed before 12 PM PST.
We ranked these by how much control each gives over the depth-of-field budget, not by resolution alone. The adjustable-iris CIL544 leads because you can trade DOF against diffraction at the bench, while the two fixed-aperture M12 lenses lock that decision at selection time; confirm the numbers for your sensor in the depth of field calculator. The aperture and EFL figures in the table come from each lens datasheet.
| Rank | Lens | Mount | EFL | Aperture | When to choose it | Product |
|---|---|---|---|---|---|---|
| 1 | CIL544 | C-mount | 25mm | F/1.8 adjustable iris | When you need to sweep the aperture at the bench to find the DOF and diffraction optimum on a 1.1" 20MP sensor. | 25mm C-mount lens |
| 2 | CIL160 | M12 | 16mm | F/1.9 to F/5.6 variants | Locked-aperture production builds that want high pixel density and hold parts at a fixtured working distance. | 16mm M12 lens |
| 3 | CIL062 | M12 | 6.2mm | F/2.8 fixed | Short-EFL layouts that need forgiving DOF at a fixed aperture where a 60° field of view is acceptable. | 6mm M12 lens |
CIL062: 6.2mm M12, fixed F/2.8
The starting point for most M12 DOF discussions. The short focal length gives naturally forgiving DOF, and the fixed aperture keeps behavior predictable: size the illumination to F/2.8 once and it does not drift. Choose it when:
- The scene is large relative to feature size and a 60° field of view is acceptable.
- Part-height variation is moderate, roughly 10-30mm at 300-500mm working distance.
- A $19 fixed-aperture lens meets the budget and the system must stay small and light.
CIL160: 16mm M12, F/1.9-F/5.6 fixed-aperture variants
Roughly 7 times less DOF than the CIL062 at the same working distance. At F/1.9 the sharp zone is thin enough to demand tight mechanical control of part position, and at F/2.8, where its published rating is 12MP at 1.55µm pixels, its depth-of-focus window is on the order of ±9µm, so sensor placement matters as much as scene focus. Choose it when:
- High pixel density on the target matters more than scene width.
- Parts arrive at a consistent, fixtured working distance.
- The f-number variant is selected to match the illumination budget, not to rescue DOF.
CIL544: 25mm C-mount, F/1.8 adjustable iris, 20MP
Chosen for resolving power, not DOF. Wide open at F/1.8 with a 5.5µm CoC (2 pixel pitches at 2.74µm), both the object-side DOF and the roughly ±10µm image-side depth-of-focus window are narrow, so the build must fixture the part and manage sensor position and tilt deliberately. Choose it when:
- The task is high-resolution measurement or fine inspection on a 1.1" sensor.
- The working distance is controlled and repeatable.
- Sensor mounting is validated for tilt and axial position at assembly.
Frequently asked questions
What is the circle of confusion in machine vision?
The circle of confusion is the maximum blur-spot diameter on the sensor that an application still treats as in focus. In machine vision it is an engineering tolerance set from pixel pitch and algorithm tolerance, typically 1-2 pixel pitches, not the photographic diagonal/1500 convention, which is calibrated to human print viewing.
What is hyperfocal distance in machine vision?
Hyperfocal distance is the closest focus distance at which the far depth-of-field limit extends to infinity for a given lens, aperture, and circle of confusion. Focused at the hyperfocal distance H = f² / (N × c), everything from H/2 to infinity stays within the blur budget. It suits navigation and monitoring cameras, not fixed-distance inspection.
What is depth of focus in machine vision?
Depth of focus is the allowed displacement of the image sensor along the optical axis before blur exceeds the permissible circle of confusion. It is an image-side tolerance, approximately 2 × f-number × CoC in total, typically tens of micrometers. Depth of field is the corresponding object-side tolerance; the two are not interchangeable.
How do I increase depth of field in machine vision?
Use a shorter focal length, increase the working distance, or stop down the aperture, in that order. The first two extend DOF quadratically without cutting light. Stopping down works linearly but costs illumination and eventually adds diffraction blur. Model the options with the Commonlands depth of field calculator before changing hardware.
Does stopping down always improve depth of field?
No. Geometric DOF grows with f-number, but diffraction blur grows too. Net sharpness peaks at some optimal aperture and then declines. For sensors with 1.5-2µm pixels, diffraction typically becomes visible around F/2.8-F/4 and dominates by F/5.6-F/8, where the added blur cancels the DOF benefit.
When does diffraction cancel the benefit of a smaller aperture?
When the Airy disk approaches the sensor pixel pitch. The Airy disk diameter is approximately 2.44 × wavelength × f-number: about 10.7µm at F/8 in 550nm light, which spans nearly 6 pixels on a 1.85µm sensor. Larger pixels, such as 3.45µm, tolerate higher f-numbers before diffraction dominates.
Should I focus at the working plane or hyperfocal distance?
Focus at the working plane when the target sits at a defined, repeatable distance, which covers most inspection systems. Focus at the hyperfocal distance when object distances vary continuously and no single plane dominates, as in robot navigation, wide-area monitoring, and fixed-focus embedded cameras.
How do focal length and working distance affect depth of field?
Depth of field scales approximately with the square of working distance divided by focal length. Doubling working distance roughly quadruples DOF; doubling focal length at the same distance cuts it by roughly four. A 6mm lens therefore holds about 7 times more DOF than a 16mm lens at equal distance and aperture.
Is shallow depth of field always bad in machine vision?
Not always. Shallow DOF can isolate the target plane from background clutter and supports focus-based 3D techniques. In flat-target inspection of PCBs, labels, and wafers it is usually a liability, because part-height variation or mounting tolerance can push regions of the target outside the sharp zone.
Need a DOF budget reviewed?
Commonlands manufactures M12 and C-mount lenses for machine vision, with MTF testing as part of production quality control. Send the San Diego engineering team your working distance, part-height variation, and sensor, and we will recommend a lens and operating aperture. In-stock samples ship same day on orders placed before 12 PM PST.