function setPixel(x, y, pix)
  if x >= 0 and y >= 0 and x < w and y < h then
    pixels[y*w+x+1] = pix
  end
end

-- copy image

w, h = img.width, img.height
pixels = {}
for y = 0, h-1 do
  for x = 0, w-1 do
    pixels[y*w+x+1] = img.getInt(x, y)
  end
end

-- iterate over heatmap

_, _, map = string.find(result, ": (.*)")

for y = 0, h-1 do
  b = math.floor((string.byte(map, y+1)-string.byte("A"))*255/25+0.5)
  for x = 0, 3 do
    setPixel(x, y, b*0x010101)
    setPixel(w-1-x, y, b*0x010101)
  end
end