LightingExplainer

Part and lighting color to maximize grayscale contrast

Choose lighting and part colors to maximize grayscale contrast for a monochrome camera, with the Michelson formula and a worked PCB example.

LumaSpec Vision12 min read Share on LinkedIn

On this page 9 sections
  1. 01The decision rule: maximize the gray-level gap at the sensor
  2. 02Match the light to the part, or oppose it
  3. 03Why narrowband light beats white light
  4. 04Worked example: gold pads on a green PCB under red light
  5. 05Bright feature or dark feature: pick the side deliberately
  6. 06Where the rule breaks down
  7. 07Bench checks before you order
  8. 08Cameras and lights for the job
  9. 09Questions

A threshold that survives the plant floor is decided at the lighting bench, not in software. Two surfaces can look clearly different to the eye and still land within a few gray counts of each other on the sensor, and that threshold fails the first time a door opens. This guide gives the rule that keeps feature and background far apart in gray level, the wavelength logic behind it, a worked PCB example with the arithmetic, and the camera and light decisions that follow from it.

The decision rule: maximize the gray-level gap at the sensor

Judge every lighting choice by one number: the difference between feature and background brightness as the camera reports it, in gray counts. Visual similarity, print quality and color difference are all secondary; the threshold sees gray counts only.

The standard measure is Michelson contrast:

C = (L_bright - L_dark) / (L_bright + L_dark)

Here L_bright and L_dark are the mean gray values of the two regions in the same image, with exposure and gain fixed. The same formula works directly on reflectances, because a linear sensor maps reflectance times exposure to gray value: contrast computed from the reflectance pair equals contrast computed from the gray pair.

C = 0 means both regions return the same gray, and no threshold exists. For scale: an 8-bit camera reports 0 to 255, and with the bright region near 230 counts, a 200-count gap gives C = (230 - 30) / (230 + 30) = 200 / 260 ≈ 0.77. Two rules of thumb carry through this guide: aim for C of 0.5 or better on the operating histogram, and keep the gap at least about eight times the additive ambient shift you measure with the lights off. Contrast that only just works fails the first time the process drifts — see robust machine vision lighting: why adequate contrast is not enough.

Match the light to the part, or oppose it

A surface returns the wavelengths its pigment reflects and absorbs the rest. That gives you two levers, pointing in opposite directions:

  • Matched light: make the feature bright. Light in the feature's own band lands on the top of its reflectance curve. Red light on red plastic, or on bare metal — gold, copper and silver reflect red strongly — drives the feature high while green solder mask, dark plastic and most print absorb the band and stay dark.
  • Opposite light: make the feature dark. Light in the complementary band lands where the pigment absorbs. Green light around 520-530 nm drives red and amber features dark; blue light around 460-490 nm does the same to orange and yellow. Use it when the background is the stable majority and you want the feature below the threshold.

The color wheel is the working map: pick the light color by where you want each surface to land.

Typical LED peaks to specify: red 625-660 nm, green 520-530 nm, blue 460-490 nm, plus white, infrared at 850 or 940 nm and ultraviolet at 365-395 nm. For band choices measured on real targets, see which LED colour gives the best contrast in machine vision.

Why narrowband light beats white light

A monochrome silicon sensor integrates everything from roughly 400 to 1000 nm into one gray value. White light spreads that integration across the whole visible range, so two colored surfaces that differ sharply at one wavelength average toward similar mid-gray. A narrowband LED samples each surface at a single point of its reflectance curve, where the separation is largest.

This is also where the eye misleads you. Red and green caps that look completely different under white light can return gray values within a few counts of each other, because their integrated reflectances happen to match; under a green LED the same pair separates completely.

The camera side matters as much as the light side. A monochrome sensor sums the full response, giving the largest signal and the deepest gap, and a bandpass filter on the lens narrows it further in a colorful scene. A color camera splits the light into broad, overlapping Bayer bands, so red signal leaks into every channel and each channel alone is dimmer and noisier. Color cameras earn their keep when hue itself is the feature — sorting red from green caps, checking print color. For gray separation, mono plus a colored LED wins.

The sensor-side detail is in monochrome versus Bayer color filter arrays, and the filter path is in why a monochrome camera with an optical filter beats color.

Worked example: gold pads on a green PCB under red light

