Skip to content

Instantly share code, notes, and snippets.

@FienSoP
Created January 16, 2019 10:42
Show Gist options
  • Save FienSoP/e9eb26c0a923dc7566304c734d13decd to your computer and use it in GitHub Desktop.
Save FienSoP/e9eb26c0a923dc7566304c734d13decd to your computer and use it in GitHub Desktop.
def threshold(img, lowThresholdRatio=0.05, highThresholdRatio=0.09):
highThreshold = img.max() * highThresholdRatio;
lowThreshold = highThreshold * lowThresholdRatio;
M, N = img.shape
res = np.zeros((M,N), dtype=np.int32)
weak = np.int32(25)
strong = np.int32(255)
strong_i, strong_j = np.where(img >= highThreshold)
zeros_i, zeros_j = np.where(img < lowThreshold)
weak_i, weak_j = np.where((img <= highThreshold) & (img >= lowThreshold))
res[strong_i, strong_j] = strong
res[weak_i, weak_j] = weak
return (res, weak, strong)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment