PIXELBANKv9.1.0
Menu

You are given an edge magnitude image (after NMS) and need to apply hysteresis thresholding to produce final binary edges.

Hysteresis uses two thresholds:

  • Strong edges: magnitude > high_threshold β†’ definitely edges
  • Weak edges: low_threshold < magnitude ≀ high_threshold β†’ edges only if connected to strong edges
  • Non-edges: magnitude ≀ low_threshold β†’ not edges

The algorithm:

  1. Mark all strong edge pixels
  2. Starting from each strong edge, propagate to connected weak edges using 8-connectivity
  3. Output: 1 for edges, 0 for non-edges

This two-threshold approach reduces noise while preserving edge continuity.

Example:

Input:
edges = [[0, 10, 0],
        [0, 50, 0],
        [0, 10, 0]]
low_thresh = 5
high_thresh = 30
Output:
[[0, 1, 0], [0, 1, 0], [0, 1, 0]]
Reasoning:
  1. Classify pixels:

    • (0,1)=10: 5 < 10 ≀ 30 β†’ weak
    • (1,1)=50: 50 > 30 β†’ strong
    • (2,1)=10: 5 < 10 ≀ 30 β†’ weak
    • All others = 0: ≀ 5 β†’ non-edge
  2. Mark strong edges:

    • (1,1) is strong β†’ set to 1
  3. Propagate to connected weak edges:

    • (0,1) is adjacent to (1,1) β†’ set to 1
    • (2,1) is adjacent to (1,1) β†’ set to 1
  4. Final result: column 1 is all edges

Constraints:

  • edges is the NMS edge magnitude image
  • low_thresh and high_thresh define the hysteresis thresholds
  • Return binary edge map (0 or 1)
  • Use 8-connectivity for edge linking
πŸ”’

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.
Hysteresis Thresholding - Medium | PixelBank