Debian Codegraph @

getting_started.py

raw symbols SCIP
1 #!/usr/bin/env python
2 # flake8: noqa
3
4 import os.path as osp
5
6 import matplotlib.pyplot as plt
7
8 here = osp.dirname(osp.abspath(__file__)) # NOQA
9
10 # -----------------------------------------------------------------------------
11 # GETTING_STARTED {{
12 import imgviz
13
14 # sample data of rgb, depth, class label and instance masks
15 data = imgviz.data.arc2017()
16
17 rgb = data["rgb"]
18 gray = imgviz.rgb2gray(rgb)
19
20 # colorize depth image with JET colormap
21 depth = data["depth"]
22 depthviz = imgviz.depth2rgb(depth, min_value=0.3, max_value=1)
23
24 # colorize label image
25 class_label = data["class_label"]
26 labelviz = imgviz.label2rgb(
27 class_label, image=gray, label_names=data["class_names"], font_size=20
28 )
29
30 # instance bboxes
31 bboxes = data["bboxes"].astype(int)
32 labels = data["labels"]
33 masks = data["masks"] == 1
34 captions = [data["class_names"][l] for l in labels]
35 maskviz = imgviz.instances2rgb(gray, masks=masks, labels=labels, captions=captions)
36
37 # tile instance masks
38 insviz = [
39 (rgb * m[:, :, None])[b[0] : b[2], b[1] : b[3]] for b, m in zip(bboxes, masks)
40 ]
41 insviz = imgviz.tile(imgs=insviz, border=(255, 255, 255))
42 insviz = imgviz.resize(insviz, height=rgb.shape[0])
43
44 # tile visualization
45 tiled = imgviz.tile(
46 [rgb, depthviz, labelviz, maskviz, insviz],
47 shape=(1, 5),
48 border=(255, 255, 255),
49 border_width=5,
50 )
51 # }} GETTING_STARTED
52 # -----------------------------------------------------------------------------
53
54 out_file = osp.join(here, ".readme/getting_started.jpg")
55 imgviz.io.imsave(out_file, tiled)
56
57 img = imgviz.io.imread(out_file)
58 plt.imshow(img)
59 plt.axis("off")
60 plt.show()