Skip to content

Commit

Permalink
add resize human masks option
Browse files Browse the repository at this point in the history
  • Loading branch information
vorozhkog committed Oct 25, 2024
1 parent 9c53153 commit 0bc2b26
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"modal_template": "src/modal.html",
"modal_template_state": {
"humanMasks": true,
"resizeHumanMasks": false,
"resizePercentze": 100,
"machineMasks": true,
"instanceMasks": false,
"thickness": 2
Expand Down
2 changes: 2 additions & 0 deletions src/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
12 changes: 11 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions src/modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
description="Semantic segmentation RGB masks with colors of classes. (0, 0, 0) is for background (unlabeled area)">
<el-checkbox v-model="state.humanMasks">enable</el-checkbox>
</sly-field>
<sly-field v-if="state.humanMasks"
title="Resize Human masks"
description="Whether to resize human masks or not. Input the number ">
<el-checkbox v-model="state.resizeHumanMasks">enable</el-checkbox>
</sly-field>
<sly-field v-if="state.humanMasks && state.resizeHumanMasks"
title="Resize percentage"
description="The percentage to resize human masks by">
<el-input-number v-model="state.resizePercent" :min="1" :max="100"></el-input-number>
</sly-field>
<sly-field title="Machine masks"
description="Additional RGB masks for NN where colors are the indices of classes">
<el-checkbox v-model="state.machineMasks">enable</el-checkbox>
Expand Down

0 comments on commit 0bc2b26

Please sign in to comment.