What is lost when a grayscale image keeps only two bits?

posterize retains high-order bits per channel. Keeping two bits allows at most four distinct output intensities.

Pixel experiment and interpretation

Turn a ramp into four steps. Two readings on the same step no longer reveal their former difference.

from PIL import Image, ImageOps

def row(values):
    return Image.frombytes('L', (len(values), 1), bytes(values))

list(ImageOps.posterize(row([0,63,64,127,128,255]),2).tobytes())

Result [0, 0, 64, 64, 128, 192]

中文

把八位照片压成四个有效灰阶会损失什么?

posterize 保留每通道的高位,舍弃低位;保留两位时最多有四个不同输出值。

像素实验与适用边界

把渐变坡分成四级台阶。处于同一级的两点不能从结果恢复原来的亮度差。

from PIL import Image, ImageOps

def row(values):
    return Image.frombytes('L', (len(values), 1), bytes(values))

list(ImageOps.posterize(row([0,63,64,127,128,255]),2).tobytes())

结果 [0, 0, 64, 64, 128, 192]

References / 参考来源

Keep reading / 继续阅读