Skip to content

Commit

Permalink
Create test_instances::test_masks_to_bboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Dec 30, 2023
1 parent d256998 commit 7a91048
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/test_instances.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import numpy as np

import imgviz


def test_masks_to_bboxes():
data = imgviz.data.arc2017()

class_label = data["class_label"]
masks = [class_label == label_id for label_id in np.unique(class_label)]
bboxes = imgviz.instances.masks_to_bboxes(masks)

assert len(bboxes) == len(masks)
assert bboxes.shape[1] == 4

ymin = bboxes[:, 0]
xmin = bboxes[:, 1]
ymax = bboxes[:, 2]
xmax = bboxes[:, 3]
height, width = class_label.shape
assert ((0 <= ymin) & (ymin <= height - 1)).all()
assert ((0 <= ymax) & (ymax <= height - 1)).all()
assert ((0 <= xmin) & (xmin <= width - 1)).all()
assert ((0 <= xmax) & (xmax <= width - 1)).all()

0 comments on commit 7a91048

Please sign in to comment.