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 with
min(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.
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 shi_tomasi(image, w_size): ans = image.copy() dy, dx = sy(image), sx(image) ofset = int(w_size/2) for y in range(ofset, image.shape-ofset): for x in range(ofset, image.shape-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] sum_xx = w_Ixx.sum() sum_yy = w_Iyy.sum() ans[y][x] = min(sum_xx, sum_yy) return ans 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