gpt4 book ai didi

python - 如何使用 PIL 显示值为 [0, 1] 的图像

转载 作者:行者123 更新时间:2023-12-01 06:41:13 24 4
gpt4 key购买 nike

我有一个像素值为 [0,1] 的 RGB 图像。如何使用 PIL 将其显示为标准 RGB 图像?

我尝试使用 numpy 转换并显示图像,如下所示:

orig = np.array(255*norm_image)
orig = orig.astype(int)
orig = Image.fromarray(orig)
orig.show()

但是我在第三行遇到错误:

TypeError: Cannot handle this data type

这里出了什么问题?

最佳答案

当你这样做时:

orig = orig.astype(int)

您将dtype设置为int64,您可以按如下方式检查:

print(orig.dtype)

这不是 Pillow 下支持的数据类型(请参阅 here ),因此您需要从我链接到的支持类型列表中选择不同的类型,例如 np.uint8 .

关于python - 如何使用 PIL 显示值为 [0, 1] 的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59449542/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com