In what order does Pillow expect pixel coordinates?
getpixel accepts horizontal x followed by vertical y, measured from the upper-left corner.
Pixel experiment and interpretation
Lay values one through six into three columns. Position (2,0) is the last item on the first row. Convert row-column annotations before sampling.
from PIL import Image
im=Image.frombytes('L',(3,2),bytes(range(1,7)))
(im.getpixel((2,0)),im.getpixel((0,1)))Result (3, 4)
中文
Pillow 采样坐标和矩阵行列顺序有什么区别?
getpixel 的坐标为横向 x、纵向 y,原点在左上。
像素实验与适用边界
把 1 到 6 按行排进三列,位置 (2,0) 对应第一行末尾。处理数组标注时,把行、列先换成 x、y。
from PIL import Image
im=Image.frombytes('L',(3,2),bytes(range(1,7)))
(im.getpixel((2,0)),im.getpixel((0,1)))结果 (3, 4)