1-day shipping on stock items3-year warranty minimumFree expert support from licensed P.E.sVolume discountsNet 30 for businesses
Configure a systemQuote

Calculator

Machine vision depth of field calculator

Calculate the depth of field of a machine-vision lens from F-number, pixel size, allowed blur and magnification, and see where diffraction starts to cost sharpness.

LumaSpec Vision Applications Team

On this page 8 sections
  1. 01How the depth of field calculation works
  2. 02Worked example: F/8, 3.45 µm pixels, m = 0.1
  3. 03Aperture against diffraction
  4. 04Light colour moves the diffraction limit
  5. 05Magnification matters most
  6. 06When the estimate is not enough
  7. 07Next steps
  8. 08Questions

A lens is only sharp in one plane; everything nearer or further away blurs gradually. Depth of field is how far a part can move along the camera's axis before that blur becomes too large for the inspection. Enter the F-number set on the lens, the camera's pixel size, how many pixels of blur you accept and the magnification (or the sensor width and field of view, and it works the magnification out). Pick the colour of the light. The calculator returns the depth of field, the diffraction spot and the F-number where diffraction starts to cost sharpness, plots depth against every F-stop with the diffraction-limited range shaded, and tabulates each stop.

Depth of field and diffraction
Units
Depth of field
– mm
About the focus plane
– mm
Diffraction limit
– F/#
Blur limit
– µm
Diffraction spot
– µm
At this F-number
–

DOF ≈ 2 × N × c × (1 + m) / m², c = allowed blur × pixel size. Diffraction spot (Airy disk) ≈ 2.44 × wavelength × N × (1 + m); past the diffraction limit it is larger than the blur you allowed.

Browse lenses by aperture and format

How the depth of field calculation works

c = allowed blur in pixels × pixel size DOF ≈ 2 × N × c × (1 + m) / m² m = sensor width / field of view width

N is the F-number marked on the lens, c the largest acceptable blur spot on the sensor and m the magnification. The (1 + m) term turns the marked F-number into the working F-number, which matters at close range. The result is the total depth, roughly half in front of the plane of focus and half behind it at low magnification.

If you do not know the magnification, take it from the lens focal length calculator: an 8.8 mm wide sensor covering an 88 mm field is at m = 0.1.

