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.
- Check where focus really sits: step the target through the positions and find where the task works best. An interval centred on the part's near face wastes half its depth in front of it.
- Lower the magnification, the sensor size divided by the field size. A wider field buys depth faster than the aperture does, but puts fewer pixels on the part. See choosing a lens when the working distance is fixed.
- Reduce the spread itself: a stop, a guide or a backing plate holds the part against a known plane.
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-number | Depth of field, calculated | Each side | Covers ±10 mm? | Covers ±12 mm? |
|---|---|---|---|---|
| f/2.8 | 14.7 mm | ±7.3 mm | No | No |
| f/4 | 21.0 mm | ±10.5 mm | Yes | No, 1.5 mm short |
| f/5.6 | 29.4 mm | ±14.7 mm | Yes | Yes, 2.7 mm to spare |
| f/11 | 57.7 mm | ±28.8 mm | Yes | Yes |
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.
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).
| Lens | Marked range | Image circle | Covers the 11.01 mm sensor diagonal (calculated)? |
|---|---|---|---|
| MVL-HF2528M-6MPE | F2.8–F16 | Ø9 mm | No |
| MVL-MF2528M-10MPE | F2.8–F16 | Φ11.2 mm | Yes, by 0.19 mm |
| MVL-KF2528M-12MP | F2.8–F16 | Ø17.6 mm | Yes, with margin |
| SA2520M-10MP | F2–F22 | Ø23 mm | Yes, 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
- You treat the interval as proof, and parts at the near and far ends fail on the first production run. Accept a setting only after a depth sweep with the real task.
- Someone reads "the lowest f-number" as "the smallest aperture", its opposite. The iris closes fully, and the station runs short of light for depth nobody needed. Name the f-number you mean, and the range and reserve it was chosen for.
- You pick f/11 because it covers nearly three times the spread. The frame then needs more gain, and feature edges lose contrast instead of gaining it. Its diffraction spot is about 4 pixels (calculated). Compare settings on a real target.
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
- MVisionPro engineering calculator (public calculation core `public-calc-core-v1`) and Hikrobot catalog records (datasheet fields); calculations and catalog routes were verified on 2026-09-21
- Depth of field is the object-side range and depth of focus the image-side tolerance; stopping down increases depth of field while reducing irradiance, and f/5.6 receives four times less light than f/2.8 in the stated comparison: Edmund Optics, https://www.edmundoptics.com/knowledge-center/application-notes/imaging/depth-of-field-and-depth-of-focus/ (checked 2026-09-21)
- The f-number is the focal length divided by the entrance-pupil diameter, so a larger f-number corresponds to a smaller aperture: Basler, https://www.baslerweb.com/en/learning/lens-selection/ (checked 2026-09-21)
- Airy-disk diameter is approximately 2.44 × wavelength × f-number; the 520 nm table gives 3.55 µm at f/2.8, 7.11 µm at f/5.6 and 13.96 µm at f/11: Edmund Optics, https://www.edmundoptics.com/knowledge-center/application-notes/imaging/limitations-on-resolution-and-contrast-the-airy-disk/ (checked 2026-09-21)
- Aperture choice is judged on a representative test target, because stopping down trades decreasing aberrations against increasing diffraction: Edmund Optics, https://www.edmundoptics.com/knowledge-center/application-notes/testing-and-detection/choosing-the-correct-test-target/ (checked 2026-09-21)
- MTF describes contrast transfer versus spatial frequency, so a lens in geometric focus can still fail to deliver feature contrast: Edmund Optics, https://www.edmundoptics.com/knowledge-center/application-notes/imaging/mtf-curves-and-lens-performance/ (checked 2026-09-21)
- A short controlled pulse freezes motion and must fall inside the window in which the rows being used are exposing: Gardasoft, https://www.gardasoft.com/boost-capability-with-pulsed-lighting/ and Basler Flash Window, https://docs.baslerweb.com/line-source#flash-window (checked 2026-09-21)
- Calibration accuracy depends on edge quality, calibration target, lens, mounting, image quality and tool accuracy, and complete-system accuracy must be tested: Cognex, https://docs.cognex.com/is_613/web/EN/ise/Content/How_To/Calibration/CalibrationAccuracy.htm (checked 2026-09-21)
- ISO/IEC 15415:2024 specifies methods to measure and grade attributes of 2D symbols: https://www.iso.org/standard/76876.html (checked 2026-09-21)
- Product-specific image requirements for a code-reading tool, in place of a universal depth boundary: Cognex ReadIDMax, https://support.cognex.com/docs/is_651/web/EN/ise/Content/Reference/ReadIDMax.htm (checked 2026-09-21)
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.