从包含注视数据的 CSV 中形成显着图

问题描述 投票:0回答:0

我有一个 CSV 文件,其中包含研究参与者的注视点,这些参与者已获得要观察的图像。 CSV 文件中的一列包含以下格式的数据数组:

[[581,497,23,0,720,899],[666,539,56,0,720,899],[616,500,83,0,720,899]]

嵌套数组中的数据为我们提供了有关参与者正在看哪里的信息。例如,如果数组是:

[933,47,365,0,1073,725]

数组会告诉我们:

  • 参与者正在环顾屏幕上的“977 x 47”像素
  • 他们在研究开始后的 365 毫秒内看着那里
  • “0”表示图片还没有滚动
  • 参与者的鼠标在“1073 x 725”的像素位置

我用来收集注视点的网站提供了参与者注视的最终热图,但是,我只需要提取热图并将其设为灰度,以便我可以将其与显着性模型的显着性图进行比较。

网站提供的热图图像形成了观众注视点的热图。

我想用 CSV 数据做什么的例子

我尝试使用以下代码自己形成热图:

import numpy as np
import matplotlib.pyplot as plt
import cv2

# Define the input image size
img_size = (1024, 1280)

# Create an empty numpy array of the same size as the input image
saliency_map = np.zeros(img_size)

array1 = [[581,497,23,0,720,899],[666,539,56,0,720,899],[616,500,83,0,720,899],[639,490,110,0,720,899],[658,511,143,0,720,899],[671,514,173,0,720,899],[671,514,199,0,720,899],[662,511,236,0,720,899],[614,489,261,0,720,899],[641,480,291,0,720,899],[664,479,331,0,720,899],[665,485,357,0,720,899],[667,508,389,0,720,899],[681,488,425,0,720,899],[696,491,451,0,720,899],[652,499,485,0,720,899],[717,509,523,0,720,899],[675,477,555,0,720,899],[737,494,579,0,720,899],[751,482,613,0,720,899],[714,469,647,0,720,899],[753,470,675,0,720,899],[761,467,707,0,720,899],[715,488,740,0,720,899],[695,475,779,0,720,899],[716,480,804,0,720,899],[702,473,840,0,720,899],[702,473,866,0,720,899],[698,469,900,0,720,899],[706,476,935,0,720,899],[772,468,963,0,720,899],[723,471,997,0,720,899],[704,469,1034,0,720,899],[733,471,1064,0,720,899],[719,461,1090,0,720,899],[678,458,1122,0,720,899],[724,449,1160,0,720,899],[695,438,1186,0,720,899],[636,483,1217,0,720,899],[657,502,1254,0,720,899],[717,481,1289,0,720,899],[688,499,1317,0,720,899],[632,496,1345,0,720,899],[556,453,1383,0,720,899],[489,492,1410,0,720,899],[470,493,1443,0,720,899],[428,481,1480,0,720,899],[428,491,1519,0,720,899],[352,483,1537,0,720,899],[328,489,1573,0,720,899],[341,503,1610,0,720,899],[338,535,1636,0,720,899],[338,535,1667,0,720,899],[341,527,1706,0,720,899],[358,550,1733,0,720,899],[330,487,1765,0,720,899],[365,475,1803,0,720,899],[400,462,1830,0,720,899],[1153,602,1861,0,720,899],[1118,605,1896,0,720,899],[1123,600,1925,0,720,899],[1190,540,1958,0,720,899],[1171,526,1985,0,720,899],[1180,534,2017,0,720,899],[1033,473,2044,0,720,899],[983,477,2079,0,720,899],[1002,494,2109,0,720,899],[917,488,2139,0,720,899],[917,488,2165,0,720,899],[961,483,2197,0,720,899],[897,483,2235,0,720,899],[884,498,2259,0,720,899],[826,492,2291,0,720,899],[792,483,2324,0,720,899],[774,468,2363,0,720,899],[850,469,2393,0,720,899],[803,446,2421,0,720,899],[698,426,2454,0,720,899],[701,427,2488,0,720,899],[708,449,2521,0,720,899],[672,424,2559,0,720,899],[647,439,2583,0,720,899],[616,435,2616,0,720,899],[630,438,2642,0,720,899],[664,428,2676,0,720,899],[632,428,2714,0,720,899],[664,434,2741,0,720,899],[658,428,2772,0,720,899],[658,428,2800,0,720,899],[709,423,2834,0,720,899],[709,423,2870,0,720,899],[723,405,2897,0,720,899],[660,408,2936,0,720,899],[646,414,2959,0,720,899],[619,429,2997,0,720,899]]
combined_array = np.array(array1)

# Loop through the combined array and draw circles on the empty array
for i in range(len(combined_array)):
    x, y, duration, _, _, _ = combined_array[i]
    radius = int(duration / 80)  # Adjust the radius based on the duration
    brightness = duration / 100  # Adjust the brightness based on the duration
    saliency_map = cv2.circle(saliency_map, (x, y), radius, brightness, -1)

# Apply a Gaussian blur to the resulting array
saliency_map = cv2.GaussianBlur(saliency_map, (0, 0), sigmaX=40, sigmaY=40)

# Plot the resulting array
plt.imshow(saliency_map, cmap='gray')
plt.show()

我的代码的输出。这看起来不像我做对了,因为原始热图中的中心点要大得多,而且最左边的点就在图像边界旁边。

如果有人能给我任何关于如何修改我的代码以使其看起来更像原始代码(但只是没有背景图像的灰度)的提示,我将不胜感激。

如果我在完全错误的方向上形成显着图,那么也请告诉我。

非常感谢任何花时间回答的人。

python numpy opencv pytorch heatmap
© www.soinside.com 2019 - 2024. All rights reserved.