当将一个1D的numpy数组转换为PIL图像对象时,PIL会返回IndexError: tuple index out of range
错误。
我正在尝试将长度为2048、值在0到255之间的1D numpy数组转换为图像使用PIL。我认为这是由于我的数组是1D造成的问题。我还尝试将一个随机的1D整数数组转换为图像,但我得到相同的错误。
随机整数示例:
from PIL import Image
import numpy as np
arr = np.random.randint(255, size=(2048))
arr = arr.astype('uint8')
img = Image.fromarray(arr, 'L')
img.show()
我希望代码能够显示一行像素,这些像素具有不同的灰度色调。