How do you encode a measurement series as a scaled grayscale preview?
putdata writes a flat sequence in scanline order and can multiply each reading by a scale before adding an offset.
Pixel experiment and interpretation
Map −1, 0 and 1 to three levels centered on 128. Keep the source measurements for computation because the eight-bit preview can round or clip.
from PIL import Image
im=Image.new('L',(3,1))
im.putdata([-1,0,1],scale=40,offset=128)
list(im.tobytes())Result [88, 128, 168]
中文
如何把浮点测量按比例和偏移量写成灰度预览?
putdata 按行写入线性序列,并可在写入时对每个值乘系数再加偏移。
像素实验与适用边界
把 −1、0、1 映成围绕 128 的三个灰度值。预览采用八位范围,原始测量应另存,以免舍入或截断影响计算。
from PIL import Image
im=Image.new('L',(3,1))
im.putdata([-1,0,1],scale=40,offset=128)
list(im.tobytes())结果 [88, 128, 168]