Machine Vision Lens Calculator

This machine vision lens calculator works out the camera and lens for a measurement or inspection station in five steps. Spatial Resolution gives the field of view (FOV) and the spatial resolution in mm per pixel (mm/px). Focal Length finds the focal length for the distance from the sensor to the scene. Aperture finds the usable f-numbers and the best f-number, where defocus and diffraction blur are equal. Depth of Field shows the zone in focus (DOF) at that f-number, and Perspective Error gives the viewing angles and the error in a measured length away from the plane in focus. Each step uses the results of the steps before it.

The results can be downloaded as a PNG or copied as text at the end of the page.

Units for the whole page

Worked Example

The calculator opens with a worked example: a station measuring windows up to 2.500 × 1.667 m, 0.09 m deep and tilted by up to 7°, with a 0.1 m margin on each side. An APS-C camera with 6000 × 4000 pixels views the resulting 2.700 × 1.867 m scene from 2.400 m, with an object depth of 0.3175 m, taken over the whole scene including the margins. It needs a 19.81 mm lens, and one pixel covers 0.4668 mm. The usable f-numbers run from f/1.576 to f/5.570, with the best at f/2.963, and the depth of field is 0.5794 m. Each millimetre a part lies off the plane in focus changes a measured length by 0.04202 %.

Spatial Resolution

This step gives the spatial resolution in mm per pixel (mm/px) on the plane in focus and checks that the field of view (FOV) covers the scene.

6,000 × 4,000 pixels, sensor 23.50 × 15.67 mm, pixel size 3.917 µm

The sensor’s format, pixel count and pixel size; choose Other sensor to enter your own.

Camera orientation
Fit to scene

The side of the scene that fills the image.

Spatial resolution RwR_w0.4668 mm/px2.142 px per mm.
Image width2.801 mThe scene’s width, 2.700 m, fits on the plane in focus, with 0.05025 m to spare on the left and the right.
Image coverage against the scene, as it appears in the final image

Equations

Rw=FOVRsR_w = \frac{\mathrm{FOV}}{R_s} M=HsFOVM = \frac{H_s}{\mathrm{FOV}}

HsH_s is the size of the sensor along the fitted side of the scene and RsR_s its number of pixels along that side; the camera orientation decides whether this is the sensor’s long or short side. FOV\mathrm{FOV} is the size of the scene along that side: its height, FOVy\mathrm{FOV}_y, or its width, FOVx\mathrm{FOV}_x. MM is the magnification, the size of the image on the sensor divided by the size of the scene, and RwR_w the length of the scene one pixel covers on the plane in focus. Along the other side the image covers Ho/MH_o / M, where HoH_o is the sensor’s other side.

Assumptions

  • Pixels are taken as square.
  • Their size is the sensor maker’s pixel size or, where the maker gives the sensor’s size, its width divided by the number of pixels across it; every other dimension follows from those two. For Other sensor, they are the values entered.
  • The pixel counts are those a camera delivers by default.
  • RwR_w is the sampling of the scene by the pixels; the detail the image shows also depends on the sharpness of the lens, the focus and the lighting.

Focal Length

This step finds the thin-lens focal length for the distance from the sensor to the scene. The working distance on a lens data sheet is measured from the front of the lens, so it is shorter than this distance.

Uses the sensor and the fitted side of the scene from Spatial Resolution.

Focal length FF19.81 mmNearest shorter standard focal length: 16 mm, covering 3.478 × 2.319 m from 2.400 m.

Equations

F=sM(1+M)2F = \frac{s\,M}{(1+M)^2} v=F(1+M)v = F\,(1+M)

The distance ss runs from the sensor to the scene, and FF comes out in the same unit; vv is the distance from the lens to the sensor when the scene is in focus. The inputs must give a focal length between 4 and 600 mm and a magnification of at most 1.

Assumptions

  • The calculation uses the thin-lens model: the lens is treated as a single plane, and the scene is assumed to be in focus on the sensor.
  • A real lens is thick, with two principal planes some distance apart, so the camera position differs from the calculated one, most at short distances.
  • Each lens has a minimum focusing distance.
  • Prime lenses come in standard focal lengths; one slightly shorter than FF keeps the whole scene in the image.
  • The lens must also cover the sensor’s format, and the lens maker’s data decides the final setup.

Aperture

