python - 将点/点注释转换为高斯密度图
问题描述
我正在研究这篇论文:https ://papers.nips.cc/paper/2010/file/fe73f687e5bc5280214e0486b273a5f9-Paper.pdf ,我在以下功能上苦苦挣扎:
基本上在图像中,每个人都会被注释一个点,而不是边界框或分割。该论文提出了一种将点转换为高斯密度图的方法,该密度图充当基本事实。我试过 numpy.random.multivariate_normal 但它似乎不起作用。
解决方案
我正在研究一个涉及密度图的研究问题。此代码假设您正在循环遍历文本文件列表,其中每个文本文件都有点注释(或者您正在从对象转换为点注释,就像我做的那样)。它还假设您有一个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'
)应该会产生一个像这样的密度图(我添加了航空图像以指示正在标记的内容):
推荐阅读
- java - 如何在 Java 中删除 Azure 容器注册表上的 Docker 映像?
- r - 如何使用 r 计算每行中的字母数?
- php - 如何在 PHP 服务器运行 cron 作业调度 PHP 脚本时停止请求?
- ruby-on-rails - Pandoc 不转换文件 doc 有数学到文件乳胶
- javascript - 在 Unity 中结束游戏 - 字母游戏
- elasticsearch - Elasticsearch 中不直接显示空字段?
- mysql - SQL:如何将 2 个查询合二为一,使用 2 个不同的 GROUP BY 指令
- javascript - 时刻时间正在返回 UTC 时间而不是本地时间
- ajax - 如何将一些数据和图像从 AJAX 发送到 Laravel 中的控制器?
- excel - Excel VBA - 将整个工作簿的蓝色阴影单元格更改为绿色