LightingExplainer

Colored background for object teaching: contrast, not hue

Pick a colored background for object teaching by grayscale contrast, not hue: the luma formula, gray levels per mat, a worked example and when a backlight wins.

LumaSpec Vision12 min read Share on LinkedIn

On this page 10 sections
  1. 01What the colored background does during object teaching
  2. 02How the camera turns a mat color into one gray value
  3. 03The decision rule: 50 gray levels of separation
  4. 04Worked example: black molded connector on a saturated teaching mat
  5. 05Where the background comes from: mat, backlight or light color
    1. A matte mat under a diffused ring light
    2. A backlight, when the part is flat
    3. The camera: color helps, gray decides
  6. 06Teach on the background you will run on
  7. 07When the usual answer is wrong
  8. 08Checks before you commit the teach
  9. 09When to skip the colored mat
  10. 10Questions

A colored teaching mat earns its place in a camera kit for one reason: it gives the object-teaching wizard a background it can separate from the part. The separation the wizard measures is grayscale, not hue, so the mat that looks most different to your eye is often the one the camera merges with the part. The fix is arithmetic, not taste. Convert each possible background into a gray value, compare it with the part's gray at the run-time exposure, and keep the mat only if the gap clears 50 of 256 levels. That rule holds on smart cameras and vision sensors and on any workflow that segments a taught part from its background.

What the colored background does during object teaching

The teaching wizard reduces the scene to one question per pixel: part or background? It learns the gray statistics of each region, stores them with the taught model and reuses them at run time. The background therefore does double duty: it is half of what gets taught and all of what the part is judged against.

A worn bench, a shiny offcut of aluminum or a scrap of tape under the part injects gray values that compete with the part. The wizard then splits one object into two regions, drifts off the part entirely, or reports locate failures that look like software bugs. A uniform matte field removes that competition, which is why camera kits ship a set of colored mats. The color itself is not the point; the controlled luminance is.

How the camera turns a mat color into one gray value

A color camera collapses its three channels to one gray value before thresholding, and most imaging libraries use the Rec. 709 luma weights to do it, applied to the stored 8-bit channel values. Green dominates the sum, red weighs about a third of green, blue about a tenth.

gray = 0.2126 R + 0.7152 G + 0.0722 B

Apply the weights to saturated mats, on an 8-bit camera under white light with the exposure set so a perfect white reads 255, and the ladder below falls out. Every value scales linearly with exposure: halve the exposure and the whole ladder halves.

Mat color RGB (8-bit) Gray value
White 255, 255, 255 255
Yellow 255, 255, 0 237
Cyan 0, 255, 255 201
Green 0, 255, 0 182
Magenta 255, 0, 255 73
Red 255, 0, 0 54
Blue 0, 0, 255 18
Black 0, 0, 0 0

A mono camera has no RGB split: its gray value follows the sensor's spectral response to whatever spectrum the light emits. Under a white LED the ordering above survives roughly intact; under a 620 nm red ring light, green and blue mats fall toward black while red and white stay bright. Choosing that wavelength is its own decision — Which LED colour gives the best contrast in machine vision and light color and monochrome camera contrast: bright vs dark cover it — and the part side of the trade is Part and lighting color to maximize grayscale contrast. This guide holds the part's color fixed and moves the field behind it, under white light.

The decision rule: 50 gray levels of separation

Keep a mat only when part gray and background gray differ by at least 50 of 256 levels. The basis: a typical bench shows 3 to 5 levels of temporal noise and around 10 levels of corner-to-corner falloff on a matte mat, so 50 levels separates the two pixel populations by several times that spread and leaves room to park the segmentation threshold midway between the means.

Part color Part gray (approx) Best background (gap) Mats that fail the 50-level rule
Black 13 White (242) Red (41), blue (5), black (0)
Blue 18 White (237) Black (18), blue (0)
Red 54 White (201), cyan (147) Blue (36), magenta (19)
Green 182 Black (182), blue (164) White (73) and yellow (55) only just pass
Yellow 237 Black (237), blue (219) White (18)
White 240 Black (240), blue (222) White (15), yellow (3)

The table assumes a strongly colored part that renders near its own hue under the same white light; a real part lands where its reflectance puts it, so measure its mean gray on a saved image and read the gap from the ladder. Shiny metal steps outside the table entirely — the part mirrors the mat rather than reflecting it — and gets its own section below.

Worked example: black molded connector on a saturated teaching mat

Inputs, and where each comes from:

  • Part: a black molded connector; the example assumes 5% diffuse reflectance, mid-range for black plastics at roughly 3-10%.
  • Light: a diffused white ring light at fixed current, exposure set so a perfect white surface reads 255 on the 8-bit image.
  • Camera: a color sensor; the teaching wizard converts to gray with the Rec. 709 weights above.
  • Mats: saturated single-color mats, 255 in the lit channel and 0 in the others.

