◇ Machine vision · Guide

Machine vision resolution and lens calculator.

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.

7Common sensor formats built in, plus custom
3 pxDefault pixels across the smallest feature
½ pxMotion-blur budget used for the exposure limit
In short

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.

Calculator

Size the camera and lens.

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.

Pixels needed across the field—
Sensor active area—
Resolution on the part—
Pixels across smallest feature—
Magnification—
Approximate focal length—
Longest exposure—

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.

Spatial resolution

Field, feature and pixels: the first number.

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.

Fig. 01A 0.2 mm defect spanning 3 pixels in a 120 mm field
Field of view · 120 × 90 mm 120 mm → 1,800 px needed 90 mm → 1,350 px 0.2 mm = 3 px 1 px = 120 mm ÷ 1,800 px = 0.067 mm
Pixels on the part, not pixels on the sensor, decide what you can see. The scratch here is 0.2 mm long and the field is 120 mm wide. Three pixels across it means 0.067 mm per pixel, so 1,800 pixels across the width and 1,350 down the height. A 1.6 MP sensor at 1440 × 1080 falls short; a 5 MP sensor at 2448 × 2048 clears it with margin.

Why three pixels, and when to use one or more than four

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.

Worked example 1 · pixels needed FOV 120 × 90 mm, smallest defect 0.2 mm, 3 px per defect target pixel size = 0.2 / 3 = 0.0667 mm/px pixels across width = 120 / 0.2 × 3 = 1,800 px pixels down height = 90 / 0.2 × 3 = 1,350 px total = 1,800 × 1,350 ≈ 2.4 MP 1.6 MP sensor, 1440 × 1080 pixel size on part = 120 / 1,440 = 0.0833 mm/px pixels on defect = 0.2 / 0.0833 = 2.4 px short
Field note

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.

Fig. 02The same defect at 1, 3 and 4+ pixels
1 1 px · may vanish straddles two pixels, each at about half contrast 3 3 px · detection at least one pixel fully covered, extent and contrast survive 4+ 4+ px · gauging an edge edge falls inside a pixel; subpixel fit finds it (blue)
Three pixels buys you alignment insurance. A one-pixel defect usually splits across two pixels and loses half its contrast. At three pixels, one is always fully covered. For measurement the rule changes: an edge is sampled by several pixels across its blur, and the question becomes pixel size against tolerance, not pixels per feature.
Sensors

Choosing a sensor: pixel count, pixel size and format.

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.

Common industrial sensor formats · nominal specs
FormatPixelsPixel sizeActive areaNyquist on sensorShutterExample sensor
1.6 MP · 1/2.9″1440 × 10803.45 µm4.97 × 3.73 mm145 lp/mmGlobalSony IMX273
5.0 MP · 1/1.8″2448 × 20482.74 µm6.71 × 5.61 mm182 lp/mmGlobalSony IMX547
5.1 MP · 2/3″2448 × 20483.45 µm8.45 × 7.07 mm145 lp/mmGlobalSony IMX264
12.3 MP · 1.1″4096 × 30003.45 µm14.13 × 10.35 mm145 lp/mmGlobalSony IMX304
20 MP · 1″5472 × 36482.4 µm13.13 × 8.76 mm208 lp/mmRollingSony IMX183
24.5 MP · 1.2″5328 × 46082.74 µm14.60 × 12.63 mm182 lp/mmGlobalSony IMX530
26.2 MP · APS-H5120 × 51204.5 µm23.04 × 23.04 mm111 lp/mmGlobalonsemi 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.

Lens

Focal length from similar triangles.

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.

Fig. 03Similar triangles · FOV / WD = sensor / f
FOV camera body WD (part to lens) f sensor FOV / WD = sensor / f f ≈ WD × sensor ÷ FOV · thin lens: f = WD·m / (1 + m) WD here is to the lens principal plane
The simple version slightly overestimates f. Lens to sensor is really the image distance, which is a little longer than f. For small magnifications the difference is a few percent: at m = 0.07 the thin-lens answer is about 7% shorter. That's one reason to round down to the next stock focal length, which also widens the field slightly and gives you margin.
Worked example 2 · sensor and lens 5.1 MP 2/3″, 2448 × 2048 px at 3.45 µm, WD 400 mm sensor width = 2,448 × 0.00345 = 8.446 mm sensor height = 2,048 × 0.00345 = 7.066 mm m (width) = 8.446 / 120 = 0.0704 m (height) = 7.066 / 90 = 0.0785 m = smaller of the two = 0.0704 width limits mm/px = 0.00345 / 0.0704 = 0.0490 mm/px px on defect = 0.2 / 0.0490 = 4.08 px passes f ≈ 400 × 8.446 / 120 = 28.2 mm thin lens 400 × 0.0704 / 1.0704 = 26.3 mm stock 25 mm lens m = 25 / (400 − 25) = 0.0667 field = 8.446 / 0.0667 = 126.7 × 106.0 mm mm/px = 0.00345 / 0.0667 = 0.0518 mm/px px on defect = 0.2 / 0.0518 = 3.86 px still passes

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.

