Skip to content

Commit 911c4d8

Browse files
committed
automatic_masking: support 16-bit images
1 parent 0303be5 commit 911c4d8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/automatic_masking.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,20 @@ def process_camera(image_mask_dir, c, camera_index):
101101
image_mask_path = str(image_mask_dir / image_mask_name) + "_mask.png"
102102

103103
photo_image = c.photo.image()
104-
img = np.frombuffer(photo_image.tostring(), dtype={'U8': np.uint8, 'U16': np.uint16}[photo_image.data_type]).reshape(photo_image.height, photo_image.width, photo_image.cn)[:, :, :3]
104+
105+
image_types_mapping = {'U8': np.uint8, 'U16': np.uint16}
106+
if photo_image.data_type not in image_types_mapping:
107+
print("Image type is not supported yet: {}".format(photo_image.data_type))
108+
if photo_image.cn not in {3, 4}:
109+
print("Image channels number not supported yet: {}".format(photo_image.cn))
110+
img = np.frombuffer(photo_image.tostring(), dtype=image_types_mapping[photo_image.data_type]).reshape(photo_image.height, photo_image.width, photo_image.cn)[:, :, :3]
111+
112+
if photo_image.data_type == "U16":
113+
assert img.dtype == np.uint16
114+
img = img - np.min(img)
115+
img = np.float32(img) * 255.0 / np.max(img)
116+
img = (img + 0.5).astype(np.uint8)
117+
assert img.dtype == np.uint8
105118

106119
img = Image.fromarray(img)
107120
max_downscale = 4

0 commit comments

Comments
 (0)