System designExplainer

Stable 2D vision inspection systems: lighting, lens, exposure first

Why a 2D vision inspection system drifts, and the numbers that hold it stable: illumination uniformity, field-edge contrast, exposure caps, threshold margins.

LumaSpec Vision12 min read Share on LinkedIn

On this page 9 sections
  1. 01The stability chain, in the order you fix it
  2. 02Illumination uniformity: hold the background to 10 grey levels
  3. 03Lens contrast at the field edge
  4. 04Lock the exposure, then freeze the motion
  5. 05Worked example: lot code on a 60 mm part moving at 150 mm/s
  6. 06What the usual answers get wrong
  7. 07Sign-off checklist for a stable 2D station
  8. 08Choosing parts and the next step
  9. 09Questions

An inspection that passed at commissioning and drifts two weeks later is rarely an algorithm problem. The grey values your thresholds act on are set upstream, by three things: how evenly the light covers the field, how much contrast the lens keeps at the corners, and how steadily the camera exposes. This guide walks that stability chain in the order to fix it, gives the numbers to hold at each stage — grey-level spread, corner contrast, exposure caps — and works one complete example from field of view to strobe timing, so you can qualify a 2D station before its first production shift.

The stability chain, in the order you fix it

A 2D inspection is repeatable when the same part yields the same grey values, shift after shift. Four stages decide that, and each can undo the ones below it, so diagnose from the top:

  1. Illumination sets the grey-level landscape. Uneven light moves the background level across the field, and a threshold tuned at the center fails parts that sit near the edges.
  2. Optics decide whether contrast survives to the corners. Lens resolution and contrast fall toward the edge of the image circle, and features near the field border meet that loss first.
  3. Exposure timing sets brightness and blur at once. Auto modes rebalance frame by frame, so background level and edge sharpness both wander with scene content.
  4. The threshold comes last. It can only separate what the first three stages delivered.

Hold the first three steady and one global threshold runs for months. Let any of them drift, and no amount of re-teaching holds a week.

Illumination uniformity: hold the background to 10 grey levels

Non-uniform illumination adds a spatially varying offset to the image, and a single threshold cannot absorb an offset that changes with position — which is why global thresholding degrades so fast under patchy light. The fix is geometric, not algorithmic: even source, right distance, right angle.

Put numbers on it. At the production exposure, image a matte white target that overfills the field, and compare grey levels (8-bit scale) at the center against the worst corner:

  • Background spread, center to worst corner: hold within 10 grey levels.
  • Shift-to-shift drift at fixed exposure: hold within 3 grey levels.

The drift target has a physical basis: sensor read noise sits around 2–4 grey levels at typical gain, so movement beyond that is the light, not the sensor.

The margin arithmetic shows why the spread target matters. Calibrate on a part whose background sits at 200 and whose dark feature sits 40 levels lower, at 160, and threshold at the midpoint, 180: 20 levels of margin on each side. Now let the light sag 20 levels at the field edge. The corner background lands on the threshold itself, and the same part segments one way in the center and another at the edge. With the spread held to 10 levels, the corner background keeps 10 levels of clearance and the feature 30 — tight but stable. That is the whole argument for the target.

Past roughly a 20-level spread, stop re-teaching the threshold and change the light: move it back, diffuse it, or wrap the part in a dome or cloudy-day source. Adaptive thresholding can mask shading afterward, but it also compensates silently as a lamp ages, so log the flat-target capture with the production images and alarm on a rising spread. The machine vision lighting stability test covers the bench checks, and closed-loop lighting control shows how to servo brightness back when LEDs warm up. For the setup sequence itself — geometry, angle, diffusion — a step-by-step vision lighting setup guide walks it end to end.

Lens contrast at the field edge

Lenses do not image the corner like the center. Resolution and contrast fall toward the edge of the image circle, and that edge contrast loss is the measurable signature of a lens nearing its limit. In a station it looks like features that read fine when the part sits centered, then vanish when the fixture lands it 5 mm outward.