Depth of field around the focus planeLight from the lens converges on the focus plane. In front of and behind it, each point spreads into a blur circle; the zone where that blur stays below about a pixel or two is the depth of field. A smaller aperture gives a narrower cone and a deeper zone.depth of fieldfocus planeapertureoutside it, pointsblur into circleswide aperture: steep cone, shallow zonesmall aperture (high F#): deeper zone
Depth of field around the focus plane. Light from the lens converges on the focus plane. In front of and behind it, each point spreads into a blur circle; the zone where that blur stays below about a pixel or two is the depth of field. A smaller aperture gives a narrower cone and a deeper zone.

Worked example: F/8, 3.45 µm pixels, m = 0.1

  1. Allowed blur: 2 pixels × 3.45 µm = 6.9 µm = 0.0069 mm.
  2. Depth of field: 2 × 8 × 0.0069 × 1.1 / 0.01 = 12.1 mm.

Parts can vary by about ±6 mm around the focus plane and stay within 2 pixels of blur. If they vary more, the next options are a smaller aperture, a lower magnification or a larger blur allowance, each with a cost.

Aperture against diffraction

Closing the aperture adds depth in direct proportion, but it also widens the diffraction spot that even a perfect lens produces. The spot's diameter (the Airy disk) is about 2.44 × wavelength × working F-number. The table shows both for green light (550 nm), m = 0.1 and the example's 6.9 µm blur limit:

F-number Depth of field Diffraction spot Spot in 3.45 µm pixels
F/2.8 4.2 mm 4.1 µm 1.2
F/4 6.1 mm 5.9 µm 1.7
F/5.6 8.5 mm 8.3 µm 2.4
F/8 12.1 mm 11.8 µm 3.4
F/11 16.7 mm 16.2 µm 4.7
F/16 24.3 mm 23.6 µm 6.8

From about F/5.6 the diffraction spot is larger than the blur limit itself, so detail at the pixel level softens even in perfect focus. That is acceptable when the smallest feature spans many pixels and is not when it spans two or three. Larger pixels move the limit: with 5.5 µm pixels the same spot stays within two pixels to just under F/8.

Light colour moves the diffraction limit

Diffraction grows with wavelength, so the same lens is sharper at a given F-number under blue light than under red or infrared light. The depth of field from the geometric formula does not change with colour. With 3.45 µm pixels, a 2-pixel blur limit and m = 0.1, the F-number at which the diffraction spot reaches the blur limit is:

Light Wavelength Diffraction limit
Blue 470 nm F/5.5
White (green peak) 550 nm F/4.7
Red 625 nm F/4.1
Infrared 850 nm F/3.0

Infrared lighting, often chosen to ignore colour variation or ambient light, therefore needs wider apertures or larger pixels to stay sharp, and leaves less depth to work with. Blue light is a common choice when fine detail and depth are both needed.

Magnification matters most

Depth of field falls with the square of the magnification. Keeping F/8, 3.45 µm pixels and 2 pixels of blur:

Magnification Field on an 8.8 mm sensor Depth of field
0.05 176 mm 46 mm
0.1 88 mm 12.1 mm
0.2 44 mm 3.3 mm
0.5 17.6 mm 0.66 mm
1.0 8.8 mm 0.22 mm

Halving the field cuts the depth to roughly a quarter. This is why close-up inspection of small features needs flat, well-located parts, and why the field of view should not be smaller than the task needs.

When the estimate is not enough

  • Telecentric lenses. The formula still applies, using the lens's working F-number and its fixed magnification. Telecentric lenses at high magnification often have only a fraction of a millimetre of depth, and their data sheets print the value.
  • Tilted surfaces. A surface at an angle to the camera needs depth across the whole field. A Scheimpflug adapter tilts the plane of focus to match the surface instead.
  • Spacers and close range. Extension tubes from the lens accessories raise the magnification and so shrink the depth; recalculate after adding one.
  • Real lenses. Aberrations add their own blur, mostly at wide apertures and at the image corners. Test at the chosen aperture with a part at both ends of its height range.

Next steps

Check the camera resolution calculator to confirm the blur limit you allowed still leaves enough pixels on the smallest feature. The focal length guide covers lens choice end to end, and the lens finder filters lenses by aperture, format and focal length.

Questions

What is depth of field in machine vision?

It is the range of distances, along the camera's axis, over which a part stays sharp enough for the inspection. Sharp enough means the blur stays below a limit you choose, usually one to two pixels. Parts that vary in height, sit on a moving conveyor or have tall features need a depth of field at least as large as that variation.

Which F-number should I use for a machine vision lens?

Start around F/4 to F/5.6 for small-pixel sensors and F/5.6 to F/8 for larger pixels. Close down further only when the parts need the depth, and add light to keep the exposure short. From about F/5.6 to F/8 with pixels near 3.45 micrometres, diffraction softens pixel-level detail even in the plane of best focus.

Does a longer focal length reduce depth of field?

At the same magnification and F-number, the depth of field is nearly the same whatever the focal length. A longer lens at a longer distance to cover the same field gives the same magnification and so about the same depth. What reduces depth is a higher magnification, meaning a smaller field on the same sensor, or a wider aperture.

How can I get more depth of field without losing sharpness?

Lower the magnification by covering a wider field, use a sensor with larger pixels, accept a larger blur if the features are large, or tilt the lens against the sensor (Scheimpflug) when the surface is inclined. For parts at very different heights, a liquid lens or motorised focus can refocus between parts instead.