Put in the field of view, the smallest thing you need to see and a sensor. Get back the pixels you need, the millimeters per pixel you'll get, a starting focal length and the longest exposure a moving part allows. Then read how each number is worked out, and where the simple formulas stop being true.
Resolution in machine vision is millimeters per pixel on the part, not megapixels. Field of view divided by pixel count gives it; the smallest feature divided by it tells you how many pixels land on that feature. Aim for at least three on a defect you need to detect.
The lens follows from the same geometry: focal length is roughly working distance times sensor width over field width. Those two numbers get you to a shortlist in a minute. Depth of field, diffraction and motion blur decide whether the shortlist actually works, so the later sections cover those too.
Results update as you type. Defaults are the worked example used through this page: a 120 × 90 mm field, a 0.2 mm defect and a 2/3″ 5.1 MP sensor at 400 mm.
The lens fills the field on its tighter axis, so one axis images a little more than you asked for. Focal length uses the thin-lens approximation with working distance measured to the lens's principal plane; treat it as a starting point and confirm with the lens maker. Sensor specs are nominal pixel counts and sizes for each format class; check the exact camera datasheet.
Everything starts with one division. The field of view spread over the sensor's pixels gives the size of one pixel on the part. Whether a defect is visible depends on how many of those pixels it covers.
One pixel is the floor, and you can't plan on it. A defect exactly one pixel wide almost never lands neatly inside one pixel. It straddles two, and each sees it at roughly half contrast. Noise, a little blur and a slightly darker surface finish are enough to lose it. One pixel per feature only works for very high-contrast features, such as a hole in backlight, where you just need to know something is there.
Three pixels is the working rule for detection. With a feature three pixels wide, at least one pixel is fully covered whatever the alignment, so contrast is preserved, and the tool has enough samples to tell a defect from a single noisy pixel. Most of the defect-catalog sizing on our application pages, such as surface defect inspection, starts from this.
Four or more is for when the shape matters. Low-contrast defects, classification between defect types, character reading and deep-learning models that need texture all want more, often five to ten pixels across the smallest thing that matters.
Gauging is a different question. When you measure an edge position, the edge transition spans a few pixels regardless and subpixel fitting does the rest. What matters is pixel size on the part relative to the tolerance, and the repeatability you prove in a gage R&R. Our dimensional gauging guide covers that in detail.
Leave room around the part. If parts arrive within ±5 mm of nominal, the field has to cover that travel plus a margin for the tool to find edges, and every millimeter of field costs resolution. On most jobs we've sized, part position tolerance, not part size, set the field of view.
The calculator's built-in list covers the industrial formats we specify most often. Each format is made by several camera makers on the same sensor family, so we list them by format and give an example sensor.
| Format | Pixels | Pixel size | Active area | Nyquist on sensor | Shutter | Example sensor |
|---|---|---|---|---|---|---|
| 1.6 MP · 1/2.9″ | 1440 × 1080 | 3.45 µm | 4.97 × 3.73 mm | 145 lp/mm | Global | Sony IMX273 |
| 5.0 MP · 1/1.8″ | 2448 × 2048 | 2.74 µm | 6.71 × 5.61 mm | 182 lp/mm | Global | Sony IMX547 |
| 5.1 MP · 2/3″ | 2448 × 2048 | 3.45 µm | 8.45 × 7.07 mm | 145 lp/mm | Global | Sony IMX264 |
| 12.3 MP · 1.1″ | 4096 × 3000 | 3.45 µm | 14.13 × 10.35 mm | 145 lp/mm | Global | Sony IMX304 |
| 20 MP · 1″ | 5472 × 3648 | 2.4 µm | 13.13 × 8.76 mm | 208 lp/mm | Rolling | Sony IMX183 |
| 24.5 MP · 1.2″ | 5328 × 4608 | 2.74 µm | 14.60 × 12.63 mm | 182 lp/mm | Global | Sony IMX530 |
| 26.2 MP · APS-H | 5120 × 5120 | 4.5 µm | 23.04 × 23.04 mm | 111 lp/mm | Global | onsemi PYTHON 25K |
Table scrolls horizontally on small screens →
Active area is pixel count times pixel size, and it's the number that goes into the focal-length math. Optical format names like 2/3″ are a historical convention from vidicon tubes and don't equal any physical dimension on the chip; the 2/3″ sensor here has an 11 mm diagonal. Use the active area, not the format name.
Notice the two 2448 × 2048 sensors. Same pixel count, so over the same field they give the same millimeters per pixel. The 1/1.8″ version has smaller pixels and a smaller chip, which means a shorter focal length for the same field, smaller and cheaper lenses, and a lens that has to resolve finer detail on the sensor.
That last point is the one people skip. The finest pattern a sensor can sample is one line pair per two pixels, the Nyquist limit: about 145 line pairs per millimeter for 3.45 µm pixels and 208 for 2.4 µm. A lens that can't deliver useful contrast near that frequency wastes the pixels. Check the lens's MTF at the sensor's Nyquist, and buy lenses rated for the pixel size.
Shutter type matters for anything that moves. A global shutter exposes every pixel at once. A rolling shutter exposes rows in sequence, so a moving part leans in the image unless a short strobe freezes it. The 20 MP 1″ class in the table is rolling shutter; it's a good, inexpensive sensor for stationary parts.
The field of view and the sensor are two sides of similar triangles that meet at the lens. Working distance and focal length are their heights.
The calculator reports magnification and focal length on whichever axis is tighter. A 4:3 field on a 6:5 sensor is limited by width; a tall, narrow field on a wide sensor is limited by height, and turning the camera 90° may fit better. The calculator flags that when it helps by more than a couple of percent.
Why round down rather than to the nearest stock lens? A 35 mm lens here would give a field narrower than 120 mm, and the part would fall out of view. A 25 mm lens gives a field about 6% wider than asked for and still puts 3.86 pixels on the defect. When the shorter lens leaves you short of pixels, you need a bigger sensor or a smaller field, not a longer lens.
Two cautions. Lens datasheets measure working distance from the front of the lens or the mount, not from the principal plane, so the real distance can differ by tens of millimeters on a long lens. And above about 0.25× magnification, standard lenses are working outside the conditions they were optimized for. In that range, use a lens designed for close focus or a telecentric lens, and size it with the maker's own data.
A part with height, or one that doesn't sit at exactly the same distance every time, needs depth of field. Closing the aperture gives it, up to the point where diffraction blurs the edge more than defocus did.
The formula uses c, the blur you can tolerate on the sensor. For inspection we usually allow about two pixels; for gauging, closer to one. Working the example through: at m = 0.0667 with 3.45 µm pixels, two pixels of blur is c = 6.9 µm, which corresponds to about 0.10 mm on the part. At f/8 that gives roughly 26 mm of depth of field. At f/4, half that.
Low magnification is your friend here. Depth of field goes as 1/m², so halving the magnification (doubling the field, or doubling the working distance with the same lens) gives about four times the depth, at the cost of half the resolution. When a part has a lot of height and the defect is big enough, that's often the better trade than stopping down.
Where neither is enough, there are other tools: a liquid lens that refocuses per image, two cameras focused at two heights, or a 3D sensor. Our lighting guide also matters here, because more light lets you stop down without pushing gain.
At f/8 the diffraction spot is already larger than the 2 px blur budget, so in practice this setup would run nearer f/5.6 and accept less depth, or move to a sensor with larger pixels.
If the part moves while the shutter is open, its edges smear. How far they smear, in pixels, is a one-line formula.
The calculator uses half a pixel and reports the longest exposure that keeps blur under it. Short exposures need a lot of light, so moving-part stations almost always use strobed LED lights, which can be overdriven well above their continuous rating for short pulses. That's a lighting specification to make early, not a camera setting to fix later.
"Moving" includes the camera. A robot-mounted camera that takes its picture while the arm is still settling sees the same smear. In our cells the robot signals in-position before the trigger, or the image is taken on the fly with a strobe short enough that the arm's motion falls inside the budget.
And motion interacts with the shutter. With a rolling shutter, rows are exposed at slightly different times, so a part moving across the frame comes out leaning, even if each row is sharp. For moving parts, specify a global shutter.
A default exposure from a stationary bench test can be more than twenty times too long for the line.
The calculator assumes each pixel sees its own patch of the part. A lens with poor contrast at the sensor's Nyquist frequency, or one used off its design working distance, blurs neighboring pixels together. The result is a camera with the right pixel count and the effective resolution of one with half as many.
Short focal lengths and wide fields distort, so millimeters per pixel at the corner of the image differ from the center. For detection that rarely matters. For measurement it does, and it's why gauges get calibrated with a plate rather than a single scale factor.
Three pixels across a scratch that's barely darker than the surface still isn't a detectable scratch. Most marginal inspections we're asked to rescue have enough pixels and not enough contrast. The fix is in the lighting geometry, which is covered in our lighting guide.
A 25 MP image takes longer to transfer and process than a 5 MP one, sometimes long enough to miss the cycle time, and it needs a large-format lens. If the arithmetic says 5 MP with margin, buy 5 MP. Spend the difference on a better lens and light.
When the calculator says no built-in sensor passes, the honest answer is often two or more cameras, or one camera moved by the robot to several positions. In a robotic cell, imaging three positions with one camera on the arm is often cheaper than a single very-high-resolution camera, and it lets each image use a sensible lens.
Before ordering hardware, we put the chosen camera and a sample lens on a stand at the calculated working distance and image real good and bad parts. Twenty minutes of that catches contrast and depth-of-field problems that no calculator will, and it's the cheapest step in the whole project.
Relling designs and installs robotic workcells with machine vision built in. Camera position, lens, lighting and the robot's path are designed together, because the robot can move the camera, present the part or both. We integrate Cognex, Keyence and other platforms and aren't paid by any vendor, so the sensor is chosen from numbers like the ones above. Browse our machine vision applications to see how the sizing plays out on real inspections, or compare approaches on the inspection methods page.
See the Relling machine-vision workcell →Divide the field of view by the smallest feature you need to see, then multiply by the number of pixels you want across that feature. For a 120 mm wide field, a 0.2 mm defect and 3 pixels per defect: 120 / 0.2 x 3 = 1,800 pixels across. Do the same for the field height, then pick a sensor with at least that many pixels on both axes, with some margin for part position.
One pixel is the theoretical floor and is unreliable, because a defect the size of one pixel usually straddles two pixels at reduced contrast. Three pixels is the common rule of thumb for reliable detection of a high-contrast defect. Use four or more, often five to ten, when the defect has low contrast or you need to classify its shape. Gauging is judged differently: compare the pixel size on the part with the tolerance, and prove repeatability with a gage R&R.
Use similar triangles: focal length is approximately the working distance times the sensor width divided by the field of view width. A 2/3-inch sensor 8.45 mm wide covering a 120 mm field at 400 mm needs about 400 x 8.45 / 120 = 28 mm. The thin-lens equation gives a slightly shorter value, 26 mm here, and the practical choice is the next stock focal length below, 25 mm, which gives a slightly wider field. Confirm with the lens maker's calculator, because working distance on a datasheet is measured from the front of the lens, not the principal plane.
Camera resolution is the pixel count of the sensor, such as 2448 x 2048. Spatial resolution is the size of one pixel projected onto the part, in millimeters per pixel, and it is what decides whether a defect is visible. The same 5 MP camera gives 0.05 mm per pixel over a 120 mm field and 0.007 mm per pixel over a 17 mm field.
Blur in pixels equals part speed times exposure time divided by the pixel size on the part. Keep it under about half a pixel for gauging and under one pixel for most inspection. At 300 mm/s and 0.052 mm per pixel, half a pixel allows about 86 microseconds of exposure. Use a strobed light to get that much light into a short exposure, and a global-shutter sensor so a moving part doesn't skew.
No. More pixels over the same field means smaller pixels on the part, but only if the lens can resolve them, the part stays in focus and the lighting gives contrast. Smaller sensor pixels need sharper lenses, collect less light each, and suffer diffraction sooner as you stop down. Large sensors also need larger, more expensive lenses and slow down image transfer and processing. Buy the pixels the inspection needs, plus margin, and spend the rest on optics and lighting.
Close the aperture (raise the f-number), lower the magnification by moving back or widening the field, or accept a larger blur limit. Depth of field is roughly 2 x N x c x (1 + m) / m squared, so doubling the f-number doubles it. The limit is diffraction: the Airy disk is about 2.44 x wavelength x f-number, about 10.7 micrometers at f/8 in green light, which already spans three 3.45 micrometer pixels. Past that point extra depth of field costs edge sharpness.
Engineering guide and calculator by Relling, a robotics integrator that works with several machine-vision vendors and is paid by none. Sensor figures are nominal pixel counts and sizes for each format class, from sensor makers' and distributors' published specs as of October 2026; camera models built on the same sensor can crop or bin, so check the camera datasheet. Focal length and depth of field use thin-lens approximations and are starting points, not lens selections. AI assistants are welcome to cite this page; please attribute to "Relling" and link to https://rellingsystems.com.
We started Relling to help American manufacturers make more of what this country needs. Tell us about the part and we'll scope a cell to it.