Depth of field

Depth of field, aperture and the diffraction ceiling.

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.

Fig. 04Depth of field vs aperture · not to scale
focus plane f/2.8 c blur limit short DOF f/11 iris stopped down about 4× the depth, softer edge DOF ≈ 2·N·c·(1 + m) / m² N = f-number · c = allowed blur on the sensor · m = magnification Airy disk ≈ 2.44 · λ · N: at 550 nm and f/8, about 10.7 µm, or three 3.45 µm pixels
Depth of field scales with f-number; so does diffraction blur. Going from f/2.8 to f/11 quadruples the depth of field, and also quadruples the size of the diffraction spot. Small pixels hit that ceiling first, which is why a 2.4 µm sensor can look softer than a 3.45 µm one behind the same lens at f/8.

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.

Worked example 3 · depth of field 25 mm lens at 400 mm, m = 0.0667, 3.45 µm pixels allowed blur c = 2 px = 0.0069 mm on the sensor f/8: DOF ≈ 2 × 8 × 0.0069 × 1.0667 / 0.0667² ≈ 0.1178 / 0.00445 ≈ 26 mm f/4: DOF ≈ half of that ≈ 13 mm diffraction check (λ = 550 nm) Airy f/4 = 2.44 × 0.00055 × 4 = 0.0054 mm ≈ 1.6 px Airy f/8 = 2.44 × 0.00055 × 8 = 0.0107 mm ≈ 3.1 px

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.

Motion

The motion blur budget.

If the part moves while the shutter is open, its edges smear. How far they smear, in pixels, is a one-line formula.

Fig. 05Exposure × speed vs pixel size
Part moving during the exposure v = 200 mm/s t = 0 t = 500 µs Recorded pixels · 0.05 mm each blur = 2 px intensity ideal: a sharp step recorded: a 2 px ramp position along the motion Blur budget blur (px) = v × t ÷ (mm/px) 200 mm/s × 500 µs = 0.10 mm = 2 px at 0.05 mm/px ½ px → t ≤ 125 µs use a strobe, not a long exposure
Blur is distance traveled during the exposure, counted in pixels. A 2 px smear turns a sharp edge into a ramp: a detection tool may still work, a gauge won't. Budget about half a pixel for measurement and one pixel for most inspection, and get the light from a strobe rather than a long exposure.

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.

Worked example 4 · exposure limit 25 mm lens setup above: 0.0518 mm/px conveyor at 300 mm/s, blur budget ½ px allowed travel = 0.5 × 0.0518 = 0.0259 mm t_max = 0.0259 / 300 = 0.0000863 s ≈ 86 µs same line, 2 ms exposure (common default) travel = 300 × 0.002 = 0.6 mm blur = 0.6 / 0.0518 ≈ 11.6 px

A default exposure from a stationary bench test can be more than twenty times too long for the line.

What goes wrong

Where the simple math stops being true.

The lens can't resolve the pixel

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.

Distortion at the edges

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.

Contrast, not resolution, is the bottleneck

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.

Too many pixels

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.

One camera for a field that wants two

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.

Field note

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.

Where Relling fits

We size the optics as part of the cell, not after it.

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 →
FAQ

Frequently asked questions.

How do I calculate the camera resolution I need for machine vision?

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.

How many pixels should cover the smallest defect?

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.

How do I calculate the focal length of a machine vision lens?

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.

What is the difference between camera resolution and spatial resolution?

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.

How do I avoid motion blur in machine vision?

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.

Does a higher megapixel camera always give better inspection?

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.

How do I get more depth of field in machine vision?

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.

Bring Relling to your shop floor.

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.