【发布时间】:2015-05-20 09:39:48
【问题描述】:
我正在尝试使用 PIL 从 numpy 数组中读取图像,方法如下:
from PIL import Image
import numpy as np
#img is a np array with shape (3,256,256)
Image.fromarray(img)
并收到以下错误:
File "...Image.py", line 2155, in fromarray
raise TypeError("Cannot handle this data type")
我认为这是因为fromarray 期望形状为(height, width, num_channels),但我拥有的数组的形状为(num_channels, height, width),因为它存储在lmdb 数据库中。
如何重塑图像以使其与Image.fromarray 兼容?
【问题讨论】:
-
也许可以试试
Image.fromarray(np.uint8(img)) -
数组的类型是uint8,问题出在形状上