首页 > 解决方案 > 将点/点注释转换为高斯密度图

问题描述

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

图片

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

标签: pythondictionarygaussiankernel-density

解决方案


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

你可以在这里找到一个很好的实现: 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')应该会产生一个像这样的密度图(我添加了航空图像以指示正在标记的内容):

左手边:放置高斯核的密度图,右手边:新西兰土地信息的航空影像


推荐阅读