I have tried implementing a basic version of shi-tomasi corner detection algorithm. The algorithm works fine for corners but I came across a strange issue that the algorithm also gives high values for slanted(titled) edges.
Here's what i did
- Took gray scale image
- computer dx, and dy of the image by convolving it with sobel_x and sobel_y
- Took a 3 size window and moved it across the image to compute the sum of the elements in the window.
- computed sum of the window elements from the dy image and sum of window elements from the dx image and saved it in sum_xx and sum_yy.
- created a new image (call it
result) where that pixel for which the window sum was computed was replaced withmin(sum_xx, sum_yy)as shi-tomasi algorithm requires.
I expected it to give maximum value for corners where dx and dy both are high, but i found it giving high values even for titled edges.
Here are the some outputs of the image i received:

so far so good, corners have high values.
Here's where the problem lies. edges have high values which is not expected by the algorithm. I can't fathom how can edges have high values for both x and y gradients (sobel being close approximation of gradient).
I would like to ask your help, if you can help me fix this issue for edges. I am open to any suggestions and ideas .
Here's my code (if it helps):
def st(image, w_size):
v = []
dy, dx = sy(image), sx(image)
dy = dy**2
dx = dx**2
dxdy = dx*dy
dx = cv2.GaussianBlur(dx, (3,3), cv2.BORDER_DEFAULT)
dy = cv2.GaussianBlur(dy, (3,3), cv2.BORDER_DEFAULT)
dxdy = cv2.GaussianBlur(dxdy, (3,3), cv2.BORDER_DEFAULT)
ofset = int(w_size/2)
for y in range(ofset, image.shape[0]-ofset):
for x in range(ofset, image.shape[1]-ofset):
s_y = y - ofset
e_y = y + ofset + 1
s_x = x - ofset
e_x = x + ofset + 1
w_Ixx = dx[s_y: e_y, s_x: e_x]
w_Iyy = dy[s_y: e_y, s_x: e_x]
w_Ixy = dxdy[s_y: e_y, s_x: e_x]
sum_xx = w_Ixx.sum()
sum_yy = w_Iyy.sum()
sum_xy = w_Ixy.sum()
#sum_r = w_r.sum()
m = np.matrix([[sum_xx, sum_xy],
[sum_xy, sum_yy]])
eg = np.linalg.eigvals(m)
v.append((min(eg[0], eg[1]), y, x))
return v
def sy(img):
t = cv2.Sobel(img,cv2.CV_8U,0,1,ksize=3)
return t
def sx(img):
t = cv2.Sobel(img,cv2.CV_8U,1,0,ksize=3)
return t





