Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow flexible post-processing for larger segmentations #853

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions micro_sam/automatic_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,16 @@ def automatic_instance_segmentation(
segmenter.initialize(image=image_data, image_embeddings=image_embeddings, verbose=verbose)
masks = segmenter.generate(**generate_kwargs)

if len(masks) == 0: # instance segmentation can have no masks, hence we just save empty labels
if isinstance(segmenter, InstanceSegmentationWithDecoder):
this_shape = segmenter._foreground.shape
elif isinstance(segmenter, AMGBase):
this_shape = segmenter._original_size
if isinstance(masks, list):
# whether the predictions from 'generate' are list of dict,
# which contains additional info req. for post-processing, eg. area per object.
if len(masks) == 0:
instances = np.zeros(image_data.shape[-2:], dtype="uint32")
else:
this_shape = image_data.shape[-2:]

instances = np.zeros(this_shape, dtype="uint32")
instances = mask_data_to_segmentation(masks, with_background=True, min_object_size=0)
else:
instances = mask_data_to_segmentation(masks, with_background=True, min_object_size=0)
# if (raw) predictions provided, store them as it is w/o further post-processing.
instances = masks

else:
if (image_data.ndim != 3) and (image_data.ndim != 4 and image_data.shape[-1] != 3):
Expand Down