Skip to content

Commit

Permalink
update single_cell.py: accelerate bulk bbox iou calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
dummyindex committed Dec 2, 2023
1 parent f43207e commit 1e4ac7d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions livecellx/core/single_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ def compute_overlap_percent(self, other_cell: "SingleCellStatic", bbox=None):
def compute_iou(self, other_cell: "SingleCellStatic", bbox=None):
if bbox is None:
bbox = self.bbox
# Compare bbox, if not overlap, return 0
other_cell_bbox = other_cell.bbox
if not (
other_cell_bbox[0] <= bbox[2]
and other_cell_bbox[2] >= bbox[0]
and other_cell_bbox[1] <= bbox[3]
and other_cell_bbox[3] >= bbox[1]
):
return 0

mask = self.get_contour_mask(bbox=bbox).astype(bool)
overlap_mask = self.compute_overlap_mask(other_cell, bbox=bbox)
return np.sum(overlap_mask) / (
Expand Down

0 comments on commit 1e4ac7d

Please sign in to comment.