How do you map a source window directly onto a target canvas?
EXTENT uses a rectangle in the source as the sampling region and maps it to the requested output size.
Pixel experiment and interpretation
Select the middle two cells of four and map them across four output cells. For class data choose nearest sampling to keep IDs intact.
from PIL import Image
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
out=row([10,20,30,40]).transform((4,1),Image.Transform.EXTENT,(1,0,3,1),Image.Resampling.NEAREST)
list(out.tobytes())Result [20, 20, 30, 30]
中文
如何一步把源图中的窗口映射到目标画布?
EXTENT 用源图中的矩形作为采样区域,并映射到指定输出尺寸。
像素实验与适用边界
从四格样本中选中间两格并扩到四格。对类别数据使用最近邻,避免映射途中插入不属于任何类的值。
from PIL import Image
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
out=row([10,20,30,40]).transform((4,1),Image.Transform.EXTENT,(1,0,3,1),Image.Resampling.NEAREST)
list(out.tobytes())结果 [20, 20, 30, 30]