PIL 图像未按正确顺序渲染输入的像素值

PIL Image not rendering inputted pixel values in correct order

只是为了好玩,我想我会尝试用像素值构建图像,然后用 PIL.Image 渲染它。

但它没有呈现我输入的值。

from PIL import Image
import numpy as np

# custom array
arr = np.array(
    [[50,200,50],
     [50,200,50],
     [50,200,50]])

print(arr)

img = Image.fromarray(arr, 'L')
img.show()

[[ 50 200 50] [ 50 200 50] [ 50 200 50]]

输出的图像如下。

鉴于高像素值是白色而低像素值是暗的,我希望图像中间有一条白线。

这里出了什么问题?

感谢@Mark Setchall 的评论。

在创建数组时添加 type=np.uint8 为我解决了这个问题。

arr = np.array(
    [[50,200,50],
     [50,200,50],
     [50,200,50]], type=np.uint8)

现在我得到了我期望的结果。