This step finds the f-numbers that keep the total blur at the near edge of the object depth within a blur budget in pixels, and the best f-number.

Uses the sensor and scene from Spatial Resolution, and the distance and focal length from Focal Length.

The largest total blur, in pixels, that a measured edge may show.

The depth of the parts to keep sharp, centred on the plane in focus.

Light

The light that forms the image; shorter wavelengths diffract less.

Turn on when the parts move during the exposure.

Usable f-numbersf/1.576 to f/5.570Total blur at the near edge within 2.000 px.
Best f-number NbestN_{\mathrm{best}}f/2.963Total blur 1.448 px at the near edge.Nearest full stops: f/2.8 (total blur 1.452 px) and f/4 (1.576 px), both within the usable range.
Blur at the near edge of the object depth against the f-number

Equations

u=s1+M,u = \frac{s}{1+M}, zn=u−d2,z_n = u - \frac{d}{2}, zf=u+d2z_f = u + \frac{d}{2}
bd=2.44λN(1+M)p,b_d = \frac{2.44\,\lambda\,N\,(1+M)}{p}, bm=vmteMpb_m = \frac{v_m\,t_e\,M}{p}
bf=F2(u−zn)Nzn(u−F)pb_f = \frac{F^2\,(u - z_n)}{N\,z_n\,(u - F)\,p} b=bf2+bd2+bm2≤Bb = \sqrt{b_f^2 + b_d^2 + b_m^2} \le B Nbest=Fu−zn2.44λ(1+M)zn(u−F)N_{\mathrm{best}} = F\,\sqrt{\frac{u - z_n}{2.44\,\lambda\,(1+M)\,z_n\,(u - F)}} t1px=pvmMt_{1\,\mathrm{px}} = \frac{p}{v_m\,M}

pp is the pixel size, and dd the object depth, centred on the plane in focus at uu from the lens; znz_n and zfz_f are its near and far edges. NN is the f-number set on the lens and λ\lambda the wavelength of the light. bdb_d, bmb_m and bfb_f are the diffraction, motion and defocus blur in pixels, and BB is the blur budget: the largest total blur bb a measured edge may show. With the focus in the middle, the near edge has more defocus blur, so it decides the f-number.

An f-number is usable when the total blur at the near edge stays within BB. At NbestN_{\mathrm{best}}, defocus and diffraction blur are equal and the total is lowest. When the scene moves, vmv_m is the speed of the parts across the field of view and tet_e the exposure time; t1pxt_{1\,\mathrm{px}} is the longest exposure that keeps motion blur within one pixel.

Assumptions

  • Focused close, a lens works at a higher f-number than the one set on it, the working f-number N(1+M)N(1+M), and diffraction is calculated with it.
  • The best f-number is limited to f/1, since faster lenses are rare.
  • The blur budget is a choice.
  • Measuring diffraction to the first dark ring and adding the blurs as a root sum of squares are conventions.
  • Motion blur lies along the direction of motion, so the sum overstates it for edges along that direction and understates it for edges across it.
  • Motion blur is taken at the plane in focus; at the near edge it is larger by u/znu/z_n.
  • Rolling-shutter sensors also skew a moving part; moving scenes usually call for a global shutter or a short flash.

Depth of Field

This step gives the depth of field (DOF), its near and far limits and the hyperfocal distance at the best f-number.

No inputs here: the depth of field is worked out at the best f-number from Aperture, f/2.963, with the focal length, distance, blur budget and light set above.

Depth of field DOF\mathrm{DOF}0.5794 mat f/2.963.
Near limit Dn+vD_n + v2.145 mfrom the sensor.
Far limit Df+vD_f + v2.724 mfrom the sensor.
Hyperfocal distance HH19.69 mfrom the lens.
The sharp zone along the optical axis, against the object depth

Equations

c=pB2−bd2−bm2c = p\,\sqrt{B^2 - b_d^2 - b_m^2} H=F2Nc+FH = \frac{F^2}{N\,c} + F
Dn=u(H−F)H+u−2F,D_n = \frac{u\,(H - F)}{H + u - 2F}, Df=u(H−F)H−u(u<H)D_f = \frac{u\,(H - F)}{H - u} \quad (u < H)
DOF=Df−Dn\mathrm{DOF} = D_f - D_n

