What happens to black, midgray and white under inversion?

For an eight-bit grayscale image invert maps each intensity v to 255 minus v.

Pixel experiment and interpretation

Changing dark text on white to light text on black flips antialiased edges too. A second inversion restores their original values.

from PIL import Image, ImageOps

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

list(ImageOps.invert(row([0,128,255])).tobytes())

Result [255, 127, 0]

中文

反相后灰度 0、128、255 各是多少?

对八位灰度图,invert 把每个值 v 换为 255−v。

像素实验与适用边界

把白底黑字变成黑底白字时,中灰边缘也随之翻转。反相两次会恢复原字形的灰度。

from PIL import Image, ImageOps

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

list(ImageOps.invert(row([0,128,255])).tobytes())

结果 [255, 127, 0]

References / 参考来源

Keep reading / 继续阅读