util.py 文件源码

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

项目:imagepy 作者: Image-Py 项目源码 文件源码
def build_surf2d(img, ds=1, sigma=0, k=0.2):
    from skimage.filters import sobel_h, sobel_v
    from scipy.ndimage import gaussian_filter
    start = time()
    img = img[::-ds, ::ds]
    img = gaussian_filter(img, sigma)
    r, c = img.shape
    rs, cs, fs = build_grididx(r, c)
    vs = img[rs, cs]

    vts = np.array([cs*ds, rs*ds, vs*k], dtype=np.float32).T
    cs = (np.ones((3, r*c))*(vs/255)).astype(np.float32).T

    dx, dy = sobel_h(img), sobel_v(img)
    cx, cy = np.zeros((r*c, 3)), np.zeros((r*c, 3))
    cx[:,0], cx[:,2] = 1, dx.ravel()
    cy[:,1], cy[:,2] = 1, dy.ravel()
    ns = np.cross(cx, cy)
    ns = (ns.T/np.linalg.norm(ns, axis=1)).astype(np.float32).T

    #ns = count_ns(vts, fs)
    print(time()-start)
    return vts, fs, ns, cs
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号