16bit depth image storage method: comparison between opencv png format and numpy npy format

The depth map obtained by lidar or depth estimation is generally float32 or float64 type data, which has a large amount of data. When saving it as a common jpg format image (uint8: 80-255), the data accuracy will be lost. If it is saved as an .npy file Sometimes the file size is too large (eg: 1280*1920 depth array takes up 37.5Mb after saving), so the data needs to be processed before saving.

1. Consider converting float32 data to uint16 or int16 data based on the accuracy information of the depth map. For example, the unit of the depth map obtained by commonly used lidar is meters, and we take the accuracy as centimeters, then the array depth_map_m (1280x1920) containing depth information is converted from meters The unit of float64 is converted to uint16 in centimeters, depth_map_cm

depth_map_cm = depth_map_m * 100
depth_map_cm_uint16 = depth_map_cm.astype(np.uint16)

2.1 The 16 depth maps can be stored in png, tif and other formats

cv2.imwrite(save_dir, depth_map_cm_uint16)

2.2 You can also store the 16 depth map in npy format

np.save(save_dir, depth_map_cm_uint16)

Storage options:

The two storage methods have their own advantages and disadvantages:
In terms of storage space:
cv2.imwrite: The obtained data is compressed, so it takes up less space. The png size obtained in the above example is only 521kb.
insert image description here
np.save: The obtained data takes up a lot of space. The above example obtains The size of the npy is 4.68mb.
insert image description here
In terms of reading speed:
cv2.imwrite: the subsequent loading of data is relatively slow, and the loading time of the above example is about 0.017s
np.save: the subsequent loading of data is fast, and the loading time of the above example is about 0.003s
insert image description here

You can choose according to your needs

Guess you like

Origin blog.csdn.net/SmaICG/article/details/130202932