Created
January 16, 2019 09:53
-
-
Save FienSoP/03ed9b0eab196dde7b66f452725a42ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def non_max_suppression(img, D): | |
M, N = img.shape | |
Z = np.zeros((M,N), dtype=np.int32) | |
angle = D * 180. / np.pi | |
angle[angle < 0] += 180 | |
for i in range(1,M-1): | |
for j in range(1,N-1): | |
try: | |
q = 255 | |
r = 255 | |
#angle 0 | |
if (0 <= angle[i,j] < 22.5) or (157.5 <= angle[i,j] <= 180): | |
q = img[i, j+1] | |
r = img[i, j-1] | |
#angle 45 | |
elif (22.5 <= angle[i,j] < 67.5): | |
q = img[i+1, j-1] | |
r = img[i-1, j+1] | |
#angle 90 | |
elif (67.5 <= angle[i,j] < 112.5): | |
q = img[i+1, j] | |
r = img[i-1, j] | |
#angle 135 | |
elif (112.5 <= angle[i,j] < 157.5): | |
q = img[i-1, j-1] | |
r = img[i+1, j+1] | |
if (img[i,j] >= q) and (img[i,j] >= r): | |
Z[i,j] = img[i,j] | |
else: | |
Z[i,j] = 0 | |
except IndexError as e: | |
pass | |
return Z |
Thankyou for your code, I've tried them but then I got this error, can you tell me whats wrong with this?
TypeError Traceback (most recent call last) in 9 gaussian_kernel(size=5, sigma=1) 10 sobel_filters(img=image) ---> 11 non_max_suppression(img=image, D=3/4) 12 threshold(img=image,lowThresholdRatio=0.05,highThresholdRatio=0.09) 13 hysteresis(img=threshold, weak=0, strong=255)
in non_max_suppression(img, D) 4 Z = np.zeros((M,N), dtype=np.int32) 5 angle = D * (180. / np.pi) ----> 6 angle[angle < 0] += 180 7 8
TypeError: 'float' object is not subscriptable
I am facing same issue. Have you figured out the issue present in this script?
how to show the result? I make this in google colab
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thankyou for your code, I've tried them but then I got this error, can you tell me whats wrong with this?
TypeError Traceback (most recent call last) in
9 gaussian_kernel(size=5, sigma=1)
10 sobel_filters(img=image)
---> 11 non_max_suppression(img=image, D=3/4)
12 threshold(img=image,lowThresholdRatio=0.05,highThresholdRatio=0.09)
13 hysteresis(img=threshold, weak=0, strong=255)
in non_max_suppression(img, D)
4 Z = np.zeros((M,N), dtype=np.int32)
5 angle = D * (180. / np.pi)
----> 6 angle[angle < 0] += 180
7
8
TypeError: 'float' object is not subscriptable