How do you assign named endpoint colors to a grayscale response map?
colorize uses grayscale as an index into a color ramp between specified colors.
Pixel experiment and interpretation
Map minimum response to blue and maximum to red and check both against the legend. Keep original scalars for modeling; colors are a display choice.
from PIL import Image, ImageOps
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
im=ImageOps.colorize(row([0,255]),black='blue',white='red')
(im.getpixel((0,0)),im.getpixel((1,0)))Result ((0, 0, 255), (255, 0, 0))
中文
如何把灰度响应映射为有指定两端颜色的热图?
colorize 以灰度为索引,在给定颜色之间生成 RGB 可视化。
像素实验与适用边界
让最低响应为蓝色、最高为红色,查看两端是否对应图例。模型计算仍使用原标量,避免把配色当作新观测。
from PIL import Image, ImageOps
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
im=ImageOps.colorize(row([0,255]),black='blue',white='red')
(im.getpixel((0,0)),im.getpixel((1,0)))结果 ((0, 0, 255), (255, 0, 0))