Machine Vision Lens Selection

Field of view, magnification, depth of field, and the smallest defect a camera and lens can resolve. The page also checks whether the optics or the pixels limit resolution, and finds the focal length you need for a given field of view.

Camera and lens

Common global- and rolling-shutter machine vision sensors. Check your camera's datasheet.

px
px

Measured from the lens's front principal plane. The mechanical working distance from the lens barrel is usually a few to tens of millimetres shorter.

f/#
px

Circle of confusion for depth of field, in pixels. Use 1–2.

px

3–5 px for reliable detection, more for measurement.

Results

Field of view (H × V)—
Magnificationm = f/(s − f)—
Sensor size—
Pixel size on the object—
Smallest detectable defect—
Depth of fieldobject side—
Working f-numberN(1 + m)—
Airy disk diameter2.44 λ Nw—
Optical cutoff ÷ sensor Nyquist—
Diffraction MTF at sensor Nyquist— Upper bound for an ideal lens at this working f-number; real lenses add aberrations.
Lens extension beyond fm·f—

Which focal length do I need?

2/3″ IMX250: 8.45 mm. 1″ IMX183: 13.1 mm. 1/1.8″ IMX252: 7.07 mm.

Lens choice

Required focal lengthf = m s/(1 + m)—
Required magnification—
Shorter standard lens (wider view)—
Longer standard lens (needs more distance)—

Standard machine vision focal lengths: 4, 6, 8, 12, 16, 25, 35, 50, 75, and 100 mm.

How the calculation works

The lens is modeled as a thin lens. For an object at distance \(s\) from a lens of focal length \(f\), the magnification and field of view are

\[ m = \frac{f}{s - f}, \qquad \text{FOV} = \frac{\text{sensor size}}{m}, \qquad \text{pixel on object} = \frac{p}{m}, \]

where \(p\) is the pixel pitch. To resolve a defect reliably it should span several pixels (typically 3–5), so the smallest detectable defect is that many object-side pixels.

Depth of field

The depth of field is the range of object distances over which the blur stays under the acceptable circle of confusion \(c\) at the sensor. Here \(c\) is set as a number of pixels. The calculator uses the exact thin-lens limits with hyperfocal distance \(H = f^2/(Nc) + f\):

\[ s_\text{near} = \frac{s(H - f)}{H + s - 2f}, \qquad s_\text{far} = \frac{s(H - f)}{H - s}, \qquad \text{DOF} = s_\text{far} - s_\text{near}. \]

For close-up work (\(s \ll H\)) this reduces to the familiar approximation

\[ \mathrm{DOF} \approx \frac{2\,N\,c\,(1 + m)}{m^2}. \]

A common mistake. The expression \(2Nc(1+m)\) is the image-side depth of focus: how far the sensor can move. Object-side depth of field carries the extra factor \(1/m^2\). At m = 0.14 the two differ by a factor of about 50. Using the wrong one makes a lens look far less forgiving than it is.

Closing the aperture (larger N) increases depth of field linearly, but it also enlarges the diffraction spot and cuts light by \(N^2\). That trade-off is the central compromise in machine vision optics.

Diffraction vs. pixel size

At the sensor, light from a point forms an Airy disk of diameter \(2.44\,\lambda N_w\), where \(N_w = N(1+m)\) is the working f-number. A diffraction-limited lens transmits no detail finer than the cutoff frequency \(1/(\lambda N_w)\) cycles/mm. The sensor can only represent detail up to its Nyquist frequency \(1/(2p)\).

The ratio alone is not the whole story. An ideal lens's MTF falls continuously to zero at the cutoff,

\[ \mathrm{MTF}(\nu) = \frac{2}{\pi}\left[\arccos\nu - \nu\sqrt{1-\nu^2}\right], \qquad \nu = \frac{f_\text{Nyquist}}{f_\text{cutoff}}, \]

so a ratio of exactly 1 still means zero contrast at Nyquist. A ratio of 1.2 gives about 8 %, and 1.5 gives about 22 %.

Real lenses reach the diffraction limit only near f/5.6–f/11 and fall short of it at wide apertures because of aberrations. Check the lens MTF at your sensor's Nyquist frequency.

Worked example

A 2/3″ IMX250 camera (3.45 µm pixels, 2448 × 2048) with a 25 mm lens at f/2.8, 200 mm from the part:

For a 100 mm field at 300 mm with the same sensor, the lower panel gives f = 23.4 mm. A standard 16 mm lens gives a 150 mm field. A 25 mm lens needs the part about 321 mm away.

Assumptions and limits

References

  1. E. Hecht, Optics, 5th ed., Pearson (2017), ch. 5 (geometrical optics) and ch. 10 (diffraction).
  2. J. E. Greivenkamp, Field Guide to Geometrical Optics, SPIE Press (2004).
  3. Edmund Optics, Imaging Resource Guide (application notes on resolution, depth of field, and lens selection).