Skip to content

Instantly share code, notes, and snippets.

@FienSoP
Last active October 11, 2019 13:48
Show Gist options
  • Save FienSoP/b2612c4b8aa519fc4559749c1c2c7f02 to your computer and use it in GitHub Desktop.
Save FienSoP/b2612c4b8aa519fc4559749c1c2c7f02 to your computer and use it in GitHub Desktop.
def hysteresis(img, weak, strong=255):
M, N = img.shape
for i in range(1, M-1):
for j in range(1, N-1):
if (img[i,j] == weak):
try:
if ((img[i+1, j-1] == strong) or (img[i+1, j] == strong) or (img[i+1, j+1] == strong)
or (img[i, j-1] == strong) or (img[i, j+1] == strong)
or (img[i-1, j-1] == strong) or (img[i-1, j] == strong) or (img[i-1, j+1] == strong)):
img[i, j] = strong
else:
img[i, j] = 0
except IndexError as e:
pass
return img
@tuanhanhdmprof
Copy link

In canny algorithm: "This can be done by starting at the known edge pixels and moving in all eight directions recursively until the gradient magnitude is less than or equal to the low threshold". I don't see recursive here. Can you explain your code when you determine eight directions of current pixel without considering from "sure-edge" pixel ?

@xarshila
Copy link

i think here is mistake, for each neigbours you must do this checking recursively

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment