MVisionPro Engineering Library · guide

Deciding whether depth of field covers every part position

In short

Set focus at the middle of the part positions. Pick the lowest f-number whose calculated depth of field covers them all, plus your reserve. A higher f-number means a smaller opening: more depth, but less light and a bigger diffraction spot. That f-number is only a candidate until the real decode or calibrated measurement passes at both extremes. If no f-number fits, lower the magnification: a wider field gains depth faster than closing the iris.

What the calculated number means

Depth of field is how far a part can move along the lens axis, around focus, and stay acceptable for your task. Depth of focus is a different thing, a tolerance at the sensor.

The calculator's yardstick is the circle of confusion: the largest blur spot on the sensor it still accepts. We set it at two pixels, 6.9 µm on the example camera's 3.45 µm pixels (calculated). That is our modelling choice, not a limit from a standard. The calculator reference shows the formula.

The result is one full interval, split evenly around focus by a thin-lens model. Its halves are not measured near and far limits. Sharpness also fades gradually: a part a millimetre outside is not lost, and one just inside is not guaranteed.

Choosing the f-number, and what it costs

The aperture is the lens opening, set by the iris. The f-number is the focal length divided by the entrance pupil diameter, the width of that opening seen from the front. A higher f-number means a smaller opening and more depth.

Light is the first cost: f/5.6 passes one quarter as much light as f/2.8 (Edmund Optics). You win it back with exposure, brighter lighting or more pulse energy. With continuous light, the motion-blur budget you calculated and tested caps the exposure. When a strobe gives nearly all the light, the pulse freezes motion and the camera exposure can run longer than that. The pulse must fit the blur budget and fall inside the window when all the rows you use are exposing. Ambient light must leave no trail. The exposure and strobe article has the details.

Diffraction is the second cost. Light spreads at the edge of the opening, so even an ideal lens images a point as a spot, the Airy disk. Its diameter is about 2.44 × wavelength × f-number, which at 520 nm gives 3.6, 7.1 and 14.0 µm at f/2.8, f/5.6 and f/11 (Edmund Optics). On the example camera those spots span about 1, 2 and 4 pixels (calculated).

Yet the image may improve before diffraction takes over, because closing the iris also reduces aberrations, the blur built into the lens design. So choose the aperture on a target of your own.

What "sharp enough" means

For code reading, the decoder must reach your required read result on representative codes, under real light, across the depth range. The two-pixel circle is not a code grade: 2D codes are graded under ISO/IEC 15415:2024. Reader makers set image requirements per product, not one depth limit. So count reads and no-reads at each depth position.

For measurement, calibrated error and repeatability must stay within vision's share of the tolerance at every part position. Calibration accuracy depends on edge quality, the calibration target, the lens, mounting, image quality and the vision tool, so test the complete system. Plot calibrated error and repeatability against depth. A part nearer the lens also looks larger in the image. For the pixels a feature needs, see sampling versus accuracy.

Testing the extremes, and what to change

Focus at the reference plane, the middle of the part positions. Run the real decode or calibrated measurement on one representative target at the nearest and farthest positions. Record aperture, lighting and exposure with each result, since you will adjust them together. If an extreme fails, try three levers.

Worked example: a 20 mm spread at a fixed 500 mm

The camera is the MV-CA050-12UM: 2448 × 2048 pixels at 3.45 µm (datasheet), so the active area is 8.45 × 7.07 mm (calculated).

This example assumes a 25 mm thin lens focused on a reference plane 500 mm from its principal plane, parts within ±10 mm of that plane, and 2 mm of reserve on each side. So the interval must reach ±12 mm. The calculated field is 160.5 × 134.2 mm, a magnification of 1:19.

f-numberDepth of field, calculatedEach sideCovers ±10 mm?Covers ±12 mm?
f/2.814.7 mm±7.3 mmNoNo
f/421.0 mm±10.5 mmYesNo, 1.5 mm short
f/5.629.4 mm±14.7 mmYesYes, 2.7 mm to spare
f/1157.7 mm±28.8 mmYesYes

f/5.6 is the first that covers both. It is a candidate, not a proved minimum: not every f-number between and beyond these four was calculated. Lighting, exposure, the task result and the lens's modulation transfer function (MTF), the contrast a lens passes at each detail size, also sit outside this arithmetic.

The reference plane at 500 mm, the part positions within ±10 mm, the ±12 mm requirement with reserve, and the calculated f/4 and f/5.6 intervals — schematic diagram, not a test image; the two-pixel circle of confusion is an assumption of the model.
The reference plane at 500 mm, the part positions within ±10 mm, the ±12 mm requirement with reserve, and the calculated f/4 and f/5.6 intervals — schematic diagram, not a test image; the two-pixel circle of confusion is an assumption of the model.

Calculate for your case

The prepared link opens the calculator with this example's camera, field size and working distance, ready for your own values. The link also carries a 0.1 mm feature, a five-pixel target and a speed of 0 mm/s, which answer other questions. The page has no aperture field, so it cannot show the intervals above.

To compare apertures, use our tools API (application programming interface), whose optics route accepts fNumber. The same geometry at f/4 and at f/5.6 returns values.depthOfFieldMm of about 21.0 and 29.4 mm (calculated). Swap in your own five values and note the f-number with each result.

Lens candidates

Four 25 mm C-mount lenses have marked aperture ranges that include every f-number in the table (datasheet).

LensMarked rangeImage circleCovers the 11.01 mm sensor diagonal (calculated)?
MVL-HF2528M-6MPEF2.8–F16Ø9 mmNo
MVL-MF2528M-10MPEF2.8–F16Φ11.2 mmYes, by 0.19 mm
MVL-KF2528M-12MPF2.8–F16Ø17.6 mmYes, with margin
SA2520M-10MPF2–F22Ø23 mmYes, with margin

A marking only proves that the iris can be set there. Send us a lens part number, and we will check the focusing range, the mount and the rest of that datasheet.

Common mistakes

When this rule breaks

The thin-lens model knows nothing about the lens you mount: every 25 mm lens gets the same number. It also refuses a field over 1000 times the sensor width rather than return an endless interval.

A smaller accepted blur circle narrows the calculated interval, and a larger one widens it. That alone does not set the range a decoder or gauge can use. The range a decoder or gauge really holds depends on contrast, lighting, code quality, aberrations, motion and calibration. Measure it. Geometric focus is not contrast either: a lens the model calls sharp can still have too low an MTF for your feature. Light level, pulse energy, exposure, gain and lens transmission are outside the calculation, so a marked aperture may still leave the image too dark at the exposure your line allows.

Next step

Send us the camera or its active sensor size, the field, the working distance, the spread of part positions, your reserve and your acceptance criterion. We will calculate the interval across apertures, name lens candidates with those markings, and say what to capture at the extremes.

Sources

Related

How this material was prepared

Prepared by MVisionPro from the stated sources and the MVisionPro calculation engine. A physical test is claimed only when the material says so explicitly. Read the editorial method.

Editorial status: verified. Content updated 2026-09-23.