有几个软件包可用于数字化线条图,例如GetData图数字化器。
但是,对于热图的数字化,我找不到任何软件包或程序。
我想使用Python将热图(来自png或jpg格式的图像)数字化。该怎么做呢?
我需要从头开始写完整的代码吗?
或者有可用的套餐?
发布于 2018-03-25 01:01:14
有多种方法可以做到这一点,许多机器学习库提供定制的可视化functions...easier或更难实现。
你得把问题分成两半。
首先,对于python或scikit-映像使用OpenCV,您首先必须将图像作为矩阵加载。您可以将一些偏移设置为从单元格的开始处开始。
import cv2
# 1 - read color image (3 color channels)
image = cv2.imread('test.jpg',1)
然后,您将遍历单元格并读取内部的颜色。如果你愿意的话,你可以将结果正常化。我们引入一些偏移的原因是热图没有从原始图像的左上角(0,0)开始。offset_x和offset_y将是包含两个值的列表。
另外,我们不迭代到最后一列。这是因为我们从“0”列开始,在每个基本的局部坐标上添加cell_size/2,以获得单元格的中心值。
def read_as_digital(image, cell_size, offset_x, offset_y):
# grab the image dimensions
h = image.shape[0]
w = image.shape[1]
results = []
# loop over the image, cell by cell
for y in range(offset_y[0], h-offset_y[1]-cell_size, cell_size):
row = []
for x in range(offset_x[0], w-offset_x[0]-cell_size, cell_size):
# append heatmap cell color to row
row.append(image[x+int(cell_size/2),y+int(cell_size/2)])
results.append(row)
# return the thresholded image
return results
提取图例信息并不困难,因为我们可以通过限制(尽管这适用于线性尺度)来导出值。
例如,我们可以从传说中(从x和y)推导出步骤。
def generate_legend(length, offset, cell_size, legend_start, legend_end):
nr_of_cells = (length- offset[0] - offset[1])/cell_size
step_size = (legend_end - legend_start)/nr_of_cells
i=legend_start+step_size/2 # a little offset to center on the cell
values = []
while(i<legend_end):
values.append(i)
i = i+step_size
return values
然后你想把它们想象出来,看看是否一切都做得对。例如,使用海运非常容易实现[1]。如果您想要更多的控制,over...anything,您可以使用scikit学习和matplotlib [2]。
https://stackoverflow.com/questions/49471502
复制相似问题