ApplicationsHow-to

Wire color classification in machine vision: five colors, one set-up

Machine vision wire color classification: white diffused light, a gray reference, HSV thresholds and the optics numbers that keep five colors apart.

LumaSpec Vision10 min read Share on LinkedIn

On this page 9 sections
  1. 01What separates the five colors
  2. 02What you need
  3. 03Light the wires so the color stays constant
  4. 04Optics and exposure: a worked example
  5. 05The classification steps
  6. 06Verify before production
  7. 07Common mistakes
  8. 08When a trained classifier earns its keep
  9. 09Questions

A harness station has to tell five wire colors apart — cyan-gray, silver-gray, copper-yellow, blue and red — and two of the pairs are genuinely close. Cyan-gray and blue share a hue family; silver-gray and copper sit near each other in brightness. Classified on hue and saturation after white-balance normalization, all five separate cleanly and stay separated, shift after shift. This how-to gives the complete set-up: lighting geometry, a worked lens and exposure calculation, HSV thresholds, and the drift checks that keep the decision stable. The numbers assume a 60 mm field and a 200 mm working distance; the method scales to your fixture by redoing that one calculation.

What separates the five colors

Decide on two channels, not three: hue H and saturation S, with brightness V used only to police exposure quality. Under a fixed white light, red wraps around 0°, copper-yellow carries a warm hue, blue is deeply saturated, cyan-gray is blue with the saturation drained to roughly a third, and silver-gray has almost none at all. Brightness fails as a discriminator precisely because it moves with exposure, ambient light and lamp aging; the saturation direction of each pair does not.

V = max(R, G, B) S = (V − min(R, G, B)) / V (valid for V > 0) H = 60° × (G − B) / (V − min) when V = R

The other two channels give H by the same cycle, and a negative result takes +360°. The two hard pairs split on saturation, not brightness: cyan-gray against blue is a factor of three or more in S at nearly the same hue, and silver-gray against copper is hue present versus hue absent. Overexposure is what collapses these gaps — when a channel clips, max stays pinned while min keeps climbing, S falls, and copper starts reading as silver. Keep the reference patch near 200 of 255 and the brightest highlight below 250 and the boundaries hold.

What you need

  • A color camera. Insist on a global shutter when the wires move; a color vision sensor or smart camera decides on the device, while PC-based capture draws on the area scan cameras range.
  • A white diffused LED light with a controller that can strobe — the bar lights category is the usual pick at these fields.
  • A matte gray or white reference patch, roughly 20 × 20 mm, mounted in the field of view in the wire plane.
  • A shroud that blocks workcell ambient light.
  • A lens sized by the worked example below, or the fixed on-device optics of a smart camera.

Both of these classify on the device, one with its own white light:

Smart cameras & vision sensors1.6 MP smart camera, 60 fps, 16 mm lens, white light (polarized, transparent light) (LS-SMC-0063)LS-SMC-0063
Interface
GigE
Resolution
Up to 3 MP
$1,110.00View part
Smart cameras & vision sensorsHikrobot MV-SC3050XC-16M-ATN-H 5 MP color vision sensorMV-SC3050XC-16M-ATN-H
Interface
Fast Ethernet
Resolution
5 MP
$1,809.00View part

Light the wires so the color stays constant

The classification lives or dies on light stability, so spend the effort here before touching the algorithm.

Fixed white. One color temperature and one drive current, every cycle. If the light is a programmable RGB unit, lock it to a fixed white mix for capture and never let it cycle during measurement. LED bins drift with age and heat, so specify deliberately — the white LED color temperature guide explains what to put on the purchase order.

Diffuse. Shiny cylindrical insulation throws a specular band that rotates with wire twist. A diffused bar or a small dome at 30-60° to the wire axis and 100-200 mm from the part softens it; where the band still clips pixels, add a polarizer to the lens and a film to the light — cross polarization removes the band almost completely.

No flicker. PWM drive can beat against the exposure and shift V frame to frame; drive at constant current or strobe in sync with the camera. The flicker diagnosis guide gives the test.

Both run on 24 V; pick by lit width:

