Python 如何将16位深度图像(png格式)转换为32位深度图像?

Python 如何将16位深度图像(png格式)转换为32位深度图像?,python,opencv,tracking,depth,Python,Opencv,Tracking,Depth,我有一张深度图像,是一只经过阈值处理的人手。我想恢复一些几何特征,如轮廓、凸包等,但所有这些函数都适用于8位或32位图像,因此我需要转换。我在用python工作 我尝试了一些开放式cv函数作为 img32 = np.array(thresh, dtype=np.float32) # This line only change the type, not values img32 *= 65536 # Now we get the good values in 32 bit format prin

我有一张深度图像,是一只经过阈值处理的人手。我想恢复一些几何特征,如轮廓、凸包等,但所有这些函数都适用于8位或32位图像,因此我需要转换。我在用python工作

我尝试了一些开放式cv函数作为

img32 = np.array(thresh, dtype=np.float32) # This line only change the type, not values
img32 *= 65536 # Now we get the good values in 32 bit format
print img.dtype

但我一直使用16 uint图像。

我不相信PNG支持浮点数据,所以我不确定您希望输出的格式是什么

如果raw 32位浮点RGB还可以,您可以使用ImageMagick,它安装在大多数Linux发行版上,并且很容易在OS X和Windows上使用。命令是

convert input.png -depth 32 -define quantum:format=floating-point rgb:out.rgb
例如,如果像这样创建1x1白色图像

convert -size 1x1 xc:white -depth 32 -define quantum:format=floating-point rgb:out.rgb
convert -size 1x1 xc:black -depth 32 -define quantum:format=floating-point rgb:out.rgb
你会得到这样一个12字节的图像

xxd out.rgb
0000000: 0000 803f 0000 803f 0000 803f
xxd out.rgb
0000000: 0000 0000 0000 0000 0000 0000
如果你像这样创建一个1x1的黑色图像

convert -size 1x1 xc:white -depth 32 -define quantum:format=floating-point rgb:out.rgb
convert -size 1x1 xc:black -depth 32 -define quantum:format=floating-point rgb:out.rgb
你会得到这样一个12字节的图像

xxd out.rgb
0000000: 0000 803f 0000 803f 0000 803f
xxd out.rgb
0000000: 0000 0000 0000 0000 0000 0000

相关的,可能会回答你的问题:什么是图像格式?它是压缩的还是生的?@RobertHarvey嗨!我只是或多或少地用同样的方式尝试过,我想:)但是没有…@Spirine嗨,是的,它是压缩的,它是一张从kinect保存为png的图像,我用它来为我的硕士学位论文做一些测试。这是一个16单位深度的图像,我用大津的阈值进行了二值化,现在我有了一个黑白图像,我想在opencv中找到一些几何特征,但我需要的许多函数需要8或32位ImagesOrry!我写的float32是错误的,我想要一个32uint输出!8 uint也许也不错,但我不想丢失太多信息