How does a lookup table threshold a grayscale image?
point maps input intensity through a lookup table. The mapping determines which side owns the boundary.
Pixel experiment and interpretation
Give the threshold itself to the foreground and test 127, 128 and 129. This exposes an accidental strict comparison.
from PIL import Image
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
list(row([127,128,129]).point(lambda v: 255 if v>=128 else 0).tobytes())Result [0, 255, 255]
中文
如何用查找表一次阈值化整张灰度图?
point 按输入灰度查表生成输出,阈值边界由映射函数定义。
像素实验与适用边界
规定 128 也算目标,把 127、128、129 三点都放进回归测试。这样能看出阈值比较写成了大于还是大于等于。
from PIL import Image
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
list(row([127,128,129]).point(lambda v: 255 if v>=128 else 0).tobytes())结果 [0, 255, 255]