From 7a9104892c069c52e4cbd04e6751adfdbc176e08 Mon Sep 17 00:00:00 2001 From: Kentaro Wada Date: Sat, 30 Dec 2023 15:49:11 +0900 Subject: [PATCH] Create test_instances::test_masks_to_bboxes --- tests/test_instances.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/test_instances.py diff --git a/tests/test_instances.py b/tests/test_instances.py new file mode 100644 index 0000000..596fd05 --- /dev/null +++ b/tests/test_instances.py @@ -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()