生成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.