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