Skip to content
DeepForgeby svx
All problems
HardComputer Visioncv-075

Hysteresis Thresholding

Problem

Connect weak edge pixels to strong ones with hysteresis thresholding.

Pixels with value >= high are strong (255). Pixels with low <= value < high are weak candidates and become 255 only when 8-connected to a strong pixel (directly or through other weak pixels); all other pixels become 0.

Hint

Seed a flood fill from every strong pixel and only walk onto weak pixels.

Test cases

case 1
in: [[[0,9,5]],5,9]
expected: [[0,255,255]]
case 2
in: [[[0,5,0]],5,9]
expected: [[0,0,0]]
case 3
in: [[[5,5,9]],5,9]
expected: [[255,255,255]]
case 4
in: [[[0,0,0,0,0],[0,5,5,0,0],[0,5,0,0,0],[0,0,0,5,9],[0,0,0,0,0]],5,9]
expected: [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,255,255],[0,0,0,0,0]]
Starter codePython
def hysteresis_threshold(image, low, high):
    # Your code here
    pass

4 test cases · run your code against them in the editor