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

标签 python image python-imaging-library

我有一个像素值为 [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/

相关文章:

python - 在numpy矩阵中查找最大列值的行索引

python - 通过 PIL 将图像转换为动画 webp 文件时出错

python - 无法在 Ubuntu 上的 Python 中导入 torchvision

iphone - 如何允许 iPhone 用户 "Move and Scale"已选择的照片

Python Pillow 的缩略图方法返回 None

Python Tornado - 使 POST 立即返回,同时异步函数继续工作

Python/Selenium 尝试在未找到的元素上使用 "if"语句

python - Google App Engine 计算属性日期返回引发异常

python - setuptools setup.py 文件中 install_requires kwarg 的引用 requirements.txt

ios - 为什么当我触摸屏幕时我的图像没有弹出?