Image.fromarray()报错:TypeError: Cannot handle this data type: (1, 1, 3), <f4
当我们通过from PIL import Image使用Image.fromarray()函数减numpy数组转成图片数据时,如果遇到以下错误:即:File "xxx.py", line 310, in rerenderrendering_img1 = Image.fromarray(rendering_img1)File "D:\Software\Anaconda\Anaconda\envs\C
·
当我们通过
from PIL import Image
使用
Image.fromarray()
函数将numpy数组转成图片数据时,如果遇到以下错误:
即:
File "xxx.py", line 310, in rerender
rendering_img1 = Image.fromarray(rendering_img1)
File "D:\Software\Anaconda\Anaconda\envs\Competition\lib\site-packages\PIL\Image.py", line 2774, in fromarray
raise TypeError("Cannot handle this data type: %s, %s" % typekey) from e
TypeError: Cannot handle this data type: (1, 1, 3), <f4
原因可能是,往 Image.fromarray() 输入的numpy数据类型不符,例如,我这输入rendering_img1图片数据类型是 float32的[0,255]区间的数据,此时,将类型转换一下即可,如下所示:
rendering_img1 = Image.fromarray(np.uint8(rendering_img1))
更多推荐
已为社区贡献5条内容
所有评论(0)