-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawer_tmp.py
More file actions
54 lines (43 loc) · 1.36 KB
/
drawer_tmp.py
File metadata and controls
54 lines (43 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from cmath import pi
from typing import Union, Any
import numpy as np
from matplotlib import pyplot as plt
import sys
from subprocess import Popen, PIPE
def useless_func():
a = np.random.randn(256, 256, 3)
a = np.abs(a)
a[a > 1] = 0
plt.imshow(a)
plt.axis(False)
plt.show()
def brightness_normalise(arr, out, H, W):
norm = 1
if np.percentile(np.array(out[3:], dtype='float'), 99.95) != 0:
norm = np.percentile(np.array(out[3:], dtype='float'), 99.95)
arr /= norm
for i in range(0, H):
for j in range(0, W):
arr[i][j][0] = min(arr[i][j][0], 1)
arr[i][j][1] = min(arr[i][j][1], 1)
arr[i][j][2] = min(arr[i][j][2], 1)
return arr
def draw_men_with_dumplings_lol(PATH=None):
'''
input: (C, H, W) matrix
'''
if PATH is None:
sub_proc = Popen(["./run"], stdout=PIPE, universal_newlines=True)
(out, _) = sub_proc.communicate()
out = out.strip().split()
H, W, C = int(out[0]), int(out[1]), int(out[2])
picture = np.array(out[3:], dtype='float').reshape(H, W, C)
picture = brightness_normalise(picture, out, H, W)
plt.axis(False)
plt.imshow(picture)
plt.savefig('scene.png', dpi = 300)
if __name__ == "__main__":
PATH = None
if len(sys.argv) > 1:
PATH = sys.argv[1].strip()
draw_men_with_dumplings_lol(PATH)