How can two eight-bit frames be averaged with a scaled sum?
The scale divisor in add acts on the sum before the value is confined to the output range.
Pixel experiment and interpretation
Two bright frames can still yield their midpoint when division precedes clipping. Clipping a stored eight-bit sum first biases the mean downward.
from PIL import Image, ImageChops
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
ImageChops.add(row([200]),row([240]),scale=2).getpixel((0,0))Result 220
中文
如何用两张八位图计算不溢出的逐像素平均?
add 的 scale 除数作用于和,再将结果转换到输出范围。
像素实验与适用边界
两幅亮度都很高的图先加再除以二,仍能得到中间亮度。若先用八位截断求和,均值会偏暗。
from PIL import Image, ImageChops
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
ImageChops.add(row([200]),row([240]),scale=2).getpixel((0,0))结果 220