The rule in words: a background's gray is the weighted sum of its channels, and the part's gray is its reflectance times the white reference of 255.

red mat = 0.2126 × 255 = 54 green mat = 0.7152 × 255 = 182 blue mat = 0.0722 × 255 = 18 part = 0.05 × 255 = 13

Separation between the part at 13 and each mat: white 255 − 13 = 242; green 182 − 13 = 169; red 54 − 13 = 41; blue 18 − 13 = 5; black 13 − 13 = 0.

The decision: the 50-level rule keeps the white mat at 242 and the green mat at 169, and rejects red at 41, blue at 5 and black at 0. Choose white — 242 levels is almost five times the minimum, margin that survives exposure drift and mat wear. The blue mat is the trap this example exists to catch: to your eye it is vivid against a black part, but at 5 levels the camera reads part and mat as one surface.

Where the background comes from: mat, backlight or light color

Three sources of background, in rising order of control: a mat you light, a light you put behind the part, and the color of the light itself.

A matte mat under a diffused ring light

Print or paint the field, then light it with a diffused ring light so the whole area reads one gray. A hard-edged ring or a bare bench lamp paints a bright stripe across the field, and the stripe becomes a false edge the wizard learns faithfully. Coverage and placement decide the evenness — Lighting geometry for image contrast: camera, light and part positions walks that choice — and a glossy mat adds a specular hot spot, which polarization removes, as Cross polarization machine vision: reduce surface glare shows.

The LS-RNG-0426 is a diffused white ring light with a 120 mm diameter, a 0-15° low-angle output and a 24 V supply.

When no mat hue clears the rule, move the light instead. A colored ring shifts every surface's gray by its reflectance at the emitted wavelength: under the 620 nm red output of the LS-RNG-0100, which projects inward at 60° from a 120 mm diameter on 24 V, green and blue mats read nearly black on a mono camera while red and white stay bright. That is the wavelength route to a dark field when no mat works.

Ring lightsRing light, 120 mm dia., 0°, White (LS-RNG-0426)LS-RNG-0426
Size
100-200 mm
Type
Diffused
$369.00View part
Ring lights120 mm dia. ring light, 60°, 620 nm, 24 V (LS-RNG-0100)LS-RNG-0100
Size
100-200 mm
Type
Standard
$179.00View part

A backlight, when the part is flat

The strongest background is a luminous one. A backlight puts the source behind the part, so the field reads near full scale, the part reads as a silhouette, and separation stops depending on paint, plastic or mat wear. That makes it the default for gaskets, O-rings, punched blanks and films — anything flat whose outline is the feature. Diffuse panels suit thin parts; thick or shiny edges let light skim around the outline and fog the silhouette, so go collimated. Collimated backlight or diffuse backlight for edge gauging compares the two, and Collimated backlight setup: working distance and light size sizes the panel to the field.

The LS-BKL-0750 is a high-luminance backlight with a 180 x 100 mm lit area on 24 V. For shiny or thick edges, the collimated LS-BKL-0830 covers a 120 x 120 mm field, also at 24 V.

Backlights180 x 100 mm High luminance back light (LS-BKL-0750)LS-BKL-0750
Size
100-200 mm
Type
Standard
Voltage
24 V
$369.00View partBuild a system with it

The camera: color helps, gray decides

A color sensor keeps every option in this guide open, because the wizard can re-weight channels or you can re-map gray in software. The MV-SC3050XC-16M-ATN-H is a 5 MP color vision sensor with a global shutter, an M12 lens mount and a Fast Ethernet port — a common teaching-station pick. Where the mat or the part is glossy, the LS-SMC-0063 smart camera attacks the hot spot at the source: it integrates a polarized white light around its 16 mm lens and runs its 1.6 MP sensor at 60 fps. The smart cameras category holds the rest of the range.

Smart cameras & vision sensorsHikrobot MV-SC3050XC-16M-ATN-H 5 MP color vision sensorMV-SC3050XC-16M-ATN-H
Interface
Fast Ethernet
Resolution
5 MP
Sensor format
1/1.45"
Shutter
Global
$1,809.00View part

Teach on the background you will run on

The wizard stores the background statistics with the part, so the background must still be there at run time. Teach a connector on a blue mat and present it later on bare steel, and the model points at a field that no longer exists: false rejects, missed locates, thresholds that fit nothing. Vision locate works in teach but fails at run time: stream vs snapshot covers the sibling failure, where timing rather than background moves the scene.

