Why can the translation sign look reversed in an affine warp?
Pillow's affine coefficients map output coordinates back to source locations for sampling.
Pixel experiment and interpretation
Tell output cell zero to read source cell one. The content appears to move left; the source boundary leaves a fill cell.
from PIL import Image
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
im=row([10,20,30])
out=im.transform(im.size,Image.Transform.AFFINE,(1,0,1,0,1,0),fillcolor=0)
list(out.tobytes())Result [20, 30, 0]
中文
仿射变换参数里为什么平移方向看起来反了?
Pillow 的仿射参数把输出坐标映射回源图,以确定每个目标像素从哪里采样。
像素实验与适用边界
让输出第零格去源图第一格取值,画面看起来就向左移动一格。超出源范围的位置用填充值补上。
from PIL import Image
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
im=row([10,20,30])
out=im.transform(im.size,Image.Transform.AFFINE,(1,0,1,0,1,0),fillcolor=0)
list(out.tobytes())结果 [20, 30, 0]