PIXELBANKv9.1.0
Menu

Feature NMS (Non-Maximum Suppression)

You are given a response map from a corner detector and need to apply non-maximum suppression to keep only local maxima as feature points.

Non-maximum suppression ensures that detected features are well-distributed and don't cluster together. A pixel is kept as a feature only if it's the strict maximum in its local neighborhood.

The algorithm:

  1. For each pixel in the response map
  2. Compare it to all neighbors within a window of size window_size × window_size
  3. If the pixel's value is strictly greater than ALL neighbors, it's a local maximum
  4. Return coordinates of all local maxima

A strict maximum means: pixel_value > all_neighbor_values (not ≥)

Example:

Input:
response_map = [[1, 2, 1],
                [2, 5, 2],
                [1, 2, 1]]
window_size = 3
Output:
[(1, 1)]
Reasoning:

Checking each pixel against its neighbors (3×3 window):

  • (0,0)=1: neighbors include 2,2,5 → not a max
  • (0,1)=2: neighbors include 5 → not a max
  • (0,2)=1: neighbors include 2,5,2 → not a max
  • (1,0)=2: neighbors include 5 → not a max
  • (1,1)=5: neighbors are [1,2,1,2,2,1,2,1] → max is 2 < 5 ✓ LOCAL MAX
  • (1,2)=2: neighbors include 5 → not a max
  • (2,0)=1: neighbors include 2,5,2 → not a max
  • (2,1)=2: neighbors include 5 → not a max
  • (2,2)=1: neighbors include 2,5,2 → not a max

Only (1,1) is a local maximum.

Constraints:

  • response_map is a 2D array of corner responses
  • window_size is an odd number (3, 5, 7, etc.)
  • Return list of (row, col) tuples for all local maxima
  • Order: top-to-bottom, left-to-right
solution.py

Test Results

0/0
Run code to see test results.