Skip to content

Commit

Permalink
Remove small noisy objects from mask
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Dec 2, 2023
1 parent 8d9541a commit 4ba6277
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion labelme/ai/models/segment_anything.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import onnxruntime
import PIL.Image
import skimage.measure
import skimage

from ...logger import logger

Expand Down Expand Up @@ -175,6 +175,12 @@ def _compute_mask_from_points(
masks, _, _ = decoder_session.run(None, decoder_inputs)
mask = masks[0, 0] # (1, 1, H, W) -> (H, W)
mask = mask > 0.0

MIN_SIZE_RATIO = 0.05
skimage.morphology.remove_small_objects(
mask, min_size=mask.sum() * MIN_SIZE_RATIO, out=mask
)

if 0:
imgviz.io.imsave(
"mask.jpg", imgviz.label2rgb(mask, imgviz.rgb2gray(image))
Expand Down

0 comments on commit 4ba6277

Please sign in to comment.