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:
- Strong edges: pixels with magnitude → mark as edge (1)
- Weak edges: pixels with
- Suppressed: pixels with magnitude → non-edge (0)
- 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
edge_map = [[10, 5, 2], [3, 15, 8], [1, 6, 12]] high = 9, low = 4
[[1, 1, 0], [0, 1, 1], [0, 1, 1]]
- Initially, we mark pixels with magnitude () as strong edges (1) and pixels with magnitude () as non-edges (0), resulting in:
- Strong edges: with magnitude , with magnitude , with magnitude
- Non-edges: with magnitude , is an edge, with magnitude
- We then identify weak edges with : with magnitude , is already marked as an edge, with magnitude
- Next, we apply the connectivity check:
- is connected to (strong edge), so it becomes a strong edge
- is connected to (strong edge), so it becomes a strong edge
- is already marked and 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)