【发布时间】:2019-10-15 15:04:27
【问题描述】:
我正在尝试使用PIL.Image.fromarray:
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
a = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]]])
im = Image.fromarray(a, mode="RGB")
im.save("test.png")
plt.imshow(im)
plt.show()
我希望看到红色、绿色和蓝色 3 个像素。
但是,如果我在文档示例中省略 mode 关键字参数,我会得到:
TypeError: 无法处理此数据类型
如果我设置mode="RGB",保存的图像文件test.png和matplotlib窗口都如下所示:
【问题讨论】:
标签: python arrays image numpy python-imaging-library