COMPUTER VISION

Sliding Window Detection: Exhaustive Search, Pyramids and NMS

Sliding window exhaustively classifies every fixed-size crop of an image. Image pyramids handle scale variation. Non-maximum suppression collapses duplicate detections into one.

1The Exhaustive Search Problem

Object detection must answer: where are the objects? Unlike classification (one label per image), detection requires finding every instance at an unknown location. The brute-force solution is simple: slide a fixed-size window across the entire image, run a classifier on each crop, and report every location that scores above a threshold. This is exactly what the Viola-Jones face detector (2001) and the HOG+SVM pedestrian detector (Dalal & Triggs, 2005) did, and they were state-of-the-art for nearly a decade.

Classic pipeline: (1) Compute HOG features for the image. (2) Slide a 128×64 (person-sized) window at every position with stride s. (3) Extract the HOG descriptor for that crop. (4) Run it through a linear SVM. (5) If score > threshold, record the bounding box + score. (6) Apply NMS to remove duplicates. This pipeline is fully deterministic and interpretable, but slow: O(H × W / s²) classifier calls per pyramid level.

2Image Pyramids for Multi-Scale Detection

A fixed window finds objects only at one size. A person 2 metres away occupies fewer pixels than one 1 metre away. The solution is an image pyramid: repeatedly downsample the image by a scale factor (typically 0.75 or 0.5) and run the same fixed-size window at each level. The window effectively sees the object at progressively larger scales. A bounding box detected at pyramid level k is rescaled by 1/scale^k to map back to original image coordinates.

Pyramid construction
Start at full resolution. Multiply both dimensions by scale (e.g., 0.75) each step. Stop when image is smaller than the window. A 640×480 image with scale 0.75 produces roughly 5 levels before a 128×128 window no longer fits.
Total windows
Summing across all pyramid levels, a typical setup produces thousands of candidate windows. Each requires a full feature extraction + classifier call. This is why CNN-based detectors replaced sliding window: they share computation across all positions via convolution.

3Non-Maximum Suppression (NMS)

A detected object triggers high scores at many adjacent windows — all slightly overlapping boxes around the same person. NMS reduces these to a single best box. The algorithm is greedy: sort all detections by score descending, keep the highest-scoring box, suppress (remove) all other boxes whose Intersection-over-Union (IoU) with the kept box exceeds a threshold (typically 0.5), then repeat on the remaining boxes.

NMS step-by-step: (1) Compute score for each candidate box. (2) Sort boxes by score, highest first. (3) Take the top box — it's a confirmed detection. (4) Compute IoU between it and all remaining boxes. (5) Discard any box with IoU > 0.5 (they overlap the same object). (6) Move to the next surviving box and repeat. Result: one box per distinct object, the highest-confidence one. IoU = area of intersection / area of union.

4Why Modern Detectors Replaced Sliding Window

Sliding window is conceptually clean but computationally redundant: adjacent windows share almost all pixels yet each is processed independently. Modern detectors eliminate this waste with shared convolutional features.

R-CNN (2014)
Run selective search to get ~2000 region proposals first, then warp each to fixed size and run CNN. 2000 forward passes per image — still slow.
Fast R-CNN / Faster R-CNN
Compute feature map once for the full image. For each region proposal, use RoI Pooling to extract a fixed-size feature from the shared map — no redundant computation.
YOLO / SSD (2016+)
One forward pass predicts all boxes simultaneously. Anchor boxes at every spatial position and scale replace the pyramid entirely. Real-time at 30+ FPS on GPU.

Related

Sliding window: count candidates across strides and pyramid levels

Recall check

0 of …

Say the answer out loud before revealing — recalling is what makes it stick. ➜ Next: VGGNet and InceptionNet

  1. Why does sliding window detection need image pyramids?

  2. What does Non-Maximum Suppression (NMS) solve?

  3. What is the computational problem with sliding window detectors?

  4. How do YOLO/SSD differ from sliding window?