create_lut.py
1.35 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
55
#!/usr/bin/env python
import sys
import numpy as np
def beautifier(c):
dc = c[1]-c[0]
new_c = [(0.0, c[0], c[0])]
n = np.linspace(0, 1, len(c))
eps = 1.0/ float(len(c))
for i in range(len(c)-1):
if abs((c[i+1]-c[i]) - dc) > eps:
#new_c.append((n[i-1], c[i-1], c[i-1]))
new_c.append((n[i], c[i], c[i]))
dc = c[i+1]-c[i]
new_c.append((n[-1], c[-1], c[-1]))
return new_c
def main(argv):
if len(argv) < 2:
print "usage ", argv[0], "lut-filename"
sys.exit(1)
lut_file = argv[1]
lut = np.loadtxt(lut_file)[3:245] # nod2 lut range
r2 = lut[:, 1] / 255.0
r = beautifier(r2)
g2 = lut[:, 2] / 255.0
g = beautifier(g2)
b2 = lut[:, 3] / 255.0
b = beautifier(b2)
# creating dictionary
k = ['red', 'green', 'blue']
color = {}
color['red'] = r
color['green'] = g
color['blue'] = b
print "_nod3_XXX_data = {"
for c in k:
col = color[c]
print " '%s': [%s," % (c, str(col[0]))
for n in range(1, len(col)-1, 1):
print " %s," % str(col[n])
if c != k[-1]:
print " %s],\n" % str(col[-1])
else:
print " %s]" % str(col[-1]),
print "}\n"
if __name__ == '__main__':
main(sys.argv)