v9.1.1
Menu

Feature NMS (Non-Maximum Suppression)

mediumFREEFeature DetectorsFeaturesCV: Feature Detection and Matching

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 ≥)

At the borders, window positions that fall outside the map are ignored: only neighbors that actually exist are compared, so edge and corner pixels can also be local maxima.

Example

Input
response_map = [[1, 2, 1],
                [2, 5, 2],
                [1, 2, 1]]
window_size = 3
Output
[(1, 1)]
Reasoning
  • response_map is a 3×33 \times 3 grid of corner strengths and window_size is 33, so each pixel's neighbourhood is the 3×33 \times 3 block centred on it: everything within ⌊3/2⌋=1\lfloor 3/2 \rfloor = 1 row and column.
  • The centre (1, 1) holds 55. Its eight neighbours are 1,2,1,2,2,1,2,11, 2, 1, 2, 2, 1, 2, 1, at most 22. Since 5>25 > 2, it is a local maximum.
  • Every edge pixel, such as (0, 1) with value 22, has the 55 inside its window. It fails to beat that neighbour, so it is suppressed.
  • Near the border the window hangs off the map, and those missing cells simply are not neighbours. Corner (0, 0) has only three real neighbours, 2,2,52, 2, 5, and loses.
  • Only one pixel survives, so the answer is [(1, 1)], written as (row, column).
  • Notice the comparison is strict: a map of all 11s returns an empty list because no pixel beats its equal neighbours, while a map with 55 in each corner and 00 elsewhere keeps all four corners.

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

Learn this in

More from CV: Feature Detection and Matching

solution.py

Test results

Sign in to run your code against the test cases.