Bar lightsBar light, 372 x 28 mm, White (LS-BAR-1276)LS-BAR-1276
Size
200-400 mm
Type
Diffused
$439.00View part
Bar lights1272 x 22 mm Diffused bar light (LS-BAR-0295)LS-BAR-0295
Size
400 mm +
Type
Diffused
$1,509.00View part

For a 60 mm field, one short diffused white bar above the part at about 150 mm and 45° is enough. Fix the geometry — re-clamping the light afterwards moves every threshold you calibrated.

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

Optics and exposure: a worked example

Size the optics from the part. Suppose the fixture pad is 50 mm wide; with margin for clamps, set the field of view to 60 mm. Take an example camera of 2448 × 2048 pixels at 3.45 µm; the sensor width is 2448 × 3.45 µm = 8.45 mm.

m = sensor width / FOV = 8.45 mm / 60 mm = 0.141 f = WD × m / (1 + m) = 200 mm × 0.141 / 1.141 = 24.7 mm → pick a 25 mm lens FOV at 25 mm, 200 mm = 8.45 mm / (25 / 175) = 59.1 mm

At 59.1 mm across 2448 pixels, the image scale is 24.1 µm per pixel — 41 px per mm. A 3.6 mm insulated wire spans 149 pixels, and the inner half you will sample is about 74 pixels across, far above the 8-10 pixel minimum, so the median hue per wire is statistically solid.

Stop down to f/4. Total depth of field at this magnification is about 21 mm, so ±10 mm (estimate from DOF ≈ 2 N c (1 + m) / m² with c = 2 pixels = 0.048 mm). Diffraction at f/4 spreads the Airy disk to 2.44 × 4 × 0.55 µm = 5.4 µm, about 1.6 pixels; soft edges cost nothing here because the decision averages a 74-pixel region.

Exposure. On a static fixture, 10 ms is comfortable. If a belt carries the harness at 300 mm/s and blur must stay under one pixel: t ≤ 0.0241 mm / 300 mm/s = 80 µs. That is 125× less light than 10 ms — recover it by strobing the LED across the exposure through the controller, and open to f/2.8 (twice the light) if ±7 mm of depth of field still covers your part.

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

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.

Two color cameras that cover the two capture styles:

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
$309.00View part
Area scan camerasHikrobot MV-CS200-10GC 20 MP Area Scan Camera, GigE, IMX183, Color, BasicMV-CS200-10GC
Sensor format
1"
Lens mount
C-mount
$739.00View part

The 2.5 MP global-shutter model handles a field of roughly this size on a moving line; the 20 MP rolling-shutter model buys pixels for a dense dozen-wire bundle, on a static fixture where rolling shutter is safe.

The classification steps

Commission once, then take the auto modes out of the loop.

  1. Fix the exposure (10 ms in the example), fix the gain, and switch white balance to manual. Auto exposure and auto gain re-aim the color vector every frame — the auto exposure guide for color cameras shows which pixels they chase.
  2. Mount the gray patch inside the field of view, in the same plane as the wires.
  3. Normalize every image on the patch: take each channel's median over the patch and scale it so the patch reads 200 of 255. Where a camera lacks manual white balance, a light balancing filter does the same job before the sensor sees the color; across multiple stations, normalize each camera and compare patch values station to station (multi-camera white balance).
  4. Convert the normalized RGB to HSV with the formulas above.
  5. Segment the wires with a brightness threshold on V or an edge-based split, ordered left to right.
  6. Sample the inner 50% of each wire's diameter and take the median H, S and V of that region.
  7. Classify with the table: saturation gate first, then hue inside the saturated family, then the blue-lean test inside the gray family.
  8. Apply the margin rule — flag any sample within 0.03 of a boundary for review — and log the patch medians beside every decision.
Class Saturation S Hue H Family
silver-gray ≤ 0.10 any gray
cyan-gray 0.08-0.28 175-230° gray, blue-lean
blue ≥ 0.35 205-255° saturated
copper-yellow 0.30-0.60 22-50° saturated
red ≥ 0.35 345-15° (wraps 0°) saturated

