Save image in 16bit

I wonder is there anyway to save the depth in 16bits image (PNG) instead of 8bits.

In, there are lines doing as follows. But the input data is already 8bit.

def save_image(self, img_type, image_data, filename):
    if img_type == "RGB":
        # Save ground truth data locally as png
        rgb_img = Image.fromarray(image_data, "RGBA")"{self.rgb_folder}/{filename}.png")
    elif img_type == "DEPTH":
        # Convert linear depth to inverse depth for better visualization
        image_data = image_data * 100
        image_data = np.reciprocal(image_data)
        # Save ground truth data locally as png
        image_data[image_data == 0.0] = 1e-5
        image_data = np.clip(image_data, 0, 255)
        image_data -= np.min(image_data)
        image_data /= np.max(image_data)
        depth_img = Image.fromarray((image_data * 255.0).astype(np.uint8))"{self.depth_folder}/{filename}.png")

The raw depth data is a float array received via get_sensor_host_float_texture_array() call. Given, that the data is 32 bits, you should be able to save it in 16 bits image.

1 Like