这是由于在使用
image=Image.fromarray(image)
将数组转为图像的过程中,数组中的数据是浮点型(F)无法转为图像,因此需要改变image的类型,
if image.mode == "F": image = image.convert('RGB')
完整代码如下:
image=Image.fromarray(image) if image.mode == "F": image = image.convert('RGB') image.save(imageName)
PIL中的模块的模式对应关系如下
模式
1 1位像素,黑和白,存成8位的像素
L 8位像素,黑白
P 8位像素,使用调色板映射到任何其他模式
RGB 3×8位像素,真彩
RGBA 4×8位像素,真彩+透明通道
CMYK 4×8位像素,颜色隔离
YCbCr 3×8位像素,彩色视频格式
I 32位整型像素
F 32位浮点型像素
# 参考链接:https://blog.csdn.net/z704630835/article/details/84968767