These are starting values from a sample set under the lighting above; move each boundary by a few points when you measure your own jackets. The gap worth defending is the 0.07 of saturation between cyan-gray's ceiling and blue's floor — if your measurement shows less, fix the light or the exposure before touching the thresholds.

Verify before production

Test like production, not like a demo.

  • Thirty images per color across two shifts, then build the confusion matrix. The bar: zero confusions inside the two hard pairs, 99% or better overall.
  • Stress the light by dropping LED current 10% and raising it 10%; every decision must hold. If cyan-gray flips to blue when the light dims, the saturation gap is thinner than your calibration sample showed.
  • Alarm when any patch median moves ±10 counts from commissioning — one number that catches LED aging, a shifted shroud and a smudged lens at once.
  • Re-run the check after any optics change; even a cleaned lens shifts transmission enough to move normalization a few counts.

Common mistakes

  • Sampling to the wire edge, where insulation blends into the dark background and hue smears; the inner half exists for a reason.
  • Colored ambient in the shroud — a blue status lamp or an HMI glow shifts every normalized channel. Shroud first, measure second.
  • A programmable RGB light left cycling through its demonstration program between machine cycles.
  • A reference patch mounted off the wire plane: its brightness changes with the tilt, and normalization chases the tilt instead of the lamp.
  • Trusting the jacket's nominal color instead of measuring it. Supplier lots vary more than your thresholds, and color tables such as the American wire color conventions for machine power wiring assign meanings by function, not by the appearance your camera measures.

When a trained classifier earns its keep

Thresholds are deterministic, run in well under a millisecond and can be audited line by line — the right tool while the five colors stay fixed, opaque and identically lit. A small trained model starts paying when jacket sheen or translucency smears the color vectors, when supplier lots vary widely, or when the station must absorb new colors without re-engineering. Budget 50-200 labeled images per class and a re-validation after any lighting change; the AI versus rule-based comparison walks through that trade. Even then, the lighting discipline above is what keeps the training set consistent — a model trained on drifting light learns the drift, not the color.

To size your own station, start from the field of view and the two hard pairs: fix the fixture, add the gray patch, then pick the camera and the light around the numbers above. The camera finder and light finder filter by resolution, interface and lit width, and the camera configurator pairs the body with mount and cabling. If you want a second pair of eyes on your threshold table, send your sample images through the contact page.

Questions

Can one camera classify all five wire colors in a single frame?

Yes, if the field of view covers the bundle. The worked example's 41 px per mm over a 2448-pixel sensor gives a 60 mm field — five wires with margin. A dozen-wire bundle needs roughly 120 mm, halving the scale to about 20 px per mm; a 3.6 mm wire still spans 72 pixels. Keep each wire's inner sampling region 8-10 pixels across or wider.

Can a mono camera with sequenced red, green and blue strobes replace a color camera?

Yes — pulse red, green and blue light in sequence and combine the three mono exposures into one color record. It works on a static fixture but triples the cycle time, and any motion between pulses fringes the color. A color sensor in a single exposure is simpler wherever the line speed allows one.

Why do thresholds pass at commissioning and fail days later?

Check the patch median trend first. A slow fall points to LED aging, a step change to a moved shroud or lamp, and random frame-to-frame scatter to exposure or gain hunting — which means an auto mode is still enabled. Fix the exposure and gain, normalize on the patch, and alarm at ±10 counts.

How thin a wire can this still classify?

Keep the inner sampling region at least 8-10 pixels across. At 41 px per mm that bounds the outer diameter near 0.5 mm; below that, edge blending and diffraction dominate the median hue. Thinner wires need more magnification — a shorter working distance or a longer lens — and in practice translucent jacket walls limit thin-wire color work before resolution does.

Do I need deep learning for five wire colors?

Not when the five colors are fixed, opaque and identically lit: hue-saturation thresholds decide in well under a millisecond and every rejection can be audited. Trained classifiers earn their keep when sheen, translucency or supplier lots smear the color vectors — budget 50-200 labeled images per class and re-validate after any lighting change.