我有这张深度图像:
我用PIL这样加载它:
depth_image = Image.open('stereo.png')
如果我打印图像的模式,它会显示模式I
,根据文档,这是(32位有符号整数像素)
。
这是正确的,因为图像值的范围从0到255。我想对这个深度图进行着色以获得更好的可视化效果,所以我尝试使用调色板将其转换为P
模式,例如:
depth_image = depth_image.convert('P', palette=custom_palette)
depth_image.save("colorized.png")
但结果是这样的黑白图像:
我相信调色板没问题,因为有256个颜色以int
格式存储在一个数组中。
我已经尝试在保存前将其转换为RGB格式,例如:
depth_image = depth_image.convert('RGB')
我也尝试在之后添加调色板,例如:
depth_image = depth_image.putpalette(custom_palette)
如果我尝试保存它而不将其转换为RGB,会收到以下提示:
depth_image.save("here.png")
AttributeError: 'NoneType' object has no attribute 'save'
目前我将尝试将图像转换为numpy数组,然后从那里映射颜色,但我想知道关于PIL方面的遗漏。我查看了文档,但没有找到有关I到P转换的信息。
custom_palette
。 - Mark Setchell.convert("P", palette=Image.ADAPTIVE, colors=256)
但仍然没有任何效果。 - bpinaya