【问题标题】:Convert point/dot annotation in to gaussian density map将点/点注释转换为高斯密度图
【发布时间】:2021-09-23 10:09:04
【问题描述】:

我正在研究这篇论文:https://papers.nips.cc/paper/2010/file/fe73f687e5bc5280214e0486b273a5f9-Paper.pdf,我在以下功能上苦苦挣扎:

基本上在图像中,每个人都会被注释一个点,而不是边界框或分割。该论文提出了一种将点转换为高斯密度图的方法,该密度图充当基本事实。我已经尝试过 numpy.random.multivariate_normal 但它似乎不起作用。

【问题讨论】:

    标签: python dictionary gaussian kernel-density


    【解决方案1】:

    我正在研究一个涉及密度图的研究问题。此代码假设您正在循环遍历文本文件列表,其中每个文本文件都有点注释(或者您正在从对象转换为点注释,就像我做的那样)。它还假设您有一个 annotations 列表,其中 (x,y) 中心 points 可以使用(在读取/处理所述文本文件之后)。

    你可以在这里找到 good 的实现: https://github.com/CommissarMa/MCNN-pytorch/blob/master/data_preparation/k_nearest_gaussian_kernel.py

    上面有一些用于自适应内核的额外代码。

    上下文中的以下代码(带有更多“绒毛”)在这里: https://github.com/MattSkiff/cow_flow/blob/master/data_loader.py

    这是我使用的代码:

    # running gaussian filter over points as in crowdcount mcnn
             
    density_map = np.zeros((img_size[1],img_size[0]), dtype=np.float32)
      
    # add points onto basemap
    for point in annotations:
    
        base_map = np.zeros((img_size[1], img_size[0]), dtype=np.float32)       
                            
        # subtract 1 to account for 0 indexing
        base_map[int(round(point[1]*img_size[1])-1),
                 int(round(point[0]*img_size[0])-1)] += 1
    
        density_map += scipy.ndimage.filters.gaussian_filter(base_map, sigma = sigma, mode='constant')
    

    这应该会创建一个密度图,可以满足您的需求。在 matplotlib 中的 ax 对象上使用“imshow”(例如ax.imshow(density,cmap='hot',interpolation='nearest')应该会产生一个像这样的密度图(我已经添加了航空图像来指示被标记的内容):

    【讨论】:

      猜你喜欢
      • 2015-01-20
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-23
      • 1970-01-01
      • 2021-10-06
      • 1970-01-01
      相关资源
      最近更新 更多