Grayscale pattern matching works until the light moves. A part that scores 0.93 at 06:00 scores 0.71 at 15:00, the accept threshold sits at 0.80, and a sunny afternoon rejects good parts by the hundred. Retaking the golden template treats the symptom and usually ships a new one next week. Normalized grayscale correlation scores pixel brightness, so anything that changes brightness unevenly moves the score: window light, light warm-up, a new material lot with a different finish. Edge based (geometric) pattern matching scores gradient direction along contours instead, and gradient direction survives exactly the changes that break correlation. This guide gives the decision rule for switching algorithms versus fixing lighting, the optics arithmetic for a stable station, and the checks that hold false rejects near zero.
Why grayscale correlation drifts when the light moves
Normalized grayscale correlation subtracts the mean intensity from the template and the search region, divides both by their standard deviations, and averages the product over the region:
That normalization divides out any uniform gain or offset: an even 30% brightness drop across an even image leaves the score essentially untouched. What it cannot divide out is change that varies across the field of view — mismatched pixels stay mismatched, and the matched ones cannot compensate beyond their share of the area.
- Window or doorway light striking one corner of the nest
- A shadow edge that crosses the part as the sun moves
- Lights running hotter for the first minutes after power-up
- A new lot of parts with a different finish, oxide colour or oil film
As a working number, a spatially uneven change of 20-30% between template and live image costs 10-20 score points. Against a typical 0.80 accept threshold, a morning score of 0.93 lands between 0.73 and 0.83: good parts straddle the threshold all afternoon, and a few percent reject. When the same part's score swings between conditions, the correlation — not the threshold — is the fault.
What an edge based matcher scores instead
An edge based, or geometric, matcher computes the intensity gradient at every pixel, keeps the points where that gradient is strong, and stores each point's gradient direction. The template stops being a picture and becomes a list of edge points with directions. Matching finds the position and rotation that land the largest fraction of model edges onto image edges with matching direction — a direction tolerance near ±30° is a good default — and reports that fraction as the score.
Why lighting change stops mattering is short enough to write down:
Gradient direction is exactly invariant to gain and offset. Uneven change bites only where local contrast collapses to the noise floor, and there gradient direction goes random. A geometric score moves a point or two across a 20-30% uneven shift that moved a correlation score by ten.
Three properties matter as much on the line:
- Occlusion tolerance. With a third of the contour hidden by a fixture or a neighbouring part, the missing third simply does not vote and the score holds.
- Rotation and scale. The model can be searched over ±180° and a scale range; correlation needs one template per pose.
- Appearance independence. An oiled part and a dry part produce nearly the same edge map and very different gray histograms.
The costs are speed and contrast. Gradient extraction plus geometric search runs longer than plain correlation; current vision sensors handle it at line rates, but budget for it on large fields. And with no contrast there is no gradient: a washed-out image degrades a geometric matcher exactly the way it degraded correlation.
Switch the algorithm, fix the light, or both
Fix the light first: a stable image improves every algorithm on the station, including the defect tools downstream. Then switch matchers if appearance varies for reasons you cannot light away.
| Symptom | First move | Why |
|---|---|---|
| Score drops in daylight hours or between shifts | Lock exposure, strobe the light, hood the station | Ambient light is the input; the algorithm was never at fault |
| Score varies part to part within one shift | Switch to geometric matching | Finish varies; the geometry does not |
| Good parts matched at 180° or mirrored poses | Tighten angle tolerance and edge polarity | A pose-control fault, not an illumination fault |
| New material lots monthly, plus daylight drift | Do both | The geometry absorbs the lots, the locked light absorbs the day |
The committed rule: lock the lighting and re-measure when good-part scores vary more than 0.05 between morning and afternoon. Switch the matcher when they still vary more than 0.05 part to part inside a single shift. Rotated false hits are a separate fault with a known fix — pattern match flips through 180 degrees covers the tolerance settings.
Lock the lighting so the score has nothing to track
Four settings do most of the work, in this order:
- Disable auto exposure and auto gain. Set a fixed exposure time and 0 dB gain. Auto exposure converts a lighting problem into a moving template: as gain chases the afternoon sun, the image drifts with it. The exposure and gain balance guide covers where to set them, and auto-exposure ROI instability shows the failure mode when the metering region follows the part.
- Strobe the light from a controller at fixed current and pulse width. A 0.5 ms pulse in a 100 ms cycle is 0.5% duty, so continuous window light contributes about half a percent of what the sensor sees — and its daily drift with it.
- Use diffuse geometry. Two diffused bar lights aimed from opposite sides at 30-45° average out part tilt and finish variation; a dome does the same for small curved parts. The illumination geometry guide maps the choices, and lighting shiny metal parts handles the specular cases where diffusion alone still glares.
- Pick the colour for contrast. The wavelength that separates part from background buys score margin that no algorithm can manufacture; the LED colour contrast guide gives the selection rule.
For a single station, a diffused white bar light from the bar lights range — start in the light finder — is the workhorse:
- Size
- 200-400 mm
- Type
- Diffused
- Voltage
- 24 V
The LS-BAR-1276 is a diffused white bar light, 372 x 28 mm on 24 V. Two of them, angled from either side of the nest, deliver the near-flat illumination both matching methods like. Intensity-driven tools fail the same way when light drifts; color detection that depends on stable lighting shows the production consequences in a concrete case.
Worked example: bracket nest, 60 mm field of view, one smart camera
The case: a 48 mm stamped steel bracket with two 6 mm holes, nested at fixed height within ±3 mm, finish alternating between oiled and dry lots. The fault, measured across two shifts: grayscale score 0.93 at 06:00, 0.71 at 15:00 with low sun across half the nest, accept threshold 0.80, about 4% of good parts rejected every afternoon.
Inputs:
- Camera: LS-SMC-0017 — 8.8 MP, C-mount, 1" sensor format, global shutter, matching on the device.
- Lens: LS-FFL-0567 — 16 mm, rated for 1.1" sensors at 20 MP, F2.8-22, distortion under 0.3%.
- Light: two diffused bar lights on a strobing controller.
- Margins: the 48 mm bracket plus 20% margin gives a 60 mm field of view.
Rules, in words: magnification is sensor width over field of view; working distance follows from focal length and magnification; object pixel is field of view over pixel count; depth of field follows from f-number and acceptable blur.
The arithmetic:
- A 1" optical-format sensor is about 12.8 mm wide, so m = 12.8 / 60 = 0.213.
- WD = 16 mm × 1.213 / 0.213 = 91 mm. Mount the camera there.
- 8.8 MP in a 16:9 frame is about 4000 pixels across: 12.8 mm / 4000 ≈ 3.2 µm pixels, and an object pixel of 60 mm / 4000 px = 15 µm.
- Each 6 mm hole spans 400 px, and its edge locates to about a tenth of a pixel — 1.5 µm — far past what this task needs. The edge position accuracy estimate explains that sampling limit.
- Exposure: a 500 µs strobe, with the part settling at about 20 mm/s, gives blur = 20 mm/s × 0.0005 s = 10 µm, inside the 15 µm one-pixel budget.
- Duty: 0.5 ms in a 100 ms cycle is 0.5%, so window light is half a percent of the signal and cannot move the score.
The f-number comes last. Acceptable blur c = 2 px = 30 µm object side. At F4, DOF = 2 × 0.030 × 4 × 1.213 / 0.213² ≈ 6.4 mm, or ±3.2 mm — the nest tolerance with no margin. At F5.6, DOF ≈ 9.0 mm, or ±4.5 mm. Run F5.6: hold the 500 µs strobe and raise the current; if the light is already at maximum, use F4 and shim the nest to hold ±2.5 mm.
Rebuild the model as an edge model taught on a dry part, angle search ±10° (the nest holds orientation within ±5°), accept 0.70, review clamp 0.45. Scored across two shifts and both finishes, the result was 0.90 ± 0.02 from 06:00 to 15:00, with afternoon false rejects below 0.1%. If the score still moves more than 0.05 after this, light is still reaching the nest — find it before touching any tolerance.
Choosing the platform that runs the matcher
One camera and one match: a smart camera with onboard geometric matching removes the PC, the frame grabber and a layer of wiring. Template banks in the hundreds, sensors in the tens of megapixels, or scoring fused with custom processing: a PC-based library gives the room. The optics arithmetic above does not change either way.
Three platforms cover most single-station jobs:
| Specification | LS-SMC-0017 | MV-SC5060XM-08M-WBN | LS-SMC-0063 |
|---|---|---|---|
| Power supply | 12 V~24 V | 24 VDC | 9-26 V DC 2 A |
| Weight | <500 g | Approx. 370 g (0.8 lb.) | <350 g |
| Storage temperature | -30 to 60 °C | – | -30 to 70 °C |
| Sensor type | 1" CMOS | CMOS, rolling shutter | – |
| Pixel size | 3.45 μm | 2 μm × 2 μm | – |
| Memory | SC: 2G (optional 4G) / SC(E): 4G | 8 GB | – |
| Resolution | – | 3200 × 1920 | 1440x1080 |
| Max. frame rate | – | 15 fps | 60 fps |
| Data interface | – | Gigabit Ethernet (1000 Mbit/s) | GigE |
| Digital I/O | – | 12-pin M12 connector provides power and I/O, including opto-isolated input × 3 (Line 0/1/2), opto-isolated output × 3 (Line 3/4/5), RS-232 × 1 | RS232, 2 Opto-isolated inputs, 3 Opto-isolated outputs |
| Power consumption | – | Avg. 12.3 W @ 24 VDC (with included light source on); Max. 48 W @ 24 VDC (with included light source on) | <18 W |
| Ingress protection | – | IP67 (under proper installation of waterproof lens cap) | IP65 |
| Price | $1,359.00 | $1,629.00 | $1,110.00 |
Values as printed in each product's data sheet; open a part for its drawing and full specifications.
The LS-SMC-0017 from the worked example takes C-mount glass, so the full machine vision lenses range and the lens finder apply. The MV-SC5060XM-08M-WBN is a 6 MP mono model with an 8 mm M12 lens: fixed geometry, nothing to choose. The LS-SMC-0063 is a 1.6 MP unit with a 16 mm lens and its own polarized white light at 60 fps, which suits small parts where an external light pair will not fit. More options in smart cameras and the camera finder.
Match the lens to the sensor with margin, as in the example: it costs nothing in score and keeps the frame corners sharp.
When edge based matching is the wrong answer
- Feature-poor surfaces. A geometric matcher needs edges and corners to vote with. A plain flat face, a smooth cylinder shot end-on, a featureless label: nothing to align. The method fails when the target holds few or no interesting points, a limit inherent to it rather than to any implementation. Silhouette the part on a backlight and gauge the outline instead — collimated backlight edge gauging covers that geometry.
- Gray-level defects. A stain, a colour shift or a missing coating is not an edge; the matcher locates the part perfectly and never sees the defect. Pair the locator with a gray-level or colour tool, as color pattern matching for localization shows.
- Heavy occlusion. A third of the contour hidden is workable; past half, scores fall through any fixed threshold. Move the camera or the fixture rather than loosening the accept score.
- Specular curved parts. Gradients exist but travel with part tilt, so the edge map changes pose to pose. Cross-polarize or dome the part first — cross polarization against surface glare has the set-up.
False rejects that survive both fixes usually have a different root cause: false rejects in PCB solder inspection and dust-driven false rejects in glass inspection both walk the same cause-versus-threshold split.
A ten-minute stability audit before you commit
- Auto exposure off, auto gain off; exposure time and gain written into the recipe.
- Strobe duty at or below 1%; the mean of a blank patch moves less than ±2 DN between morning and afternoon.
- The weakest edge you must match steps at least 30 DN across 2-3 pixels.
- The model holds at least 50 edge points; angle search equals the fixture's real tolerance — ±10° for a nest, ±180° for free-arriving parts.
- Accept score sits at least 0.10 below the worst good-part score from a 100-part, two-shift histogram; review clamp halfway between the two.
- Position repeatability over 30 repeats of one part: better than a fifth of a pixel.
- A hood over the station, with no line of sight to windows, bays or neighbouring strobes.
Build the station in one pass from the light step, or send a pair of morning and afternoon images through expert support and we will read the drift with you. More station build-outs sit on the applications topic page.
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.
Questions
How much illumination change can normalized grayscale correlation tolerate?
An even change, any size: the mean and standard-deviation normalization divides global gain and offset out before scoring, so a uniform 30% drop leaves the score untouched. An uneven change is the killer — budget 10-20 score points lost per 20-30% of spatial variation. The diagnostic split: shadow the station and re-run; if the score recovers, ambient light was the cause. If it recovers only with a fresh template, appearance is the cause, and appearance is the case that needs geometric matching, because no lighting budget fixes a lot-to-lot finish change.
Does edge based matching work in low light or at low contrast?
Down to the contrast floor, and no further. The matcher votes with gradient direction, and direction goes random when the edge step approaches the noise floor. The faintest edge the matcher must find should still rise at least 30 DN across 2-3 pixels. If you are short of light, lengthen the strobe pulse first: doubling the pulse doubles the edge step in DN, and your blur budget is one object pixel of motion to spend. Below that floor, add light or open the aperture — the algorithm cannot invent gradients.
Can a smart camera run geometric matching, or do I need a PC?
A current smart camera runs geometric matching on the device at line rates; the worked example above does exactly that on an 8.8 MP unit. Go to a PC-based library when you need template banks in the hundreds, sensors in the tens of megapixels, scoring fused with custom processing, or heavy pre-processing before the match. One station with one or a handful of templates stays cleaner on the camera: no frame grabber, no PC in the cabinet, one cable to the PLC.
Should I retrain the template when the light changes, instead of switching algorithms?
Retraining treats the symptom, and every retrain risks quietly accepting a bad part. Retrain only when the part geometry itself changes. As a stopgap, build a three-template library — morning, afternoon and the worst finish lot — and match against all three; it buys weeks, not a cure. Then track which template wins each shift: if it is not the same one every time, the lighting is still moving, and the durable fix is locked exposure with strobed diffuse light.
What match score and tolerances should I start with?
Start at accept 0.70 with a review clamp at 0.45, angle search matched to the fixture — ±10° in a nest, ±180° where parts arrive free — and edge direction tolerance near ±30°. Then move the accept score onto data: 0.10 below the worst good-part score from a two-shift histogram. Two settings matter more than people expect: edge polarity, so a bright-on-dark edge never matches a dark-on-bright one, and image sub-sampling, which buys speed for a point or two of score.
Do polarization or dome lights help matching stability?
On shiny parts, decisively. A specular highlight travels with part tilt, so the edge map changes pose to pose; cross-polarization removes the highlight and freezes the edge map, and a dome does the same for small curved parts. A dome loses some light through its camera aperture, so lengthen the strobe to hold your 30 DN edge steps. Matte parts under diffused bars gain little from polarization — spend that budget on light output or a better lens instead.
