ruijiege

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
import numpy as np
def draw_gauss(heatmap, x, y, gsize):
    
    height, width = heatmap.shape[:2]
    gsize += 1 - (gsize % 2)
    sigma = gsize / 6
    s = 2 * sigma * sigma
    radius = gsize // 2
    ky, kx = np.ogrid[-radius:+radius+1, -radius:+radius+1]
    kernel = np.exp(-(kx * kx + ky * ky) / s)
    
    dleft, dtop = -min(x, radius), -min(y, radius)
    dright, dbottom = +min(width - x, radius+1), +min(height - y, radius+1)
    select_heatmap = heatmap[y+dtop:y+dbottom, x+dleft:x+dright]
    select_kernel = kernel[radius+dtop:radius+dbottom, radius+dleft:radius+dright]
    if min(select_heatmap.shape) > 0:
        np.maximum(select_heatmap, select_kernel, out=select_heatmap)
    return heatmap

 

posted on 2022-11-02 18:04  哦哟这个怎么搞  阅读(28)  评论(0编辑  收藏  举报