-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhd108calc.py
executable file
·162 lines (121 loc) · 3.35 KB
/
hd108calc.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python3
import sys
import time
import csv
import matplotlib.pyplot as plt
import numpy as np
import math
# best match so far
rconst = 1.000
gconst = 0.760
bconst = 0.550
ra = []
ga = []
ba = []
rq = []
gq = []
bq = []
ri = []
gi = []
bi = []
rc = []
gc = []
bc = []
rd = []
gd = []
bd = []
'''
-a * exp(-b * 1) + a = 1
(1 - a) / - a = e ^ (-b)
-log((1-a)/(-a)) = b
a * (-exp(-b) + 1) = 1
1 / (-exp(-b) + 1)
'''
def rfunc(x, b):
return x
def rifunc(x, b):
return x
def gfunc(x, b):
a = 1.0 / (-np.exp(-b) + 1.0)
return -a * np.exp(-b * x) + a
def gifunc(x, b):
a = 1.0 / (-np.exp(-b) + 1.0)
return np.log((x - a) / -a) / -b
def bfunc(x, b):
a = 1.0 / (-np.exp(-b) + 1.0)
return -a * np.exp(-b * x) + a
def bifunc(x, b):
a = 1.0 / (-np.exp(-b) + 1.0)
return np.log((x - a) / -a) / -b
def main():
with open('hd108data_g0i0rg31gg31bg31_255_65535.txt', newline='\n') as csvfile:
csvreader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in csvreader:
ra.append(float(row[1]))
ga.append(float(row[2]))
ba.append(float(row[3]))
rmax = max(ra)
gmax = max(ga)
bmax = max(ba)
for i in range(len(ra)):
ra[i] /= rmax;
for i in range(len(ga)):
ga[i] /= gmax;
for i in range(len(ba)):
ba[i] /= bmax;
rd = ra.copy()
gd = ga.copy()
bd = ba.copy()
for i in range(len(ra)):
rd[i] = rifunc(rd[i], rconst);
for i in range(len(ga)):
gd[i] = gifunc(gd[i], gconst);
for i in range(len(ba)):
bd[i] = bifunc(bd[i], bconst);
for i in np.arange(0, 1, 1/256):
rq.append(rfunc(i, rconst))
for i in np.arange(0, 1, 1/256):
gq.append(gfunc(i, gconst))
for i in np.arange(0, 1, 1/256):
bq.append(bfunc(i, bconst))
for i in np.arange(0, 1, 1/256):
ri.append(rifunc(i, rconst))
for i in np.arange(0, 1, 1/256):
gi.append(gifunc(i, gconst))
for i in np.arange(0, 1, 1/256):
bi.append(bifunc(i, bconst))
rc = ra.copy()
gc = ga.copy()
bc = ba.copy()
# this correction map makes sure that
# the response curve is monotone
monotone_map = [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x0F, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D
]
# for i in range(len(ra)):
# rc[i] = ra[monotone_map[(i&0x1F)]+(i&(~0x1F))]
# gc[i] = ga[monotone_map[(i&0x1F)]+(i&(~0x1F))]
# bc[i] = ba[monotone_map[(i&0x1F)]+(i&(~0x1F))]
plt.grid(True,'both','both')
plt.xticks(np.arange(-1, 1023, step=16))
plt.plot(ra, color='salmon', linestyle='dashed')
plt.plot(ga, color='limegreen', linestyle='dashed')
plt.plot(ba, color='royalblue', linestyle='dashed')
plt.plot(rq, color='darkred')
plt.plot(gq, color='forestgreen')
plt.plot(bq, color='darkblue')
# plt.plot(ri, color='darkred')
# plt.plot(gi, color='forestgreen')
# plt.plot(bi, color='darkblue')
# plt.plot(rd, color='darkred')
# plt.plot(gd, color='forestgreen')
# plt.plot(bd, color='darkblue')
# plt.plot(rc, color='darkred')
# plt.plot(gc, color='forestgreen')
# plt.plot(bc, color='darkblue')
plt.show()
if __name__ == '__main__':
sys.exit(main())