Scipy生成16位的深度图

生成16位的深度图(点云投影)

With scipy.misc.image there seems to be no option to save as 16-bit, so it will always write an 8-bit PNG. But you can use scipy.misc.toimage to create a 16-bit image, just be sure to pass mode=‘I’. Also be sure to specify the array min and max to avoid scaling. Here’s how to use it to save a 16-bit png:

import numpy as np
import scipy.misc
a = np.random.uniform(0, 2**16 - 1, (500, 500)).astype('int32')
img = scipy.misc.toimage(a, high=np.max(a), low=np.min(a), mode='I')
img.save('my16bit.png')
``

```python
# check that you got the same values
b = scipy.misc.imread('my16bit.png')
b.dtype
# dtype('int32')
np.array_equal(a, b)
# True

Note that in this example I used int32 for data type. However, the data must still fit in a uint16. If you put negative values or values larger than 2^16, those will be clipped in the save to PNG. Conversely, even though sp.misc.imread reads as int32, the data will never be more than uint16.

In summary: if you want to write exactly the same numpy array to a PNG you need to make sure it is of uint8/uint16 type, and that you pass the correct high/low/mode to scipy.misc.toimage.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值