Keep the taught background honest in one of three ways. Keep the mat in the fixture, so every cycle presents the part on the same field — the standard answer for pick-and-place cells. Teach on the production surface itself, when the part must be inspected where it lies. Or backlight the station, which reproduces an identical luminous field every cycle regardless of what sits underneath. Whichever you choose, fix the exposure: auto-exposure rewrites every gray value in the scene and silently voids the 50-level margin. Ambient light variation in pick and place vision: control it lists the controls, and Object teaching on a vision camera: the setup that holds at run time assembles the full teaching set-up.

When the usual answer is wrong

Three cases walk past the table.

Shiny metal mirrors instead of reflecting: the mat's color arrives inside the part's own pixels, so no hue choice survives. Go dark and matte behind the part, or work at a low angle so the field stays dark while edges glint, or backlight. Metal part on metal background: lighting for consistent detection works that problem head-on, and Backlight for width measurement on shiny turned steel shows the silhouette version.

Transparent and translucent parts show the mat through their own pixels: a red gasket on a red mat disappears, just as a black part disappears on a blue mat, and for the same luminance reason. Pick the mat by transmitted gray, or drop the mat and backlight at a wavelength the part absorbs — Backlight wavelength selection for semi-transparent parts sets out that choice.

Parts inspected in motion on their own conveyor rarely get a mat at all: teach on the belt surface, or hang the station on a backlight and let the luminous field be the background.

Checks before you commit the teach

Run these on saved images at the exposure production will use:

  1. Fix the exposure: auto-exposure off, fixed shutter and gain. Every value in the ladder scales with exposure, and auto mode rescales it frame by frame.
  2. Measure both means: draw regions over part and background and read their mean gray on the saved file, not on a live view.
  3. Require the 50-level gap, and park the segmentation threshold midway between the two means.
  4. Sweep the part across the mat, corners included, and confirm the gap holds at every position.
  5. Shoot the worst case: oiled, oxidized or mold-fresh parts, whichever is ugliest, on each shortlisted mat.
  6. Repeat the measurement under the run-time light with the plant's ambient present; skylights and high-bay lamps move both means.

When to skip the colored mat

A mat earns its keep when the part sits on something uncontrolled. Skip it when the station already owns the background: a backlight makes the mat redundant for flat parts, texture-based teaching finds features without background contrast at all, and a height-based inspection ignores the field behind the part entirely. If the feature that matters is the outline, backlight and be done; if the feature sits on the surface — an engraving, a dot-peened mark, a defect — the background was never the problem, the illumination angle was.

Start from the ladder: compute the part's gray, pick the background that clears 50 levels, then order the light that makes the field even. The light finder filters lights by color, size and type, and the lighting step of the configurator assembles light, controller and mount in one pass; on the camera side, the camera finder and the camera step of the configurator do the same for the sensor. The lighting guides hub collects the neighboring lighting decisions, and the contact page reaches us if you want a part photo checked against the ladder before you order.

Questions

What background color should I use to teach a black part?

White, by a wide margin. Under white light the part reads about 13 of 256 gray levels and a saturated white mat reads 255, a 242-level gap; a green mat still works at 169. A blue mat reads 18, five levels from the part, which is why a black part on a blue mat teaches badly despite looking colorful. The white mat also keeps the largest margin against lighting drift.

Does background color matter for a monochrome camera?

It matters more, because the sensor weighs every color by its spectral response to the light in use. Under white illumination the ordering is close to the color camera's ladder; under a red or blue LED the ladder reorders completely, and a mat that was mid-gray can go black. Judge the mat on a saved image captured with the run-time light, never under room lighting.

How much gray-level separation do part and background need?

Plan on at least 50 of 256 levels. A typical bench shows 3 to 5 levels of temporal noise and around 10 levels of illumination falloff across a matte mat, so 50 keeps the two pixel populations apart by roughly three times that spread and leaves room to park the threshold midway. Measure it on a saved image at the production exposure, not on a live view.

Why does a taught object fail once production starts?

Usually the background changed. The wizard stores the background statistics with the part, so a switch from teaching mat to bare conveyor removes the field the model expects. Keep the mat in the fixture so every cycle sees it, teach on the production surface, or backlight the station so the luminous background is identical every cycle regardless of what is underneath.

Can a backlight replace the colored teaching mat?

For flat parts, yes, and it usually wins: the background becomes transmitted light at near-full scale, the part becomes a silhouette, and separation stops depending on paint or plastic reflectance. Use a diffuse panel for films and gaskets and a collimated panel for thick or shiny edges, where light skimming around the outline would fog the silhouette.

What if the part matches every mat color in gray?

Under white light that is rare, because black and white mats bracket the ladder with 255 levels between them. When it happens, stop moving the background and move the light: a colored LED drives mats that absorb its wavelength toward black and shifts the part the same way. A shiny part that defeats every wavelength needs a dark matte field or a backlight instead.