From 0bc2b26c5ceded48d59e4b5690fde3d69461f1d6 Mon Sep 17 00:00:00 2001 From: vorozhkog Date: Fri, 25 Oct 2024 11:52:33 +0100 Subject: [PATCH] add resize human masks option --- config.json | 2 ++ src/globals.py | 2 ++ src/main.py | 12 +++++++++++- src/modal.html | 10 ++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/config.json b/config.json index d2dafe9..d6c3340 100644 --- a/config.json +++ b/config.json @@ -13,6 +13,8 @@ "modal_template": "src/modal.html", "modal_template_state": { "humanMasks": true, + "resizeHumanMasks": false, + "resizePercentze": 100, "machineMasks": true, "instanceMasks": false, "thickness": 2 diff --git a/src/globals.py b/src/globals.py index 40782e6..a1bcfb7 100644 --- a/src/globals.py +++ b/src/globals.py @@ -27,6 +27,8 @@ Image.MAX_IMAGE_PIXELS = None HUMAN_MASKS = bool(strtobool(os.environ["modal.state.humanMasks"])) +RESIZE_HUMAN_MASKS = bool(strtobool(os.environ["modal.state.resizeHumanMasks"])) +RESIZE_PERCENT = int(os.environ["modal.state.resizePercent"]) MACHINE_MASKS = bool(strtobool(os.environ["modal.state.machineMasks"])) INSTANCE_MASKS = bool(strtobool(os.environ["modal.state.instanceMasks"])) THICKNESS = int(os.environ["modal.state.thickness"]) diff --git a/src/main.py b/src/main.py index 68f8f39..262c123 100644 --- a/src/main.py +++ b/src/main.py @@ -84,9 +84,19 @@ def export_as_masks(api: sly.Api): (overlay.astype(np.uint16) + temp_overlay.astype(np.uint16)) / 2 ).astype(np.uint8) + array_to_write = np.concatenate([raw_img, overlay], axis=1) + + if g.RESIZE_HUMAN_MASKS: + new_dimensions = ( + int(overlay.shape[0] * (g.RESIZE_PERCENT / 100)), + int(overlay.shape[1] * (g.RESIZE_PERCENT / 100)), + overlay.shape[2], + ) + array_to_write = array_to_write.reshape(new_dimensions) + sly.image.write( os.path.join(human_masks_dir, mask_img_name), - np.concatenate([raw_img, overlay], axis=1), + array_to_write, ) if g.MACHINE_MASKS: diff --git a/src/modal.html b/src/modal.html index 2427b9e..8b9ca4a 100644 --- a/src/modal.html +++ b/src/modal.html @@ -7,6 +7,16 @@ description="Semantic segmentation RGB masks with colors of classes. (0, 0, 0) is for background (unlabeled area)"> enable + + enable + + + + enable