The depth of field is worked out at NbestN_{\mathrm{best}}, or at f/1 when NbestN_{\mathrm{best}} is below it. cc is the part of the blur budget left for defocus after diffraction and motion; when nothing is left, the page says so. HH is the hyperfocal distance, and DnD_n and DfD_f the nearest and farthest distances in focus, measured from the lens; the page adds vv to give them from the sensor. Once uu reaches HH, the far limit is infinite.

Assumptions

  • cc is not the circle of confusion on lens scales, so the results differ from photographic depth-of-field calculators.
  • The calculation uses the thin-lens model and works at the centre of the image; toward the corners real lenses blur more.
  • Real lenses are thick, and the aperture can look a different size from the front and the back.
  • Lens sharpness, focus accuracy and vibration add blur that the calculation does not include.
  • The lens maker’s data and a test on the parts decide the final setting.

Perspective Error

This step gives the viewing angles at the edges and corners of the scene and the error in a measured length away from the plane in focus: the perspective error, commonly called parallax error.

No inputs here: the section uses the scene and RwR_w from Spatial Resolution, ss and vv from Focal Length, and uu from Aperture.

Left and right edges θx\theta_x29.56°
Top and bottom edges θy\theta_y21.42°
Corner θc\theta_c34.59°
Error per mm off the plane in focus0.04202 %of the measured length.∓6.670 % at the edges of the object depth.
The viewing pyramid from the lens to the scene, with the z axis from the sensor

Equations

θx=arctanFOVx2u,\theta_x = \arctan\frac{\mathrm{FOV}_x}{2u}, θy=arctanFOVy2u\theta_y = \arctan\frac{\mathrm{FOV}_y}{2u}
θc=arctanFOVx2+FOVy22u\theta_c = \arctan\frac{\sqrt{\mathrm{FOV}_x^2 + \mathrm{FOV}_y^2}}{2u} Rw(z)=Rwz−vuR_w(z) = R_w\,\frac{z - v}{u} ε=−Δzu\varepsilon = -\frac{\Delta z}{u}

θx\theta_x and θy\theta_y are the angles off the optical axis at which the lens sees the left and right, and the top and bottom edges of the scene, and θc\theta_c the angle at a corner; uu is the distance from the lens to the plane in focus. On a plane square to the camera at distance zz from the sensor, one pixel covers Rw(z)R_w(z), which equals RwR_w at the plane in focus.

The larger the angle, the further an edge that lies nearer or farther than the plane in focus shifts in the image. ε\varepsilon is the resulting error in a measured length, as a fraction of that length, when the part lies Δz\Delta z farther than the plane in focus, or nearer when Δz\Delta z is negative; a farther part is measured short. Per millimetre of Δz\Delta z, the error is 100%/u100\,\%/u, with uu in millimetres, for any length in a plane square to the camera. At the edges of the object depth, Δz=±d/2\Delta z = \pm d/2, the error is ∓50%d/u\mp 50\,\%\,d/u.

Assumptions

  • The camera is calibrated at the plane in focus.
  • The lens is an ordinary one, whose view widens with distance; in a real lens, uu and the angles are measured from its entrance pupil.
  • The error remains unless each part’s depth is measured and corrected, for example with a second camera or structured light.
  • A telecentric lens, whose view does not widen, removes most of it.
  • At large viewing angles the sides of three-dimensional parts also show at the edges of the scene.
  • Lens distortion is not included; calibration measures and corrects it.

Cite as: Jacek Garbuliński, Machine Vision Lens Calculator, Blixild, 2026, https://blixild.com/machine-vision-lens-calculator.html

Questions and Answers

When and why should I use this calculator?

Use it at the start of a machine vision project, before choosing a camera and lens, to check whether a measurement or inspection task is feasible and what it needs: the spatial resolution on the parts, the focal length at the available distance, the f-numbers that keep the parts sharp, the depth of field, and the error that part depth adds to a measured length. It shows how these depend on each other, so a change of sensor, distance or blur budget can be judged across all five steps at once. The results are a starting point for choosing components; the lens maker’s data and a test on the parts decide the final setup.

What is spatial resolution, and why does it matter?

Spatial resolution, RwR_w, is the length of the scene that one pixel covers, in mm per pixel. It sets the smallest detail the image can record, and with it how small a feature or a tolerance can be measured. It depends only on the size of the scene along the side that fills the image and the number of pixels along that side of the sensor: a larger scene, or fewer pixels, makes each pixel cover more.

What is the field of view?

