How can you invert only the bright end of an image?
solarize leaves intensities below the threshold alone and inverts values at or above it.
Pixel experiment and interpretation
Test a strip straddling 100. The mapping can jump at the threshold, so a new dark boundary need not mark a real object.
from PIL import Image, ImageOps
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
list(ImageOps.solarize(row([99,100,101]),threshold=100).tobytes())Result [99, 155, 154]
中文
如何只反转超过指定亮度的像素?
solarize 保留阈值以下的像素,对达到阈值的像素做反相。
像素实验与适用边界
用刚好跨越 100 的色带验证边界。映射在阈值处可能跳变,因此产生的暗边不一定是物体边缘。
from PIL import Image, ImageOps
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
list(ImageOps.solarize(row([99,100,101]),threshold=100).tobytes())结果 [99, 155, 154]