Skip to content

Commit

Permalink
Fix a couple of bounding boxes bugs
Browse files Browse the repository at this point in the history
1.  The automatic verison of SAM also adds a 'bbox' entry to the
    dictionary which is the bounding box surrounding the segmented mask.
    Rename 'bbox' to 'prompt_bbox' when it it refers to the bounding
    box used a prompt.  This will separate the two slightly different
    versions of bounding box.

 2.  Change viewer to 2D mode when adding bounding boxes.  It seems an
     error occurs if adding a 2D bounding box to the shapes layer if the
     viewer is in 3D mode.
  • Loading branch information
bnorthan committed Apr 21, 2024
1 parent 5aa700e commit 9e39842
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/napari_segment_everything/segment_everything.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def process(self):
bounding_boxes = get_bounding_boxes(self.image, imgsz=1024, device='cuda')
self.results = get_mobileSAMv2(self.image, bounding_boxes)
for result, bbox in zip(self.results, bounding_boxes):
result["bbox"] = bbox
result["prompt_bbox"] = bbox
self.results = sorted(
self.results, key=lambda x: x["area"], reverse=False
)
Expand Down Expand Up @@ -634,9 +634,11 @@ def add_points(self):
def add_boxes(self):
# delete old boxes
self._boxes_layer.data = []
self.viewer.dims.ndisplay = 2
for result in self.results:
# if point_coords is a key
if "bbox" in result:
bbox = result["bbox"]
if "prompt_bbox" in result:
bbox = result["prompt_bbox"]
bbox = [[bbox[1], bbox[0]], [bbox[3], bbox[2]]]
self._boxes_layer.add(bbox)
self.viewer.dims.ndisplay = 3

0 comments on commit 9e39842

Please sign in to comment.