Inputs, with where each comes from:

  • Light: red LED bar light, peak near 630 nm (red LED band 625-660 nm).
  • Background: green solder mask returns about 10 percent of incident red light — green pigment absorbs the red band.
  • Feature: bare copper and gold pads return about 90 percent — gold, copper and silver reflect red strongly. The 10/90 split is the rule-of-thumb pair for a strongly complementary combination; your histogram gives the exact numbers.
  • Camera: 8-bit monochrome output, 0-255 counts. Exposure set from the bench histogram until the pads read 230 counts, about 90 percent of full scale.
  • Ambient: lights-off frame at the worst time of day shows a uniform shift of +12 counts typical, +24 counts in the worst case measured.

The rule in words: with exposure fixed, gray value carries the reflectance ratio, so the Michelson contrast of the reflectance pair equals the Michelson contrast of the gray pair.

Arithmetic:

  1. Reflectance contrast: C = (0.9 - 0.1) / (0.9 + 0.1) = 0.80.
  2. Gray values: pads at 230; mask at 230 × (0.1 / 0.9) = 25.6 ≈ 26. Gap = 230 - 26 = 204 counts. C = (230 - 26) / (230 + 26) = 204 / 256 ≈ 0.80 — the same number, with the small step coming from rounding 25.6 to 26.
  3. Threshold: any value between 26 and 230 separates the regions. The midpoint, 128, leaves 102 counts of margin to each side.
  4. Ambient at +12: pads read 242, mask reads 38. A uniform additive shift moves both regions equally, so the gap stays 204 counts; C drops to 204 / 280 ≈ 0.73 because the denominator grew. The threshold at 128 still splits (38 below, 242 above).
  5. Worst case at +24: pads 254, mask 50. Gap still 204, threshold still holds — and the pads sit one count from saturation.

Decision: the threshold itself is safe — ambient would need about +102 counts to push the mask region across 128, more than four times the worst case measured. The binding constraint is saturation: one more count of ambient clips the pads, and a clipped bright region lets the gap close from the top. Trim the exposure about 10 percent: pads 207, mask 23, worst case 231 and 47. The gap falls only to 184 counts, saturation headroom grows to 24 counts, and the threshold keeps a margin of 81 counts on the dark side. Keep the LED driven so its contribution at the surface stays near ten times the lights-off reading, and the additive shift stays in the tens of counts rather than the hundreds.

Bright feature or dark feature: pick the side deliberately

Both directions can deliver a large C. The real choice is which region dominates the histogram: put the bigger, more stable area on one side and the feature on the other, then let the threshold sit in the valley.

Task Feature ends up Light color Why it works
Gold or copper pads on green solder mask Bright Red, 625-660 nm Metal reflects red; green mask absorbs it
Red or amber print on a neutral surface Dark Green, 520-530 nm Red pigment absorbs green; neutral background stays mid-gray
Orange or yellow feature Dark Blue, 460-490 nm Orange and yellow pigments absorb blue
Black ink on a white label Dark White or any LED Ink absorbs across the band, so every wavelength works
Red part on a gray carrier Dark Green The red part drops below the gray instead of competing with it

Code reading defaults to a dark code on a light field, because the background peak is the stable one — see OCR thresholding with a dark background. For how bright-field and dark-field geometry interact with these color choices, see light color and monochrome camera contrast: bright vs dark.

Where the rule breaks down

White light on a colored pair. Under white light both reflectances average, and the pair can nearly tie. Illustrative numbers: a red surface at 60 percent integrated reflectance against a light-gray background at 70 percent gives C = (0.7 - 0.6) / (0.7 + 0.6) = 0.08. At the example's 230-count operating point the background sits at 230 and the red surface at 230 × (0.6 / 0.7) ≈ 197, a gap of 33 counts — ambient can eat that in one shift. Swap the band, not the exposure.

Infrared flips the map. Silicon keeps responding to about 1000 nm, and pigments that absorb visible light can pass or reflect near 850 nm, so a brighter IR light can turn a black code mid-gray and invert the polarity of the whole image. Test at the purchase wavelength first — see near infrared wavelength selection for water and silicon inspection.

Ambient is not gray. White ambient re-illuminates each region with its broadband response, adding more to the green mask than to the pads, so it erodes the gap faster than the uniform shift in the example. Shroud the station or drive the LED past ambient; the ratio of gap to lights-off counts tells you the margin you bought — see ambient light variation in pick and place vision: control it.

