harris.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:computer-vision-algorithms 作者: aleju 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号