def harris_ones(img, window_size, k=0.05):
"""Calculate the harris score based on a window function of diagonal ones.
Args:
img The image to use for corner detection.
window_size Size of the window (NxN).
k Weighting parameter during the final scoring (det vs. trace).
Returns:
Corner score image
"""
# Gradients
img = skiutil.img_as_float(img)
imgy, imgx = np.gradient(img)
imgxy = imgx * imgy
imgxx = imgx ** 2
imgyy = imgy ** 2
# window function (matrix of diagonal ones)
window = np.ones((window_size, window_size))
# compute parts of harris matrix
a11 = signal.correlate(imgxx, window, mode="same") / window_size
a12 = signal.correlate(imgxy, window, mode="same") / window_size
a21 = a12
a22 = signal.correlate(imgyy, window, mode="same") / window_size
# compute score per pixel
det_a = a11 * a22 - a12 * a21
trace_a = a11 + a22
return det_a - k * trace_a ** 2
评论列表
文章目录