Same color everywhere. No wavelength separates a red part from a red tray; the reflectance pair is 1:1 at every band. Change the geometry — lighting geometry for image contrast: camera, light and part positions — or the part presentation. If uneven shading on the part itself is what limits you, software has a fallback in dark region extraction: adaptive thresholding for uneven part shading, but do not make software carry a cell the lighting could win.

Bench checks before you order

  1. Histogram the pair. Fixed exposure, both regions in frame; note the mean gray of each and compute C. Below about 0.5, try the complementary LED before changing anything else.
  2. Lights-off frame. Worst time of day, lights and enclosure as in production. The gap should stay about eight times that shift or better.
  3. Saturation check. Brightest region at or below about 240 counts at the operating exposure, so ambient has headroom before clipping.
  4. Sweep wavelength, not brightness. A complementary band or a bandpass filter moves C far more than exposure does — see machine vision optical filters: choosing contrast over color and color filters on monochrome cameras: match the filter to the feature.
  5. Confirm the sensor is mono. If the gap only appears when you switch from a color model, band overlap is the cause, not the lighting.

Cameras and lights for the job

A monochrome area scan camera is the whole story on the sensor side: every band lands on one channel, at full signal. Filter the area scan cameras by mono sensor, resolution and interface, or narrow the field in the camera finder. The lighting finder sorts LED lights by wavelength, shape and drive — start with bar lights for the flat-field red LED in the example.

One monochrome reference that fits the worked example above:

Area scan camerasHikrobot MV-CS200-10UM 20 MP Area Scan Camera, USB3.0, IMX183, 2nd Gen., MonoMV-CS200-10UM
Sensor format
1"
Lens mount
C-mount
Interface
USB3
Resolution
16-25 MP
$759.00View partBuild a system with it

The MV-CS200-10UM is a 20 MP monochrome USB3.0 camera with a 1" sensor and C-mount — enough pixels to hold both regions and their histograms in one frame with margin to zoom. If your cell instead runs on GigE, filter the camera finder by mono sensor and GigE interface; any of those models reads the same gray values under the same light.

Build the whole station

The configurator matches a camera, lens, light, light controller and cables to each other, step by step, and lists only parts that fit what you already picked.

Start with the light

Size wavelength and geometry together: pick the band first from the reflectance pair, then the shape — bar, ring, dome or coaxial — from the surface. The camera configurator matches sensor and lens to the field of view next. More worked lighting choices sit on the lighting topic page, and if you send your histogram and lights-off frame through the contact page, we will read the gap and name the band.

Questions

Does a brighter light increase grayscale contrast?

No. Raising exposure or drive current multiplies every gray value by the same factor, so the ratio between the two regions, and the Michelson contrast, stays as it was. Brightness buys short exposures and immunity to dim ambient light, both worth having, but it cannot separate two surfaces that return the same gray under the same band. Move the wavelength, add a bandpass filter or change the lighting geometry instead.

Which LED color makes a red part look dark on a monochrome camera?

Green, around 520-530 nm, is the standard pick: the pigment that reflects red absorbs green, so the part drops to a low gray value while neutral surfaces stay near mid-gray. Blue light works the same way on red and amber. Red light does the opposite and drives the red part bright, which is the correct choice when the part is the feature and the background must go dark.

Can a color camera replace a monochrome camera plus colored light?

Only when hue itself is the feature, such as sorting red from green caps. A Bayer sensor splits light into broad, overlapping bands, so red signal leaks into every channel, and each channel receives only a quarter to a half of the photons, which costs signal quality exactly where you need separation. A monochrome sensor with a narrowband LED keeps the whole band on one channel and delivers the deeper, more stable gray gap.

Why does black print turn bright under an infrared light?

Silicon keeps responding to wavelengths out to about 1000 nm, and many inks and pigments that absorb visible light transmit or reflect near 850 nm. A code that read dark under white light can land mid-gray or bright on an infrared image, which flips the polarity of the threshold. Image the actual print at the wavelength you plan to buy; if it vanishes, stay in the visible band or change the code medium.

How much gray-level gap does a fixed threshold need?

Scale it to your own cell. Take the gap in counts from the histogram and the additive ambient shift from a lights-off frame at the worst time of day. In the PCB example the gap was 204 counts against 24 counts of worst-case shift, and the threshold sat 102 counts from either side, so ambient could grow more than fourfold before it crossed. Keep that order of margin and the threshold holds.