在我的代码中,我正在创建一个RGB数组(256 * 256 * 3),需要显示它。 我无法从RGB阵列创建PIL图像。 我写了这段代码来解释:
import numpy as np
from PIL import Image
image = Image.open('img_test.png')
image.thumbnail((256, 256))
image = image.convert("RGB")
image = np.asarray(image, dtype=np.float32) / 255
PIL.Image.fromarray(image, "RGB").show()
我正在找回这张图片:
如果我正在使用
import matplotlib.pyplot as plt
plt.imshow(image)
plt.show()
这行我在做什么错?
PIL.Image.fromarray(image, "RGB").show()
答案 0 :(得分:2)
答案 1 :(得分:1)
您提到的行似乎很好,但是,我想知道为什么要这样做:
image = np.asarray(image, dtype=np.float32) / 255
如果用以下内容替换该行,则可以使用PIL或matplotlib显示图像:
image = np.asarray(image)