Vision Systems & Engineering
Lighting for Machine Vision
How the geometry, pattern, wavelength and filtering of the light decide which features of a part have contrast in an inspection image, from the law of reflection behind bright field and dark field to domes, coaxial light, colour, pass filters, polarizers and collimation, with an exact rendering of four defects under six lighting geometries.
intermediate
Lighting for machine vision is the design of the illumination of an inspection or measurement station so that the features to be judged stand out from their surroundings in the image, and keep standing out when parts, positions and the room’s light vary. On a production line the scene can be lit on purpose, and the choice of light can decide whether a feature is in the image at all: a scratch on a polished part can be black, white or invisible depending only on where the light comes from.
Industrial visual inspection gives the catalogue of lighting geometries (bright field, dark field, back light, coaxial, dome) and telecentric lenses; industrial machine vision treats strobing, triggering and fixed lighting recipes as system decisions; vision system design places lighting among the design stages. This article covers why the geometries work, from the law of reflection and the shape of a surface’s reflectance, and the other levers a lighting engineer has: the pattern of the light, its wavelength, filters against ambient light, polarizers and collimation. Most of the practice is described from one lighting maker’s guide, Advanced Illumination’s A Practical Guide to Machine Vision Lighting (as of November 2026; called “the guide” below), and is attributed to it. The example renders a glossy plate with four kinds of defect exactly under six geometries and measures each defect’s contrast.
Angles in this article are measured from the surface normal unless they are said to be measured from the surface. The guide measures “low angle” light from the surface, so light it calls low-angle, under 45° from the surface, is more than 45° from the normal.
Purpose
The guide states the aim of lighting analysis as feature-appropriate lighting that meets two acceptance criteria consistently: to “maximize the contrast on those features of interest vs. their background” and to provide robustness. Its example of a cellophane-wrapped pack shows a set-up that meets the first criterion only: the barcode reads, but a wrinkle in another place on the next pack could stop it. Robustness means that the contrast survives the variation in part size, shape, orientation and placement and in ambient light that the line will produce.
The guide opens by suggesting that perhaps no other part of vision system design has caused more delay, cost overruns and trouble than lighting, which was historically often the last part specified. Its closing advice runs the other way: where the inspection and part handling are designed from scratch, get the lighting solution in place first and build the rest around it.
When to Use It
Designed lighting applies wherever the scene can be enclosed or at least dominated by the system’s own light: inspection, gauging, code reading and guidance on production lines, laboratory imaging and fixed test stations. It matters most where the part’s surface is shiny, curved or textured. The guide’s application-field diagram plots surface reflectivity (matte, mirror, mixed) against flatness and texture; relatively flat, diffuse parts fall in a “geometry independent” region where any technique that gives enough contrast may work, and away from that region the guide calls for more specialized geometries and structured lighting.
It does not apply, or applies only partly, where the scene cannot be lit: streets, fields, sky and much consumer imaging. There the range of natural light becomes a requirement on the data and the tests (vision system design). Lighting variation as a nuisance that models must tolerate, relighting in rendering, and illumination estimation for colour constancy are different subjects.
How It Works
Light leaves a surface in two ways
A surface reflects part of the light diffusely, nearly equally in all directions, and part specularly, in a lobe around the mirror direction. Reflectance models describe both with the bidirectional reflectance distribution function: a Lambertian term for the diffuse part, and for the specular part a microfacet model whose lobe width is set by a roughness, such as GGX with its distribution of normals , masking term and Fresnel term (Walter et al., 2007, as Reflectance Models states them). The guide makes the same distinction in words: on a specular surface the angle of reflection equals the angle of incidence, while a diffuse surface scatters.
For a mirror-like surface, the law of reflection fixes which light reaches the camera. With the camera on the surface normal, light arriving at angle from the normal is mirrored to on the other side, away from the lens; a facet tilted by towards the light turns the mirror direction by , so it sends that light into the lens when (our derivation; the example’s check C4 confirms it for its BRDF). A camera collects the light that leaves the surface within the cone its lens accepts, so on a glossy surface the image is dominated by whatever the lens sees mirrored in the surface: the light source, or the dark surroundings.
Bright field and dark field
The guide explains the two techniques with its “W” diagram, which draws the angles of incidence of bright-field and dark-field lights and shows a scratch on a flat field standing out under dark field. In bright field, the light’s mirror reflection from the flat surface enters the lens, so the surface looks bright and features that tilt the surface send the light elsewhere and look darker. In dark field, the light arrives at a low angle, its mirror reflection from the flat surface misses the lens and the surface looks dark; the guide explains that the small amount of light reaching the camera is scattered or reflected by edges of small features that happen to satisfy the law of reflection, so they appear bright on a dark background. Its examples are a mirror whose scratch shows under a dark-field ring but not under a bright-field one, a sealed bag whose seam and contents show under dark field, and a dot-peened 2-D code that a low-angle linear dark-field light images more effectively than a bright-field ring light.
The guide also separates system geometry, the spatial arrangement of camera, light and part, from light-ray geometry, what the rays do at the surface. Its geometry article (3 September 2026) gives the example that ring, dome, flat diffuse and true coaxial lights are all centred on the camera’s optical axis, an on-axis system geometry, while only true coaxial light, sent down the lens axis by a beam splitter, travels along the axis; a ring light’s rays reach the part at an angle that depends on the ring’s diameter, its optics and the working distance. The guide’s example is a camera and light kept coaxial but tilted together away from the surface normal, which mitigates specular reflection but gives a perspective view, suited to presence or absence rather than measurement; keeping the camera perpendicular and moving only the light off-axis mitigates the glare without the perspective shift.
The four cornerstones
The guide organizes the levers into four “cornerstones of image contrast”:
- Geometry: the spatial relationship among object, light and camera.
- Structure or pattern: the shape of the light projected onto the object, which mostly follows from the type of light head.
- Wavelength or colour: how differently the object and its background reflect or absorb the light.
- Filters: blocking and passing wavelengths or light directions differentially.
It gives no fixed order of investigation, but states that geometry and structure matter more for specular surfaces, wavelength and filtering more for colour and transparency, and that one application can need several, or all, of them.
Wavelength and colour
Materials reflect and absorb wavelengths differently, and a monochrome camera can turn this into contrast. The guide’s rule, from a colour wheel: light of the same colour as a surface brightens it, light of the opposite colour darkens it, and opposite colours on the wheel give the largest difference, so green light darkens a red feature more than blue light does; white light contrasts all colours but may be a compromise. Its examples include a red stamp imaged under red, green, blue and white light, and coloured sweets sorted by a monochrome camera under different coloured lights.
Outside the visible range, the guide reports that infrared light evens out colour differences, because its reflection depends more on composition and texture than on visible colour (black print on crayons of every colour reads under 850 nm), and that it penetrates polymers better than shorter wavelengths such as UV or blue, and in some cases red; a deep blue bottle in its back-lit fill-level example did not transmit blue light preferentially, which the guide attributes to the glass’s composition rather than its colour. Short wavelengths penetrate less, which the guide uses for shallow surface features such as laser etching on a gear face under blue 470 nm light. Ultraviolet light makes some inks, dyes and materials fluoresce at a longer wavelength, which the guide uses for hidden security marks and for checking nylon inserts in nuts. A camera’s spectral sensitivity bounds all of this: the guide recommends matching the light’s peak wavelength to the sensor’s peak quantum efficiency in light-starved applications. Colorimetry and the image sensor article cover colour and spectral response.
Filters and ambient light
Ambient light from overhead lamps, sunlight, workstation lamps or a neighbouring station’s lights (the guide’s “friendly fire”) adds a varying amount to every image. The guide lists three practical counter-measures: high-power strobing with short pulses that swamps the ambient contribution (the system side is in industrial machine vision), physical enclosures, and pass filters on the lens: long-pass, short-pass or band-pass. A red 660 nm band-pass filter on the lens, matched to a red 660 nm light, blocks much of the light from overhead fluorescent or mercury lamps; for fluorescence, the filter is chosen to pass the emission wavelength and block both the exciting ultraviolet and the ambient light, as in the guide’s nylon-insert example with a 510 nm short-pass filter. Turning the ambient light off is rarely practical, and against sunlight the guide recommends an opaque housing. Narrow filters do not suit colour cameras, which need the full white spectrum, so there the enclosure is the remaining option. Glare from the station’s own light is not ambient light in the guide’s terms: it is treated with geometry or polarization.
How bright a light is on the part is an irradiance, in watts per square metre at the working distance, and it falls with the square of the distance from a small source (the inverse-square law, which Radiometry and Photometry derives). The guide warns against comparing lights by source power alone, or comparing monochromatic and white lights in photometric units weighted by human vision, which rate infrared and ultraviolet as zero; it recommends comparing irradiance at the same working distance and taking the camera’s quantum efficiency into account.
Polarization
A linear polarizer on the light and a second one, the analyzer, on the lens can block specular glare. In the idealized case (our derivation), light mirrored once by a smooth surface keeps the polarization the polarizer gave it, so an analyzer crossed with the polarizer blocks it, while light scattered diffusely inside a material is depolarized and the analyzer passes half of it. The guide gives the law that governs the pair, Malus’s law,
where is the angle between the polarizer’s polarization axis and the analyzer’s transmission axis, and notes that polarized light has half the intensity of the unpolarized light that entered the first polarizer. A crossed pair therefore costs a large share of the light: in our idealization a quarter of the diffuse light reaches the sensor (a half at each filter), and in the guide’s own glare example the lens had to be opened by 2½ f-stops to keep the scene’s brightness. Light that is already partly polarized by reflection, such as glare from a road or a lake, can be reduced with an analyzer alone, but the guide notes that such polarization by reflection is not complete, and that metals reflect most of the incident light, so for them the station’s own light is polarized first and its reflection blocked with the analyzer.
The guide’s limits on polarization come from its examples. On a curved bottle, crossed polarizers reduced but did not remove the glare, which the guide attributes to the many reflection directions on a curved surface; moving the light off-axis removed it. Its conclusion is to try a change of geometry before polarizers. Polarizers also show stress in transparent, birefringent plastics: between a polarizer pair and a back light, stressed regions appear as dark and light bands.
Collimation
Collimated back light has rays nearly parallel to the optical axis. The guide describes collimation film (a polymer sheet with a grating of parallel prisms, 50 µm pitch with 90° faces in its illustration; two crossed sheets for collimation in both directions), which passes and concentrates near-vertical rays and recycles others by internal reflection; its maker calls it brightness enhancement film. In back lighting it sharpens the image of a part’s edge along its true maximum projection, which suits high-accuracy gauging. It is not a perfect collimator: the guide reports a window of roughly ±25–30° of off-axis light still visible to a camera with an ordinary lens, whereas a lensed collimator viewed through a telecentric lens goes dark a few degrees off-axis. The guide also recommends monochrome light with collimation film for precise back-lit edges, and notes that shorter wavelengths such as blue diffract slightly less than red, while the wavelengths in white light diffract by different amounts.
How to Apply It
The guide ends with a “sequence of lighting analysis”, a checklist that it says is not comprehensive. In outline:
- Inspection environment. The working volume and access for camera, lens and light; minimum and maximum working distance and field of view; whether the part is stationary, moving or indexed, with speeds, cycle time and strobing parameters; vibration; how consistently the part is presented; ambient light; operators and safety near intense or strobed light.
- Object–light interactions. Surface reflectivity (diffuse, specular, mixed), overall shape (flat, curved), texture and topography; composition and colour, part colour against background, transparency (including in the infrared) and fluorescence; light contamination from the room, other stations or the station itself.
- The features of interest. What exactly the inspection must decide.
- The four cornerstones. Geometry, pattern, colour differences and filters (pass filters, polarization, collimation or extra diffusion).
- Light types and techniques. The source (LED, fluorescent, quartz-halogen and others), the technique (bright field, dark field, diffuse, back light) and the camera’s spectral response.
The guide adds that such an analysis often ends in conflicting conclusions and compromises, for example dark field indicated by the part but a remote light forced by the environment, and that bench analysis is often no substitute for testing two or three light types in the production environment. Its own example makes the point: for laser-etched codes at the bottom of small wells, high-angle and coaxial lights failed, a low-angle ring worked but showed a crescent shadow from the well walls, the dome gave even light but little code contrast, and a flat diffuse light worked best; the guide’s author reports having expected the dome to win.
Example: four defects under six geometries
The script renders an orthographic camera looking straight down at a flat 256 × 256 plate, with every source at infinity and scaled so that it gives irradiance 1 on the flat plate. The plate is Lambertian with albedo 0.2 plus a GGX specular lobe (, Fresnel term for a dielectric of index 1.5), written from the equations of Walter et al. (2007) as Reflectance Models gives them. It carries four defects with exact masks:
- a scratch, a straight V-groove 8 pixels wide with walls tilted ±20°, with cast shadows from the groove’s rim and no interreflections; its walls are rendered polished (as the plate) and rough (), because the finish is an open choice;
- a bump, a shallow spherical cap whose tilt reaches 5° at its rim;
- a printed mark that changes only the diffuse albedo (0.05, a dark ink);
- a dust spot, Lambertian with albedo 0.4 and no specular term.
The six geometries, with angles from the normal: COAX, a small on-axis source within 3°; BF30, a partial bright-field ring at 28–32°; DF80, a dark-field ring at 78–82° (8–12° above the surface); DOME8, a uniform hemisphere minus a camera port of half-angle 8°; DOME0, the hemisphere with the port filled (an idealization; the port size is an open choice); and XPOL, the coaxial light with idealized crossed polarizers, in which the specular part is removed and the diffuse part multiplied by 1/4 (our derivation above; the batch plan had “diffuse halved”, which we corrected, taking the half at the polarizer from the guide). Each source is integrated by the midpoint rule over its directions (0.1° by 0.5°). The script prints each defect’s Weber contrast against the plate more than 6 pixels from any defect, the background radiance split into diffuse and specular parts, and a hotspot count, the number of pixels whose specular part exceeds their diffuse part.
The hypotheses, from the batch plan, were fixed with numerical bars in a file saved at 09:03:17 on 14 November 2026, before any script for this article existed; “visible” means , our choice. (H1) The scratch is dark on bright under COAX (, H1a) and bright on dark under DF80 (, H1b), with a brighter background under COAX than under DF80 (H1c), for both wall finishes. (H2) The mark is visible under both domes (H2a) and under COAX (H2b), and weaker under DF80 than under DOME8 and COAX (H2c). (H3) Each dome gives the bump a smaller than COAX (H3a) and than BF30 and DF80 (H3b). (H4) XPOL has no hotspot pixels while COAX has some (H4a), and the mark’s under XPOL is at least that under COAX (H4b). Six checks verify the code: the masks and normals (C1); the quadrature against the closed-form irradiance on a facet tilted by under a uniform hemisphere of unit radiance (C2); the normalization of the GGX distribution, , and at normal incidence (C3); the law of reflection, a light at 80° being mirrored into the camera by a facet tilted 40° (C4); the groove’s shadow test against an independent sampled ray (C5); and each source’s solid angle and normalized irradiance (C6). Against the batch plan’s description of this example, we added the rough walls, DOME0, the groove’s cast shadows and the six checks, corrected the cross-polarized diffuse factor, defined the source normalization, the hotspot count and the bars, and chose every numerical value of the scene. The tolerances of C2 (), C3’s normalization () and C6’s solid angle () were set after a planning script had printed the reachable values. That script also printed the radiance of single facets under each source, which pointed to the outcomes of H1a, H1c, H2b, H2c, H3a and H3b for DOME8 before the pilot ran, so those outcomes illustrate the rendering rather than test it. H4a’s XPOL part holds by construction, because the script sets the specular term to zero, so it is not a test.
import os
os.environ["OPENBLAS_NUM_THREADS"] = os.environ["OMP_NUM_THREADS"] = "1"
import numpy as np
from scipy import ndimage
# Conventions: plate in z = 0 with normal +z; orthographic camera on the normal, o = (0, 0, 1).
# Angles theta are measured FROM THE NORMAL (80 deg from the normal = 10 deg above the surface).
# Sources are at infinity with uniform radiance over their directions, scaled to irradiance 1 on the
# flat plate. Radiance values are linear; BRDFs in 1/sr.
D2R, O, N = np.pi/180, np.array([0.0, 0.0, 1.0]), 256
def directions(t1, t2, dt=0.1, dp=0.5):
"""Midpoint grid, theta in [t1, t2] deg, phi in [0, 180) deg; weights doubled for the mirror half.
Every normal below lies in the x-z plane, so the scene is symmetric under phi -> -phi."""
nt, npp = int(round((t2 - t1)/dt)), int(round(180/dp))
T, P = np.meshgrid((t1 + (np.arange(nt) + 0.5)*dt)*D2R, (np.arange(npp) + 0.5)*dp*D2R, indexing="ij")
w = 2*np.sin(T)*dt*D2R*dp*D2R
i = np.stack([np.sin(T)*np.cos(P), np.sin(T)*np.sin(P), np.cos(T)], -1).reshape(-1, 3)
return i, w.ravel()
def fresnel(c, eta=1.5): # Walter et al. (2007) Eq. 22, unpolarized, c = |i.h|
g = np.sqrt(eta*eta - 1 + c*c)
return 0.5*(g - c)**2/(g + c)**2*(1 + (c*(g + c) - 1)**2/(c*(g - c) + 1)**2)
def D_ggx(cm, a): # Eq. 33, cm = h.n > 0
t2 = (1 - cm*cm)/(cm*cm)
return a*a/(np.pi*cm**4*(a*a + t2)**2)
def G1(cv, vm, a): # Eq. 34 (Smith), cv = v.n > 0, vm = v.h
t2 = np.maximum(0.0, 1 - cv*cv)/(cv*cv)
return np.where(vm > 0, 2.0/(1 + np.sqrt(1 + a*a*t2)), 0.0)
def shade(n, i, wL, rho, a, vis=1.0):
"""Radiance towards the camera of a facet with normal n: (diffuse, specular) parts.
wL = quadrature weight x source radiance; vis = 0/1 cast-shadow mask (or its average)."""
ci = i @ n
k = wL*np.maximum(ci, 0)*vis
diff = rho/np.pi*k.sum()
if a is None or not (ci > 0).any():
return diff, 0.0
m = ci > 0
h = i[m] + O; h /= np.linalg.norm(h, axis=1, keepdims=True)
ch, co = h @ n, O @ n
fs = np.where(ch > 0, fresnel(np.abs(h @ O))*G1(ci[m], (i[m]*h).sum(1), a)*G1(co, h @ O, a)
*D_ggx(np.clip(ch, 1e-12, 1), a)/(4*ci[m]*co), 0.0)
return diff, (fs*k[m]).sum()
# ---- Scene: masks, normals and materials (exact by construction) ----
rr, cc = np.mgrid[0:N, 0:N] + 0.5 # pixel centres
BETA, W = 20.0, 8.0 # groove wall tilt (deg) and width (px)
groove = (cc > 60) & (cc < 68) & (rr > 32) & (rr < 224)
rad = np.hypot(rr - 64, cc - 176); RB, TB = 20.0, 5.0 # bump footprint radius, rim tilt (deg)
bump = rad < RB
bump_tilt = np.degrees(np.arcsin(np.clip(rad/(RB/np.sin(TB*D2R)), 0, 1)))
mark = (rr > 116) & (rr < 140) & (cc > 164) & (cc < 188)
dust = np.hypot(rr - 192, cc - 176) < 4
masks = {"scratch": groove, "bump": bump, "mark": mark, "dust": dust}
anyd = groove | bump | mark | dust
background = ndimage.distance_transform_edt(~anyd) > 6
PLATE, INK, DUST, ROUGH = (0.2, 0.05), (0.05, 0.05), (0.4, None), (0.2, 0.3) # (diffuse albedo, alpha_g)
def tilted(b): # unit normal tilted b deg towards -x
return np.array([-np.sin(b*D2R), 0.0, np.cos(b*D2R)])
def groove_point(x): # x in (-4, 4) across the groove: height, normal
H = W/2*np.tan(BETA*D2R)
return abs(x)*np.tan(BETA*D2R) - H, tilted(BETA if x > 0 else -BETA)
def in_shadow(x, i): # light blocked by the groove's opposite rim?
z, _ = groove_point(x)
with np.errstate(divide="ignore", invalid="ignore"):
xr = np.where(i[:, 0] < 0, -W/2, W/2)
t = (xr - x)/i[:, 0]
return (i[:, 0] != 0) & (z + t*i[:, 2] < 0)
def ray_march(x, d, k=20001): # independent check of in_shadow: sample the ray
z, _ = groove_point(x) # until it leaves the groove or rises above z = 0
t_end = min((np.sign(d[0])*W/2 - x)/d[0] if d[0] != 0 else np.inf, -z/d[2] if d[2] > 0 else np.inf)
t = np.linspace(0, t_end, k)[1:]
X, Z = x + t*d[0], z + t*d[2]
zs = np.abs(X)*np.tan(BETA*D2R) - W/2*np.tan(BETA*D2R)
return bool(((Z < zs - 1e-9) & (np.abs(X) <= W/2)).any())
SOURCES = {"COAX": (0, 3), "BF30": (28, 32), "DF80": (78, 82), "DOME8": (8, 90), "DOME0": (0, 90)}
SUB = (np.arange(8) + 0.5)/8 # 8 sub-positions per groove pixel
cols = np.arange(60, 68)
tilts_u = np.unique(bump_tilt[bump])
def render(i, w):
wL = w/(w*i[:, 2]).sum() # irradiance 1 on the flat plate
img = {}
flat = {m: shade(O, i, wL, *mat) for m, mat in [("plate", PLATE), ("ink", INK), ("dust", DUST)]}
lut = np.array([shade(tilted(t), i, wL, *PLATE) for t in tilts_u]) # bump: by tilt (sources are
for k, part in enumerate(("diff", "spec")): # symmetric about the normal)
a = np.full((N, N), flat["plate"][k])
a[mark] = flat["ink"][k]; a[dust] = flat["dust"][k]
a[bump] = lut[np.searchsorted(tilts_u, bump_tilt[bump]), k]
img[part] = a
for name, mat in [("polished", PLATE), ("rough", ROUGH)]:
gd, gs = img["diff"].copy(), img["spec"].copy()
for c in cols:
vals = []
for s in SUB:
x = c + s - 64
_, n = groove_point(x)
vals.append(shade(n, i, wL, *mat, vis=~in_shadow(x, i)))
d, s_ = np.mean(vals, axis=0)
gd[groove & (cc == c + 0.5)], gs[groove & (cc == c + 0.5)] = d, s_
img[name] = (gd, gs)
return img
def contrast(total, m):
bg = total[background].mean()
return (total[m].mean() - bg)/bg
# ---- Checks ----
print("== Checks")
cnt = {k: int(v.sum()) for k, v in masks.items()}
disjoint = sum(cnt.values()) == int(anyd.sum())
gn = [groove_point(x)[1] for x in (-1.0, 1.0)]
print("C1 mask pixels", cnt, "background", int(background.sum()), "disjoint", disjoint)
print("C1 groove wall tilts %.12f %.12f deg; bump max tilt %.6f deg; max |norm-1| %.1e" % (
np.degrees(np.arccos(gn[0][2])), np.degrees(np.arccos(gn[1][2])), bump_tilt[bump].max(),
max(abs(np.linalg.norm(tilted(t)) - 1) for t in list(tilts_u) + [BETA])))
ih, wh = directions(0, 90)
print("C2 tilted facet, full hemisphere L=1, rel err vs pi(1+cos b)/2, b = 0, 5, 20 deg:",
" ".join("%.2e" % ((np.maximum(0, ih @ tilted(b))*wh).sum()/(np.pi*(1 + np.cos(b*D2R))/2) - 1)
for b in (0, 5, 20)), "(bar 1e-6)")
print("C3 int D cos dw - 1: alpha 0.05 %.3e, alpha 0.30 %.3e (bar 2e-4); F(0) - 0.04 = %.1e (bar 1e-12)" % (
(D_ggx(ih[:, 2], 0.05)*ih[:, 2]*wh).sum() - 1, (D_ggx(ih[:, 2], 0.3)*ih[:, 2]*wh).sum() - 1, fresnel(1.0) - 0.04))
bs = np.arange(0, 90, 0.01)
l80 = np.array([-np.sin(80*D2R), 0.0, np.cos(80*D2R)])
fsb = [shade(tilted(b), l80[None], np.ones(1), 0.0, 0.05)[1]/max(l80 @ tilted(b), 1e-300) for b in bs]
print("C4 light at 80 deg, camera on the normal: specular BRDF peaks at facet tilt %.2f deg (expected 40.00)" %
bs[int(np.argmax(fsb))])
rng = np.random.default_rng(0)
dis, used = 0, 0
for _ in range(2000):
x = rng.uniform(-3.99, 3.99)
u, p = rng.random(), 2*np.pi*rng.random()
d = np.array([np.sqrt(1 - u*u)*np.cos(p), np.sqrt(1 - u*u)*np.sin(p), u])
z, n = groove_point(x)
xr = -W/2 if d[0] < 0 else W/2
if d @ n <= 0 or d[0] == 0 or abs(z + (xr - x)/d[0]*d[2]) < 1e-6:
continue
used += 1
dis += bool(in_shadow(x, d[None])[0]) != ray_march(x, d)
print("C5 groove shadow test vs ray march: %d disagreements in %d lit cases (bar 0)" % (dis, used))
geo = {}
for s, (t1, t2) in SOURCES.items():
i, w = directions(t1, t2)
wL = w/(w*i[:, 2]).sum()
print("C6 %-5s %6d directions, solid angle rel err %.2e (bar 1e-6), E - 1 = %.1e (bar 1e-12)" % (
s, len(w), w.sum()/(2*np.pi*(np.cos(t1*D2R) - np.cos(t2*D2R))) - 1, (wL*i[:, 2]).sum() - 1))
geo[s] = render(i, w)
c = geo["COAX"] # idealized crossed polarizers on the coaxial light
geo["XPOL"] = {"diff": c["diff"]/4, "spec": 0*c["spec"],
"polished": (c["polished"][0]/4, 0*c["polished"][1]), "rough": (c["rough"][0]/4, 0*c["rough"][1])}
# ---- Measures ----
print("\n== Background radiance (irradiance 1) and Weber contrast of each defect")
print("geometry bg total bg diff bg spec | scratch(pol) scratch(rgh) bump mark dust | hotspot px (pol, rgh)")
C, HOT, BG = {}, {}, {}
for g, im in geo.items():
tot = im["diff"] + im["spec"]
BG[g] = tot[background].mean()
C[g] = {"scratch_pol": contrast(sum(im["polished"]), groove), "scratch_rgh": contrast(sum(im["rough"]), groove)}
for k in ("bump", "mark", "dust"):
C[g][k] = contrast(tot, masks[k])
HOT[g] = [int((im[v][1] > im[v][0]).sum()) for v in ("polished", "rough")]
print("%-7s %9.5f %9.5f %9.5f | %+11.5f %+11.5f %+10.5f %+10.5f %+10.5f | %5d %5d (of %d)" % (
g, BG[g], im["diff"][background].mean(), im["spec"][background].mean(), C[g]["scratch_pol"],
C[g]["scratch_rgh"], C[g]["bump"], C[g]["mark"], C[g]["dust"], HOT[g][0], HOT[g][1], N*N))
print("\n== Hypotheses (visible: |C| >= 0.1)")
A = lambda g, k: abs(C[g][k])
for v in ("pol", "rgh"):
print("H1a scratch(%s) COAX C = %+.5f <= -0.1: %s" % (v, C["COAX"]["scratch_" + v], C["COAX"]["scratch_" + v] <= -0.1))
print("H1b scratch(%s) DF80 C = %+.5f >= +0.1: %s" % (v, C["DF80"]["scratch_" + v], C["DF80"]["scratch_" + v] >= 0.1))
print("H1c background COAX %.5f > DF80 %.5f: %s" % (BG["COAX"], BG["DF80"], BG["COAX"] > BG["DF80"]))
print("H2a |C mark| DOME8 %.5f, DOME0 %.5f >= 0.1: %s" % (A("DOME8", "mark"), A("DOME0", "mark"),
A("DOME8", "mark") >= 0.1 and A("DOME0", "mark") >= 0.1))
print("H2b |C mark| COAX %.5f >= 0.1: %s" % (A("COAX", "mark"), A("COAX", "mark") >= 0.1))
print("H2c |C mark| DF80 %.5f < min(DOME8, COAX) %.5f: %s" % (A("DF80", "mark"), min(A("DOME8", "mark"), A("COAX", "mark")),
A("DF80", "mark") < min(A("DOME8", "mark"), A("COAX", "mark"))))
for d in ("DOME8", "DOME0"):
print("H3a |C bump| %s %.5f < COAX %.5f: %s" % (d, A(d, "bump"), A("COAX", "bump"), A(d, "bump") < A("COAX", "bump")))
print("H3b |C bump| %s %.5f < BF30 %.5f and < DF80 %.5f: %s" % (d, A(d, "bump"), A("BF30", "bump"), A("DF80", "bump"),
A(d, "bump") < min(A("BF30", "bump"), A("DF80", "bump"))))
print("H4a hotspot px XPOL %s = 0 and COAX %s > 0: %s" % (HOT["XPOL"], HOT["COAX"],
max(HOT["XPOL"]) == 0 and min(HOT["COAX"]) > 0))
print("H4b |C mark| XPOL %.5f >= COAX %.5f: %s" % (A("XPOL", "mark"), A("COAX", "mark"), A("XPOL", "mark") >= A("COAX", "mark")))
== Checks
C1 mask pixels {'scratch': 1536, 'bump': 1264, 'mark': 576, 'dust': 52} background 57868 disjoint True
C1 groove wall tilts 20.000000000000 20.000000000000 deg; bump max tilt 4.990592 deg; max |norm-1| 1.1e-16
C2 tilted facet, full hemisphere L=1, rel err vs pi(1+cos b)/2, b = 0, 5, 20 deg: 5.08e-07 3.86e-07 3.62e-07 (bar 1e-6)
C3 int D cos dw - 1: alpha 0.05 1.016e-04, alpha 0.30 2.843e-06 (bar 2e-4); F(0) - 0.04 = 0.0e+00 (bar 1e-12)
C4 light at 80 deg, camera on the normal: specular BRDF peaks at facet tilt 40.00 deg (expected 40.00)
C5 groove shadow test vs ray march: 0 disagreements in 1761 lit cases (bar 0)
C6 COAX 10800 directions, solid angle rel err 1.27e-07 (bar 1e-6), E - 1 = 0.0e+00 (bar 1e-12)
C6 BF30 14400 directions, solid angle rel err 1.27e-07 (bar 1e-6), E - 1 = 2.2e-16 (bar 1e-12)
C6 DF80 14400 directions, solid angle rel err 1.27e-07 (bar 1e-6), E - 1 = 0.0e+00 (bar 1e-12)
C6 DOME8 295200 directions, solid angle rel err 1.27e-07 (bar 1e-6), E - 1 = -1.1e-16 (bar 1e-12)
C6 DOME0 324000 directions, solid angle rel err 1.27e-07 (bar 1e-6), E - 1 = 0.0e+00 (bar 1e-12)
== Background radiance (irradiance 1) and Weber contrast of each defect
geometry bg total bg diff bg spec | scratch(pol) scratch(rgh) bump mark dust | hotspot px (pol, rgh)
COAX 1.06432 0.06366 1.00066 | -0.94323 -0.93640 -0.64937 -0.04486 -0.88037 | 63948 63948 (of 65536)
BF30 0.06559 0.06366 0.00193 | +0.04446 +0.08391 +0.00513 -0.72790 +0.94107 | 0 0 (of 65536)
DF80 0.06396 0.06366 0.00030 | -0.05566 +0.07809 -0.00178 -0.74649 +0.99064 | 0 0 (of 65536)
DOME8 0.06803 0.06366 0.00437 | +0.07061 +0.03825 +0.04694 -0.70186 +0.87161 | 0 0 (of 65536)
DOME0 0.07637 0.06366 0.01271 | -0.04946 -0.07586 -0.00080 -0.62520 +0.66721 | 0 0 (of 65536)
XPOL 0.01592 0.01592 0.00000 | -0.06031 -0.06031 -0.00191 -0.75000 +1.00000 | 0 0 (of 65536)
== Hypotheses (visible: |C| >= 0.1)
H1a scratch(pol) COAX C = -0.94323 <= -0.1: True
H1b scratch(pol) DF80 C = -0.05566 >= +0.1: False
H1a scratch(rgh) COAX C = -0.93640 <= -0.1: True
H1b scratch(rgh) DF80 C = +0.07809 >= +0.1: False
H1c background COAX 1.06432 > DF80 0.06396: True
H2a |C mark| DOME8 0.70186, DOME0 0.62520 >= 0.1: True
H2b |C mark| COAX 0.04486 >= 0.1: False
H2c |C mark| DF80 0.74649 < min(DOME8, COAX) 0.04486: False
H3a |C bump| DOME8 0.04694 < COAX 0.64937: True
H3b |C bump| DOME8 0.04694 < BF30 0.00513 and < DF80 0.00178: False
H3a |C bump| DOME0 0.00080 < COAX 0.64937: True
H3b |C bump| DOME0 0.00080 < BF30 0.00513 and < DF80 0.00178: True
H4a hotspot px XPOL [0, 0] = 0 and COAX [63948, 63948] > 0: True
H4b |C mark| XPOL 0.75000 >= COAX 0.04486: True
The script uses NumPy 2.3.5 and SciPy 1.16.3, runs in about 12 seconds, and two runs printed identical output. The pilot ran the same script, unchanged, with the same output; nothing was changed after it.
All six checks held. C1 confirms the masks are disjoint and the bump’s largest tilt is 4.99°, C2, C3 and C6 are within their tolerances, C4 peaks at 40.00°, and C5 found no disagreement in 1,761 lit cases.
H1a held for both wall finishes: under the coaxial light the scratch is dark against the bright plate ( polished, rough). H1c held: at equal irradiance the background printed 1.06432 under COAX against 0.06396 under DF80. H1b failed for both finishes: under DF80 the polished groove printed , darker than the plate, and the rough groove , brighter but below the bar of .
H2a held: the mark is visible under both domes, with of 0.70186 (DOME8) and 0.62520 (DOME0). H2b failed: under the coaxial light the mark’s contrast is , below the bar. H2c failed: under DF80 the mark’s is 0.74649, the largest of the three geometries compared rather than the smallest.
H3a held for both domes: the bump’s under either dome (0.04694 and 0.00080) is below its 0.64937 under the coaxial light. H3b held for DOME0, whose is below both rings’. H3b failed for DOME8, whose is above both rings’ (0.00513 and 0.00178).
H4a held: COAX made 63,948 of the 65,536 pixels hotspot pixels with either wall finish, and the other five geometries none; the XPOL count is zero by construction. H4b held: the mark’s is 0.75000 under XPOL against 0.04486 under COAX.
The table also prints the dust, which no hypothesis covers: darker than the plate under COAX and brighter under every other geometry.
The example idealizes in several ways besides those of the scene description: sources at infinity and an orthographic camera, so that a flat plate images uniformly and the “hotspot” covers the whole plate rather than a spot (a near source and an ordinary lens make a localized one); no sensor, noise or saturation; and polarization treated as perfectly kept by single specular reflection and perfectly lost by diffuse reflection.
Variants
The guide’s illumination techniques, with the light heads it names for each:
- Back lighting. The part between light and camera gives a silhouette: presence of holes and gaps, placement, orientation and gauging. Monochrome light with collimation film suits sub-pixel edge detection; back light also passes through transparent and translucent parts, such as an amber bottle under red 660 nm light. Long, narrow linear back lights serve line-scan cameras on webs, run constant-on.
- Partial (directional) bright field. Spot, ring or bar lights from one side or angle; the guide calls it the most commonly used technique, good for topographic detail, but on-axis on specular surfaces it produces a hotspot.
- Full bright field (diffuse). Dome and tunnel lights send light from all directions and from low to high angles, which the guide describes as normalizing differential reflections on curved, shiny parts; the geometry article adds that a dome must sit close to the part to keep the effect. Coaxial diffuse lights act like a dome for flat parts and can use the specular reflection itself to show angled or textured features on otherwise flat parts, such as damage to a bottle’s sealing surface. Flat diffuse lights sit between the two, with more off-axis rays than coaxial and fewer than a dome, and work at much longer working distances than a dome.
- Dark field. Circular (ring) or linear (directional) low- and medium-angle lights, the circular kind usually at a very short working distance. A directional light across the web suits defects with a known orientation, such as a longitudinal scratch on sheet steel; many bright-field lights can be mounted in a dark-field configuration.
- Structured line lighting. Line lights at high or low angle for line-scan cameras, for example unwrapping a rotating can’s label into one image. Projected patterns for measuring height are structured light, and several directional lights used to recover surface normals are photometric stereo.
Best Practices
- Look at the camera’s image, not the part. The guide warns that human vision is a poor judge of what a camera will see, in spectral sensitivity and dynamic range alike, and recommends viewing the image as acquired.
- Test several geometries on real parts. The guide’s well-plate example shows why a wide variety of geometries should be tested, and its closing advice is to try two or three light types in the actual production environment.
- Design for robustness, not one good image. Check that contrast survives the expected spread of part position, orientation, shape and ambient light (the guide’s second acceptance criterion).
- Change the geometry before adding filters. The guide’s glare examples favour moving the light off-axis over polarizers, which cost light.
- Specify light on the part. Compare lights by irradiance at the working distance, in radiometric units for monochromatic and infrared sources, with the camera’s quantum efficiency in mind.
- Shut out ambient light with an enclosure, a matched band-pass filter or strobing, and keep the lighting level fixed in the station’s recipe (industrial machine vision).
- Mind eye safety near operators. The guide notes that LED lights are now classified for photobiological safety under IEC 62471 into risk groups from Exempt to group 3, and that infrared light produces no aversion response of the eye; it advises consulting the lighting maker about any doubt over a light’s safety.
Pitfalls
- Comparing lights in lumens. Photometric units rate light by the human eye’s response, which misjudges blue, red and especially infrared sources for a camera.
- Expecting colour to follow intuition. The guide’s deep blue bottle did not pass blue light preferentially.
- Polarizers on a light-starved station. In the guide’s glare example the pair needed the lens opened by 2½ f-stops, light a fast line may not have; on its curved bottle some glare remained anyway.
- Treating collimation film as true collimation. It still passes a wide window of off-axis light.
- Letting the light drift. Aging or failed LED segments change the image, which industrial machine vision and industrial visual inspection treat as a monitoring and maintenance task.
Evidence and Impact
The evidence in this article is of two kinds. The guide’s is practical: its figures pair images of the same parts under different lights, and its claims about what works on which surface are a maker’s experience, attributed to it rather than to measurements across many stations. It is one manufacturer’s guide; the other lighting makers’ tutorials could not be used for this article. The physics behind the geometries (the law of reflection, diffuse against specular reflection, Malus’s law, the inverse-square law) is standard optics, and the example’s numbers come from an exact rendering of an idealized scene, not from a camera. Neither kind measures how often a lighting change rescues a real inspection. The guide’s broader claim, that perhaps no other part of vision projects has caused more delay and cost than lighting, is its authors’ judgement.
Related
- Industrial Visual Inspection
Using cameras and vision algorithms to check manufactured parts on a production line, from lighting and optics to golden-template comparison, supervised defect models and anomaly detection trained on good parts only, judged by how many defects escape and how many good parts are rejected.
- Designing a Computer Vision System
How a working vision system is designed from its requirements, through the choice of sensor, optics, lighting, compute and model, to the data it is trained on, its validation in the field and its maintenance once deployed, with the requirement arithmetic for a measurement station worked through in code.
- Radiometry and Photometry
How light is measured in physical units (flux, radiant intensity, irradiance and radiance) and in units weighted by human vision (lumens, candelas, lux and candelas per square metre), with solid angle, the cosine and inverse-square laws, Lambertian surfaces, why radiance is what a pixel measures, and the SI definition of the candela.
- Image Formation
How light leaving a scene becomes an array of pixel values, through illumination and reflectance, the lens, the sensor and its colour filters, sampling and quantization, and the camera's own processing.
- Photometric Stereo
Recovering surface orientation and albedo at every pixel from several images taken from a fixed viewpoint under different lighting, from Woodham's Lambertian least squares to uncalibrated, robust and learned methods and the DiLiGenT benchmark.
- Structured Light
An active depth sensor that replaces one camera of a stereo pair with a projector, labels every illuminated point with a projected code such as a Gray-code sequence, phase-shifted fringes or a pseudo-random dot pattern, and triangulates each camera ray against the projector plane or ray the code identifies.
References
- Advanced Illumination (2023). A Practical Guide to Machine Vision Lighting (manufacturer's guide, HTML page published 25 January 2023 and last modified 29 December 2023, as of November 2026).
- Advanced Illumination (2026). Understanding Geometry in Machine Vision Lighting, 3 September 2026 (manufacturer's tutorial page, as of November 2026).
- Walter, B., Marschner, S. R., Li, H. & Torrance, K. E. (2007). Microfacet Models for Refraction through Rough Surfaces. Eurographics Symposium on Rendering (EGSR), 195–206 (not read).