How do you stretch a narrow intensity range across black and white?
autocontrast remaps intensity levels using histogram endpoints to expand the occupied range.
Pixel experiment and interpretation
A scan strip spanning 40 to 80 gains contrast. A single bright defect can drive the mapping, so inspect the histogram before choosing a cutoff.
from PIL import Image, ImageOps
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
list(ImageOps.autocontrast(row([40,60,80])).tobytes())Result [0, 127, 255]
中文
怎样把一小段灰度范围拉伸到黑白两端?
autocontrast 根据直方图的端点重新映射色阶,使有效范围扩展。
像素实验与适用边界
一条只覆盖 40 至 80 的扫描带会更醒目。单个极亮坏点会影响映射,决定截尾比例前先检查直方图。
from PIL import Image, ImageOps
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
list(ImageOps.autocontrast(row([40,60,80])).tobytes())结果 [0, 127, 255]