Task 2 of 5

The Score That Lies

Now break it. brightScene is the same scene photographed in brighter light: every value 0.28 higher, nothing moved, nothing changed shape. The patch is still exactly where it was. Run the same kernel over it — the kernel is not what is wrong here — and the best match walks off to a completely different place.

Here is why, in one line of algebra. Add δ to every scene value and the score at a window becomes

SSD(w + δ, t) = SSD(w, t)
              + 2δ · sum(wᵢ − tᵢ)
              + n · δ²

At the true match the pixels agree, so sum(wᵢ − tᵢ) is zero and there is nothing to offset the last term: a perfect match now scores 64 × 0.28² = 5.02. Meanwhile any window that is darker than the template has a negative sum(wᵢ − tᵢ), and the middle term pays it a discount. Somewhere in this scene sits a patch that is dark and matches badly; brighten the picture and its discount beats a perfect match outright.

That is the whole lesson of this module, and it is not really about vision. SSD is not a measure of similarity — it is a measure of distance in absolute value, and every camera, every light, every exposure, every gain setting moves absolute values around. A score that cannot tell "brighter" from "different" will confidently point at the wrong thing.

the same two windows, before and after somebody turned the lights up
Goal: score both scenes with the same SSD kernel and show the damage — log where each one thinks the patch is, and the two bright-scene scores that explain it.

Requirements

Hint 1 — nothing about the kernel changes

Same kernel, called twice. brightScene has exactly the same shape as scene, so the second call costs you one line.

Hint 2 — reading a known cell

The map is indexed map[y][x], so the score the bright map gives the true position is brightMap[TRUE_Y][TRUE_X]. Compare it against bestMatch(brightMap).score.

Same idea elsewhere

Every practitioner meets this wall. It is why OpenCV ships TM_CCOEFF_NORMED alongside TM_SQDIFF, why stereo matchers use census transforms or rank filters instead of raw differences, and why "we normalised the inputs and the model started working" is the most common debugging story in machine learning. A raw difference is a distance in whatever units the sensor happened to produce.

All tasks in Template Matching

  1. Score Every Position at Once
  2. The Score That Lies
  3. Normalize It
  4. Hoist What Never Changes
  5. Payoff: Present or Absent?

This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.