Object Detection, box by box


Look for
Noise
Window stride
Keep scores above
NMS: suppress if IoU >
1. Slide the window
2. Clean up (NMS)
Show
What the detector sees: one brightness per pixel. Dashed boxes, once NMS is done, mark where the real animals are.

How well does this window match?

template
vs
window

IoU: how much do two boxes overlap?

 

The whole idea.
A detector has to answer two questions: is there a cat? and where, exactly? The oldest way to do it is the one on this page. Take a small picture of a cat — the template — and slide it over the image exactly like the filter on the edge-detection page, one position at a time. At every position, score how well the window under it matches. Any window that scores above the cut-off becomes a box.

The score here is normalized correlation: subtract the average brightness from the window and from the template, then measure how closely the two patterns agree. It runs from +1 (identical pattern) through 0 (unrelated) to −1 (the exact negative), and it does not care whether the window is brighter or darker overall.

The problem the sweep leaves behind.
A window one or two pixels away from a cat still mostly covers the cat, so it scores almost as high. Every cat ends up wrapped in a pile of nearly identical boxes. Non-max suppression cleans that up with one rule, repeated: keep the highest-scoring box left, then delete every box that overlaps it by more than a set amount. The overlap is measured as IoU — the area the two boxes share, divided by the area they cover together. Identical boxes have IoU 1; boxes that do not touch have IoU 0.

How a modern detector differs.
YOLO, Faster R-CNN and the rest replace the hand-made template with a CNN that has learned what cats look like, and they predict box sizes instead of using one fixed window. But they still produce a pile of overlapping boxes, and most of them still clean it up with exactly this NMS step.

Things worth trying:
1. Press Score everything at once and count the pile: 19 boxes for three cats, each cat buried under a stack of its own. Then Run NMS to the end. Each stack collapses to one box.

2. Now slide the IoU limit down to 0.05 and run NMS again. The two cats sitting side by side become one: their boxes overlap by only 0.11, but that is more than 0.05, so keeping one deletes the other. Slide it up to 0.95 and the opposite happens — all 19 boxes survive, because even boxes one pixel apart overlap by only 0.90.

3. Look at the big cat. The template has one fixed size, and a cat drawn larger does not match it — its best window scores 0.43, well under the cut-off. Older detectors fixed this by shrinking the picture again and again and sliding the same window over every size; modern ones learn to predict the box size directly.

4. Pull the score cut-off down to 0.50 and both dogs get boxes; at 0.45 the ball does too. That is the trade every detector makes: a lower cut-off catches more of what you want, and more of what you don’t.