【debug】PIL TypeError: Cannot handle this data type(已解决)

python处理数据的时候,用到了PIL库,过程中出现了如题目的错误,轻松解决:

在这里插入图片描述

处理方式:

im = Image.fromarray((x * 255).astype(np.uint8))

解释理解:

  • 就是说,一般的图像数据处理开源的库,如opencv、matplotlib等等,都支持处理uint和float元素数据类型的数据,但是PIL很特殊,它不支持float类型,所以要转为uint,就用上面那一行代码。完毕。

猜你喜欢

转载自blog.csdn.net/weixin_42306148/article/details/124832192