File: test_instances.py

package info (click to toggle)
python-imgviz 1.7.5%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,084 kB
  • sloc: python: 3,229; makefile: 15
file content (24 lines) | stat: -rw-r--r-- 685 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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()