SIFT算法之关键点查找

本文详细介绍了SIFT算法中的关键点查找过程,包括图像转换、高斯拉普拉斯算子卷积、尺度空间极值检测以及下采样与上采样的优化策略。通过对不同尺度的图像应用高斯滤波器,计算尺度不变的高斯拉普拉斯响应,并进行非极大值抑制,以找出关键点的位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SIFT算法之关键点查找

1. 综述

利用SIFT算法找到输入图像的关键点,预期效果如下图所示。


2. 基本实现

    2.1 读入图像并利用PIL.ImageOps.grayscale() 函数转换成灰度图,除以255以normalize到[0,1]范围内。

    2.2 利用scipy函数scipy.ndimage.gaussian_laplace(input, sigma, output=None, mode='reflect', cval=0.0, **kwargs) 来对图像进行gaussian Laplacian 算子卷积。(函数参数解读见附录1)。 注意此处需要进行scale normalize的操作,对结果乘以sigma*2(可以求平方得到squared laplacian response in scale space. 求平方是为了将白点和黑点统一化)

          设置不同的一系列不同的sigma值分别对图像进行卷积。得到一个三维的矩阵,第三个维度为sigma

    (由于gaussian Laplacian算子不可以通过分解来降维,所以当sigma变大的时候卷积速度会大幅度下降,所以可以采用skimage.transform.resize(matrix, size = (newx,newy))的方法对图像进行不同程度的降采样然后用同一个gaussian Laplacian算子卷积后再upsample到原来的大小,这个方法可以大幅度提升卷积速度)

     2.3 对这个三维的scale space进行nonmaximum suppress,找到矩阵的三维极大值。输出(x,y, 1.414 * sigma)作为圆心坐标(可能会用到IOU,没有实现)

      2.4 画图,利用如下函数

def show_all_circles(image, circles, color='r'):
    """
    image: numpy array, representing the grayscsale image
    cx, cy: numpy arrays or lists, centers of the detected blobs
    rad: numpy array or list, radius of the detected blobs
    """
    import matplotlib.pyplot as plt
    from matplotlib.patches import Circle

    fig, ax = plt.subplots()
    ax.set_aspect('equal')
    ax.imshow(image, cmap='gray')
    for circle in circles:
        circ = Circle((circle[1], circle[0]), circle[2], color=color, fill=False)
        ax.add_patch(circ)

    plt.title('%i circles' % len(circles))
    plt.show()
    return 0
3. 实验结果



4. Difference of Gaussian

    In David G. Lowe’s paper, Difference of Gaussian can be viewed as an approximationof the Gaussian Laplace filter. The formula is given as follows:

            G(x,y,kσ)-G(x,y,σ)≈(k-1)σ^2 ∇^2 G

    TheLHS of the above equation is the original scale-invariant Gaussian Laplacianresponse and the RHS is the difference of two gaussian responses.

     What we have to do is to downsample theimage from the original size to several levels and a Gaussian filter with samesigma is applied to each level of image. Rescale every downsampled responsematrix to the original image size and stack each matrix and finally get a 3D arrayand the shape of which is [level, x, y]. Get (levels -1) differences between eachpair of adjacent layers. The rest work of nonmaximum suppression is similar toLaplacian Gaussian method.

    (以上英文段落引自本人实验报告)

附录

1. filter函数参数解读

scipy.ndimage.gaussian_laplace(input, sigma, output=None, mode='reflect', cval=0.0, **kwargs)

Parameters:

input : array_like

Input array to filter.

sigma : scalar or sequence of scalars

The standard deviations of the Gaussian filter are given for each axis as a sequence, or as a single number, in which case it is equal for all axes.

output : array, optional

The output parameter passes an array in which to store the filter output. Output array should have different name as compared to input array to avoid aliasing errors.

mode : str or sequence, optional

The mode parameter determines how the array borders are handled. Valid modes are {‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}. cval is the value used when mode is equal to ‘constant’. A list of modes with length equal to the number of axes can be provided to specify different modes for different axes. Default is ‘reflect’

cval : scalar, optional

Value to fill past edges of input if mode is ‘constant’. Default is 0.0

Extra keyword arguments will be passed to gaussian_filter().


2. 如何由函数gaussian_filter的truncate 和 sigma参数确定filter的宽度?

以下引自 Stack Overflow https://stackoverflow.com/questions/25216382/gaussian-filter-in-scip

---------------------------------分割线-----------------------------------------

Check out the source code here: https://github.com/scipy/scipy/blob/master/scipy/ndimage/filters.py

You'll see that gaussian_filter calls gaussian_filter1d for each axis. In gaussian_filter1d, the width of the filter is determined implicitly by the values of sigma and truncate. In effect, the width w is

w = 2*int(truncate*sigma + 0.5) + 1

So

(w 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值