I am trying to get the orientation of the edges detected using the Sobel filter. However, the angle of the pixels kept overlapping. For example, in this image: , the descending slopes have 2 colors, indicating 2 different angle values.
Here is the original image
Here is my code:
import cv2
import numpy as np
import matplotlib.pyplot as plt
EDGE_CHARS = ['_', '|', '/', '\']
image = cv2.imread("test/3.png")
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY).astype(np.uint8)
sigma = 1
k = 2
blur1 = cv2.GaussianBlur(image, (0, 0), sigma)
blur2 = cv2.GaussianBlur(image, (0, 0), sigma * k)
dog = cv2.subtract(blur2, blur1)
gx = cv2.Sobel(dog, cv2.CV_64F, 1, 0) # Gradient in X direction
gy = cv2.Sobel(dog, cv2.CV_64F, 0, 1) # Gradient in Y direction
angle = (np.arctan2(gy, gx) / np.pi) * 0.5 + 0.5
angle = np.floor(angle * len(EDGE_CHARS)).astype(int)
angle = cv2.medianBlur(angle.astype(np.uint8), 5)
plt.imshow(angle)
plt.colorbar()
plt.show()