【发布时间】:2018-08-22 15:19:24
【问题描述】:
我有一个 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")
输出将图像转换为 3 个通道,但显示为黑白(灰度)图像。如果我使用以下代码
img_as_img = imge_out.convert("R")
它显示
error conversion from L to R not supported
如何正确地将 numpy 数组转换为 RGB 图片?
【问题讨论】:
-
请给我们看一些你的代码。
-
@DanielF 不,它没有解决我的问题,因为它以图像作为输入,而我的数据已经是 csv 格式,而以图像作为输入,默认情况下你得到 3 个通道,而我的是 1 个通道数据。
标签: python image numpy python-imaging-library