问题描述
输入:
from PIL import Image
img=Image.open(r"C:\img1.png")
pixelMap = img.load()
pixel = pixelMap[0,0]
print(pixel)
输出:0
所需的输出:(0,0)
解决方法
您的图像可能是调色板图像-请参见here。因此,将您的代码更改为此:
from PIL import Image
# Load image - ensuring RGB not palette
img=Image.open(r"C:\img1.png").convert('RGB')
pixelMap = img.load()
pixel = pixelMap[0,0]
print(pixel)