Debian Codegraph @

examples/nchannel2rgb.py

raw symbols SCIP
1 #!/usr/bin/env python
2
3 import matplotlib.pyplot as plt
4 import numpy as np
5
6 import imgviz
7
8
9 def nchannel2rgb():
10 data = imgviz.data.arc2017()
11
12 nchannel_viz = imgviz.nchannel2rgb(data["res4"], dtype=np.float32)
13
14 H, W = data["rgb"].shape[:2]
15 nchannel_viz = imgviz.resize(nchannel_viz, height=H, width=W)
16 nchannel_viz = (nchannel_viz * 255).round().astype(np.uint8)
17
18 # -------------------------------------------------------------------------
19
20 plt.figure(dpi=200)
21
22 plt.subplot(121)
23 plt.title("rgb")
24 plt.imshow(data["rgb"])
25 plt.axis("off")
26
27 plt.subplot(122)
28 plt.title("res4 (colorized)")
29 plt.imshow(nchannel_viz)
30 plt.axis("off")
31
32 img = imgviz.io.pyplot_to_numpy()
33 plt.close()
34
35 return img
36
37
38 if __name__ == "__main__":
39 from base import run_example
40
41 run_example(nchannel2rgb)