I'd like to digitize a heatmap, Panel D in this source
As a first step, I tried to read the image in opencv and obtain a matrix
import cv2
from pprint import pprint
def read_as_digital(image):
# mage dimensions
h = image.shape[0]
w = image.shape[1]
print(h, w)
pass
if __name__ == '__main__':
image = cv2.imread('ip.jpg', 1)
pprint(image)
read_as_digital(image)
I could read the image as a matrix, but I don't know how to specify the beginning of the cells (corresponding to different subplots in panel D of the image) in the heatmap. finally, I want to map the pixels to values.
Any suggestions on how to proceed will be really helpful
EDIT1:
I tried to obtain the values on click
For instance, when I consider a small subsection of the heatmap provided in the source
I expect to obtain the average value for each cell (centered around yellow dots) in the image.
Clicking at different points yields different values. Clicking on the cell that's coored
gives different RGB values at different points.
Any suggestion on how to obtain an average value for each cell (e.g.) will be really helpful.
EDIT2:
I've tried the updated code.
The mean average for this ((e.g.)) works really well. However, there is a problem with the cell next to it. When I click the adjacent cell, the mean that is displayed by the code is for 3 cells that are with the same color. It would be really nice if there is a way to limit the cell size, kind of specify a boundary in which the mean should be calculated in the code. The image presented in edit 1 has 6 rows and 6 columns. If we view this as 6 by 6 matrix say, A, the mean should be obtained for each Aijth entry of the matrix.