Two habits keep the corner honest:

  • Rate the lens for the sensor. A 5 MP sensor wants a lens rated 5 MP or better in that format; an under-rated lens passes the center and smears the corners.
  • Test the corner. Image a straight edge at the field corner and compare its spread with the same edge at center. If corner contrast falls below about half of center, shrink the field of view or step up a lens grade — halving contrast halves the grey-level separation your threshold depends on.

The optics follow from the thin-lens relations, where WD is the working distance:

FOV = sensor width / magnification m = f / (WD − f) f = WD × m / (1 + m)

These approximations land within a few percent for fixed machine vision lenses. The same working-distance and field-of-view algebra is applied to a real part in the blister inspection working distance guide, and lens contrast and resolution explains how to read a contrast curve. Where pixel pitch and lens resolution disagree, the Nyquist limit marks where detail actually stops.

How sensor width, working distance and field of view set the focal length Rays from the edges of the sensor pass through the lens and spread to the edges of the field of view. The ratio of sensor width to field of view is the magnification m.CameraField of view (FOV)Working distance (WD)≈ fsensor width slensm = s / FOVf = WD × m / (1 + m)
How sensor width, working distance and field of view set the focal length. Rays from the edges of the sensor pass through the lens and spread to the edges of the field of view. The ratio of sensor width to field of view is the magnification m.

When the inspection measures instead of just passing or failing, magnification must also hold as the part moves in depth — the telecentric case. A fixed-magnification telecentric such as the LS-TCL-0574 is rated 0.4x on a 1.2" sensor with 227 mm of working distance and a C-mount. On a 4:3 sensor of that format, about 15 mm wide, that is an object field near 38 mm with the perspective error taken out of the measurement.

Machine vision lensesFixed-magnification lens, 0.4x, 227 mm WD, 1.2" (LS-TCL-0574)LS-TCL-0574
Sensor format
1.2"
Mount
C-mount
Image circle
16-22 mm
$2,269.00View partBuild a system with it

Lock the exposure, then freeze the motion

Auto exposure and auto gain are repeatability killers. They rebalance every frame against scene content, so a dark tray or a missing part shifts the background level, and yesterday's threshold sits in the wrong place. Set exposure, gain and iris to manual and leave them there. Brightness that drifts over time is the classic signature of an auto mode left on — see turn every auto mode off — and contour position jitter appears even when the part stands still. If an auto mode must stay on for startup, cap its maximum exposure time: capping auto exposure keeps blur out of the loop.

Motion sets the exposure budget. Keep blur under one pixel:

t_exp ≤ object pixel size / part speed

At 150 mm/s and 27 µm pixels that is about 180 µs — shorter than most continuous lights can fill at a usable aperture. The practical answer is to strobe. A strobe-capable digital controller such as the LS-CTL-0070 (4 channels, 200 W, RS232) fires the LEDs only during the camera exposure, so the flash reaches far above continuous brightness, motion freezes, and the LEDs run cool between parts.

Light controllersDigital control box, 4 ch, 200 W, RS232 (LS-CTL-0070)LS-CTL-0070
Output
Constant voltage 24 V
Channels
4 channels
Control
Digital
Feature
Strobe
$549.00View partBuild a system with it

Two timing traps sit next to that decision. Mains flicker: an unsynchronized exposure under mains-driven lighting picks up ripple at twice the line frequency, visible as bands that move with exposure time — the camera flicker diagnosis shows the pattern and the fixes. Ambient light: daylight through a dock door adds grey levels no recipe controls, so enclose the station or strobe past it, as laid out in ambient light variation control. And when the first frames of a run come back dark, the cause is usually exposure settling or trigger timing rather than the light — first camera frame dark separates the two.

Worked example: lot code on a 60 mm part moving at 150 mm/s

