我有一个numpy值范围为的数组0-255。我想将其转换为3通道RGB图像。我使用了该PIL Image.convert()函数,但是它将其转换为灰度图像。
我正在使用Python PIL库numpy通过以下代码将数组转换为图像:
imge_out = Image.fromarray(img_as_np.astype('uint8'))
img_as_img = imge_out.convert("RGB")
Run Code Online (Sandbox Code Playgroud)
输出将图像转换为3个通道,但显示为黑白(灰度)图像。如果我使用以下代码
img_as_img = imge_out.convert("R")
Run Code Online (Sandbox Code Playgroud)
表明
error conversion from L to R not supported
Run Code Online (Sandbox Code Playgroud)
如何将numpy数组正确转换为RGB图片?