PIXELBANKv9.1.0
Menu

Canny Hysteresis Thresholding

Given an NMS edge map (2D matrix of magnitudes) and two thresholds (high, low), apply hysteresis thresholding to produce a binary edge map.

Algorithm:

  1. Strong edges: pixels with magnitude >high> \text{high} → mark as edge (1)
  2. Weak edges: pixels with low<magnitude≤high\text{low} < \text{magnitude} \leq \text{high}
  3. Suppressed: pixels with magnitude ≤low\leq \text{low} → non-edge (0)
  4. Connectivity check: Weak edges that are connected to strong edges (8-connectivity) become strong edges. Use BFS/DFS to propagate from strong edges to connected weak edges.

Return a binary edge map where 1 = edge, 0 = non-edge.

Example:

Input:
edge_map = [[10, 5, 2], [3, 15, 8], [1, 6, 12]]
high = 9, low = 4
Output:
[[1, 1, 0], [0, 1, 1], [0, 1, 1]]
Reasoning:
  • Initially, we mark pixels with magnitude >high> \text{high} (99) as strong edges (1) and pixels with magnitude ≤low\leq \text{low} (44) as non-edges (0), resulting in:
    • Strong edges: (1,2)(1,2) with magnitude 1515, (1,0)(1,0) with magnitude 1010, (2,2)(2,2) with magnitude 1212
    • Non-edges: (0,2)(0,2) with magnitude 22, (1,0)(1,0) is an edge, (2,0)(2,0) with magnitude 11
  • We then identify weak edges with 4<magnitude≤94 < \text{magnitude} \leq 9: (0,1)(0,1) with magnitude 55, (1,2)(1,2) is already marked as an edge, (2,1)(2,1) with magnitude 66
  • Next, we apply the connectivity check:
    • (0,1)(0,1) is connected to (1,0)(1,0) (strong edge), so it becomes a strong edge
    • (2,1)(2,1) is connected to (2,2)(2,2) (strong edge), so it becomes a strong edge
    • (1,2)(1,2) is already marked and (2,0)(2,0) is not connected to any strong edge
  • The final output is: [[1, 1, 0], [0, 1, 1], [0, 1, 1]]

Constraints:

  • edge_map is a 2D list of non-negative magnitudes
  • high > low >= 0
  • Use 8-connectivity (all 8 neighbors)
  • Return binary 2D list (0 or 1)
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Canny Hysteresis Thresholding - Hard | PixelBank