How do you trim different binding margins from four edges?

ImageOps.crop interprets its border as thicknesses to remove from the edges, independent of the final rectangle's absolute coordinates.

Pixel experiment and interpretation

Remove one column on the left and two on the right from a six-column strip. Check binding orientation before trimming a mixed batch.

from PIL import Image, ImageOps

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

list(ImageOps.crop(row([1,2,3,4,5,6]),border=(1,0,2,0)).tobytes())

Result [2, 3, 4]

中文

如何从扫描图的四边剥离固定厚度的装订边?

ImageOps.crop 把参数解释为各边要剥掉的厚度,而非最终矩形的坐标。

像素实验与适用边界

六列纸带去掉左一列、右两列后剩三列。用这种办法批处理前,要确认所有扫描件的装订方向一致。

from PIL import Image, ImageOps

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

list(ImageOps.crop(row([1,2,3,4,5,6]),border=(1,0,2,0)).tobytes())

结果 [2, 3, 4]

References / 参考来源

Keep reading / 继续阅读