How does an incomplete edge block affect integer image reduction?

reduce shrinks by integer factors and rounds the output dimension up when an input extent is not divisible.

Pixel experiment and interpretation

Reduce five sample columns in pairs. The right edge occupies a third output cell. Decide whether to crop or pad first when a downstream contract requires exact divisibility.

from PIL import Image

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

im=row([0,10,20,30,80]).reduce((2,1))
(im.size,list(im.tobytes()))

Result ((3, 1), [5, 25, 80])

中文

整数倍缩小时不完整的边缘块怎样影响输出尺寸?

reduce 按整数因子缩小,当某维度不能整除时,对应输出尺寸向上取整。

像素实验与适用边界

五列采样按每两列合并,右端单独留下第三格。若下游期望严格整除,先明确裁掉还是补齐边缘。

from PIL import Image

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

im=row([0,10,20,30,80]).reduce((2,1))
(im.size,list(im.tobytes()))

结果 ((3, 1), [5, 25, 80])

References / 参考来源

Keep reading / 继续阅读