TypeError: Cannot handle this data type: (1, 1, 3), <f8和Image.fromarray()函数转换后图像失真

错误显示1.

错误显示2.

(预测为RGB图像,结果失真为黑色)

原因:采用 matplotlib.image 读入图片数组,注意这里读入的数组是 float32 型的,范围是 0-1,而 PIL.Image 数据是 uinit8 型的,范围是0-255

(可根据python PIL图像处理 - jujua - 博客园 (cnblogs.com)分析)

更改方案:

image=Image.fromarray(image)——>image=Image.fromarray(np.uint8(image*255))

猜你喜欢

转载自blog.csdn.net/weixin_45866058/article/details/124838012