答案 0 :(得分:1)
据我对问题的理解,您想将numpy数组转换为图像格式(PIL)。可以通过以下代码完成:
import numpy
import PIL
#Convert nparray to PIL image
img = PIL.Image.fromarray(arr) #arr is numpy array
答案 1 :(得分:0)
import numpy as np
from PIL import Image
# monochrome:
X1 = np.random.randint(0, 255, size=(256,256), dtype=np.uint8)
image1 = Image.fromarray(X1, "L")
image1.show()
# color:
X2 = np.random.randint(0, 255, size=(256,256,3), dtype=np.uint8)
image2 = Image.fromarray(X2, "RGB")
image2.show()
查看不同的模式:
https://pillow.readthedocs.io/en/5.2.x/handbook/concepts.html#concept-modes