Inputs (a typical electronics line; substitute your station's numbers):

  • Part: 60 mm wide board with an inkjet lot code; narrowest character stroke 0.15 mm.
  • Placement: ±3 mm in the fixture, so the field carries 6 mm of margin — FOV 66 mm.
  • Camera: 5 MP, 2/3" class, 2448 × 2048 pixels; nominal 2/3" sensor width 8.8 mm; pixel pitch 8.8 mm ÷ 2448 = 3.6 µm.
  • Standoff: 300 mm working distance to clear the fixture.
  • Belt speed: 150 mm/s under the camera.
  • Light: white LED bar, strobed during the exposure.

Rules, in order: field from part plus placement margin; focal length from field and standoff; pixels against the feature, using the 3-pixel minimum from the pixel rule for defect detection; exposure from the blur budget; aperture from the diffraction budget.

Arithmetic:

  • Magnification: m = 8.8 ÷ 66 = 0.133
  • Focal length: f = 300 × 0.133 ÷ 1.133 = 35.2 mm → standard 35 mm
  • Check at 35 mm and 300 mm: m = 35 ÷ (300 − 35) = 0.132, FOV = 8.8 ÷ 0.132 = 66.6 mm ✓
  • Object pixel: 66.6 ÷ 2448 = 0.0272 mm (27 µm)
  • Feature: 0.15 ÷ 0.0272 = 5.5 pixels across the stroke, above the 3-pixel minimum ✓
  • Exposure cap: 0.0272 ÷ 150 = 181 µs → set 150–180 µs
  • Diffraction: Airy diameter = 2.44 × 0.55 µm × f-number → at f/4, 5.4 µm ≈ 1.5 px ✓; at f/8, 10.7 µm ≈ 3 px, which would soften a 5.5-pixel stroke
  • Depth of field at f/4, 2-pixel tolerance (c = 0.054 mm): DOF ≈ 2 × 4 × 0.054 ÷ 0.133² ≈ 24 mm, far beyond the fixture's ±1 mm

Decision: a 35 mm lens rated for a 2/3" sensor, working near 300 mm WD at f/4; exposure capped at 180 µs; light strobed during the exposure. If the image runs dark, open to f/2.8 before adding gain, and do not stretch exposure past the cap. The 35 mm, 2/3", 6 MP, C-mount class this lands on is the standard workhorse for fields of this size:

Machine vision lenses35 mm, 2/3", 6 MP, C-mount machine vision lens (LS-FFL-0679)LS-FFL-0679
Type
Machine vision fixed
Sensor format
2/3"
Mount
C-mount
Resolution
6-10 MP
$219.00View partBuild a system with it

Check the focal length for your own part and standoff with the calculator:

Lens focal length, field of view and working distance
Units
Solve for
Focal length
– mm
Field of view
– mm
Working distance
– mm
Magnification
– x
Angle of view
– °
Pixel on the part
– mm

Thin-lens model: m = sensor width / field of view, f = WD × m / (1 + m). Accurate to a few percent above about 150 mm; check the lens's minimum object distance.

Find lenses with this focal length Open the full calculator

What the usual answers get wrong

"Add resolution." Pixels do not steady grey values. More pixels over the same field means smaller pixels, each collecting less light, so gain rises and noise eats the margin you were protecting. Size pixels from the smallest feature, then stop.

"Leave auto exposure on for consistency." It is the opposite of consistency: auto modes renormalize every frame. Fix the exposure and the light instead.

"The algorithm can fix the lighting." Local and adaptive thresholding rescue genuinely shaded parts, and edge-based pattern matching holds results steady when light must vary — but adaptation also hides an aging lamp. Fix geometry first, adapt second, and log the difference. The glass bottle defect case tells the same story from the failure end: fix the light, and the threshold holds by itself.

"Indoors, ambient does not matter." A dock door or a work lamp adds tens of grey levels with the time of day. Enclose the station, strobe past ambient, or qualify at the brightest ambient the line will see.

"Retune the threshold when yield moves." That treats the symptom and erases the evidence. Trend the flat-target capture instead, and the drift shows up days before the yield does.

Sign-off checklist for a stable 2D station

Run these once the station is mounted, and again after any physical change:

  • Flat-target uniformity: center-to-worst-corner spread ≤ 10 grey levels.
  • Repeatability: 30 images of one static part, background mean drift ≤ 3 grey levels.
  • Corner contrast: straight-edge spread at the corner no worse than about half of center.
  • Feature size: smallest defect ≥ 3 pixels across; character stroke ≥ 5 pixels for OCR.
  • Blur: exposure ≤ pixel size ÷ speed, edges crisp under magnification.
  • Auto modes: exposure, gain, iris and white balance all fixed.
  • Flicker: no ripple bands at the production exposure time.
  • Threshold margin: feature ≥ 40 grey levels below background, threshold at the midpoint, worst-corner clearance ≥ 10 levels.
  • Logging: flat-target capture stored with every recipe change.

A station that passes all nine rarely needs re-teaching; when one line fails, work the stability chain from the top before touching software.

Choosing parts and the next step

None of this is exotic hardware: a global-shutter camera, a lens rated for the sensor with corner margin, a diffuse light, and a strobe-capable controller. For anything moving, prefer a global shutter — a rolling shutter reads rows in sequence and shears a moving part even at short exposure. The MV-CU020-90GC, for instance, is a 2.5 MP GigE camera with a global shutter, 1/1.7" sensor and C-mount.

Area scan camerasHikrobot MV-CU020-90GC 2.5 MP Area Scan Camera, GigE, GMAX4002, ColorMV-CU020-90GC
Sensor format
1/1.7"
Lens mount
C-mount
Interface
GigE
Resolution
Up to 3 MP
$309.00View partBuild a system with it

Browse the area scan cameras with the camera finder, the lenses with the lens finder, and the light controllers with the controller finder. The system configurator steps through camera, lens and light against your part, and a vision inspection system selection guide covers the specification questions for a production line. To go deeper on the numbers, the object-space pixel size calculation extends the magnification math, and the systems topic page collects the rest of this chain. If you want the chain reviewed against your own part, send the drawing through the contact page.

Questions

How do I measure illumination uniformity quickly?

Run the station at its production exposure and image a matte white ceramic target that overfills the field of view. Read the mean grey level in five boxes: center and the four image corners. Subtract the darkest corner from the brightest: at or under 10 grey levels the illumination passes; over 20, fix the light geometry before touching thresholds. Save the capture, because comparing it to next month's capture is your aging alarm.

What exposure time stops motion blur on a 300 mm/s line?

Divide the object-space pixel size by the speed. With 27 µm pixels — a 66 mm field over a 2448-pixel sensor — 300 mm/s needs exposure at or under 90 µs; at 150 mm/s the same line allows 180 µs. If the light cannot fill the shorter exposure at your aperture, strobe during the exposure rather than raising gain, because gain lifts noise into the threshold margin.

Does a 12 MP camera make inspection more repeatable than a 5 MP?

No. Repeatability comes from illumination, lens contrast and exposure timing; more pixels only resolve smaller features. Oversampling also costs light: a pixel half the size collects about a quarter of the photons, so gain rises and noise eats the same threshold margin you were protecting. Choose resolution from the smallest feature — three pixels across it — then spend the effort on lighting and timing.

Global or local thresholding for uneven lighting?

Fix the light first: uniform illumination keeps a global threshold valid, which is the cheapest and most diagnosable state. Local and adaptive methods rescue genuinely shaded parts — curved, wrinkled or back-lit edges — but they also compensate silently as a lamp ages or shifts, so a marginal station keeps passing while its margin erodes. If you must adapt, log the flat-target capture with every recipe and alarm on spread over 10 grey levels.

Strobe or continuous light for a stable image?

For moving parts, strobe: it freezes motion at exposure times below a few hundred microseconds and lets the LEDs pulse far above their continuous rating during the flash. Continuous light suits static stations, where its lower peak brightness is enough and the wiring is simpler. Either way, drive the light from the same trigger as the camera so brightness cannot vary frame to frame.

How often should a stable station be re-qualified?

Ten minutes per shift is enough: the flat-target uniformity capture and a golden-part run against the current recipe. Do a full re-qualification — light geometry, corner contrast, exposure cap — whenever a lamp is replaced, the camera or light is remounted, or first-pass yield moves without a known cause. LED output drifts gradually over thousands of hours, so trend the numbers rather than trusting a single passing check.