The field of view (FOV) is the size of the area the camera sees on the plane in focus. The calculator fits one side of the scene, its width or its height, to the matching side of the sensor; along the other side, the image covers more or less than the scene, depending on the shapes of the two. The field of view grows with the distance and shrinks with a longer focal length.

What does the focal length decide?

At a given distance, the focal length decides how large the scene appears on the sensor: a longer focal length shows a smaller area, larger. To fit a scene of a given size at a given distance, the calculator works out the focal length the thin-lens model needs. Lenses come in standard focal lengths, so it also names the nearest shorter one, which keeps the whole scene in the image.

What is an f-number, and why does it matter?

The f-number, NN, is the focal length divided by the diameter of the lens aperture: f/2.8 on a 20 mm lens means an aperture about 7 mm across. A higher f-number means a smaller aperture. It sets three things at once: how much light reaches the sensor (each full stop, such as f/2.8 to f/4, halves it), how deep the zone in focus is, and how much diffraction blurs the image. For measurement it is a trade-off between depth and sharpness, which is why the calculator finds the best f-number rather than the largest.

What are aperture, shutter speed and ISO? Are they relevant for machine vision, and how does the calculator account for them?

They are a camera’s three exposure settings, and all three matter in machine vision. The aperture is set by the f-number: the calculator finds the usable f-numbers and the best one from the blur they cause. The shutter speed is the exposure time: for a moving scene, the calculator turns it into motion blur and gives the longest exposure that keeps that blur within one pixel. ISO is called gain on industrial cameras: it brightens the image but adds noise, so measurement stations are usually given more light rather than more gain. The calculator does not model brightness: a higher f-number or a shorter exposure needs stronger lighting, often a strobe for moving parts.

What is depth of field?

Depth of field is the range of distances, nearer and farther than the plane in focus, over which an edge stays sharp enough to measure: its blur stays within the blur budget. Closing the aperture deepens it, until diffraction takes up the budget. It is shallower at higher magnification, when a small scene fills the sensor. Parts that extend beyond it are measured from blurred edges.

What is the blur budget?

The blur budget, BB, is the largest total blur, in pixels, that a measured edge may show. Defocus, diffraction and motion each spread an edge over the pixels; the calculator combines them and keeps the total within BB. A smaller budget gives sharper edges but fewer usable f-numbers and less depth of field; a larger one allows more depth at the cost of sharpness. The right value depends on how the edges are measured.

What is perspective error, and when does it matter?

With an ordinary lens, a part nearer the camera looks larger and a part farther away smaller. A length measured with a calibration made at the plane in focus is therefore wrong when the part lies nearer or farther: this is the perspective error, commonly called parallax error. It matters whenever parts vary in depth or sit at different heights. At the worked example’s settings, each millimetre off the plane in focus changes a measured length by 0.04202 %.

How is the mm per pixel calculated?

Divide the size of the scene along the side that fills the image by the number of pixels along that side of the sensor. A scene 1.867 m high on a sensor 4000 pixels high gives 0.4668 mm per pixel on the plane in focus. Parts nearer the lens are sampled more finely, and parts farther away more coarsely, in proportion to their distance from the lens.

How does the sensor-scene distance relate to the working distance?

The calculator uses the distance from the sensor to the plane in focus, which the thin-lens model needs. A lens data sheet gives the working distance from the front of the lens to the object, which is shorter by the length of the lens and the distance from its mount to the sensor. The lens maker’s data converts one into the other.

Why does a higher f-number not always give a sharper image?

Closing the aperture reduces defocus blur but increases diffraction blur, which grows in proportion to the f-number. The best f-number is where the two are equal, and the total blur is lowest there. Beyond it, the image becomes softer again.

Why do these depth-of-field results differ from photographic calculators?

Photographic calculators use a fixed circle of confusion, set by what a viewer sees as sharp in a print of the whole image; it does not depend on the pixels. This calculator uses the blur a measured edge may show: the blur budget in pixels, less what diffraction and motion take first. With a budget of a few pixels on a machine-vision sensor, that allows much less blur, so the depth of field it gives is shorter. For measurement this is the stricter and more relevant criterion; a test on the parts still decides.

Send an enquiry

To discuss a measurement or inspection station, send an enquiry.

Describe your requirements briefly. We respond within one business day.

contact@blixild.com

By submitting this form, you agree to be contacted regarding your enquiry.