简体   繁体   English

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

[英]How i can convert a 16 bit depth image (png format) into a 32 bit one?

I have a depth image 16 uint of an human hand, after thresholding. 经过阈值处理后,我得到了人手的深度图像16 uint。 I want to recover some geometric features as contour, convex hull, etc., but all these functions work with 8 or 32 bit images so I need to convert. 我想恢复一些几何特征,例如轮廓,凸包等,但是所有这些功能都适用于8位或32位图像,因此需要进行转换。 I'm working in python! 我正在用python工作!

I've tried with some open cv function as 我已经尝试过使用一些开放的简历功能

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

but I've always a 16 uint image. 但是我总是有16个单位的图像。

I don't believe PNG supports floating point data, so I am not sure what format you expect the output to be in? 我不相信PNG支持浮点数据,所以我不确定您期望输出采用哪种格式?

If raw 32-bit float RGB is ok, you could use ImageMagick which is installed on most Linux distros and readily avilable for OS X and Windows. 如果原始的32位浮点RGB没问题,则可以使用ImageMagick,它已安装在大多数Linux发行版中,并且适用于OS X和Windows。 The command would be 该命令将是

convert input.png -depth 32 -define quantum:format=floating-point rgb:out.rgb

For example, if you create a 1x1 white image like this 例如,如果您创建这样的1x1白色图像

convert -size 1x1 xc:white -depth 32 -define quantum:format=floating-point rgb:out.rgb

you get a 12-byte image like this 你会得到一个12字节的图像

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

If you create a 1x1 black image like this 如果创建这样的1x1黑色图像

convert -size 1x1 xc:black -depth 32 -define quantum:format=floating-point rgb:out.rgb

you get a 12-byte image like this 你会得到一个12字节的图像

xxd out.rgb
0000000: 0000 0000 0000 0000 0000 0000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM