-
Notifications
You must be signed in to change notification settings - Fork 2
/
analysis_colorSpace.py
106 lines (81 loc) · 2.92 KB
/
analysis_colorSpace.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
import matplotlib.pylab as plt
import numpy as np
from base import plot as pf
from colorSpace import colorSpace
space = colorSpace()
def trichromaticAnalysis(Lmax=560, Smax=417):
'''
'''
M_lamMax = []
volume = []
for i in range(420, 561):
M_lamMax.append(i)
space.genLMS('Neitz', [Lmax, i, Smax])
space.setLights('stiles and burch')
space.genConvMatrix()
volume.append(np.linalg.det(space.convMatrix))
fig = plt.figure()
fig.set_tight_layout(True)
ax = fig.add_subplot(111)
pf.AxisFormat()
pf.TufteAxis(ax, ['left', 'bottom'], Nticks=[5, 5])
ax.plot(M_lamMax, volume, 'k', linewidth=3)
ind = np.where(np.array(M_lamMax) == 530)[0]
ax.plot(M_lamMax[ind], volume[ind], 'g+', markersize=15,
markeredgewidth=3)
ax.set_ylabel('color space volume')
ax.set_xlabel('$M_{\lambda_{max}}$')
ax.text(0.5, 0.5,
('$L_{\lambda_{max}}$: ' + str(Lmax) + 'nm\n$S_{\lambda_{max}}$: '
+ str(Smax) + 'nm'),
fontsize=20,
horizontalalignment='center',
verticalalignment='top',
transform=ax.transAxes)
plt.show()
def tetrachromaticAnalysis(Lmax=560, Mmax=530, Smax=417):
'''
'''
X_lamMax = []
volume = []
space.genLMS('Neitz', [Lmax, Mmax, Smax])
for i in range(300, 850):
X_lamMax.append(i)
tetraSystem = space.genTetraConvMatrix(i)
volume.append(abs(np.linalg.det(tetraSystem)))
'''
if i % 10 == 0:
print i, 'nm, rank: ', np.linalg.matrix_rank(tetraSystem)
'''
fig = plt.figure()
fig.set_tight_layout(True)
ax = fig.add_subplot(111)
pf.AxisFormat()
pf.TufteAxis(ax, ['left', 'bottom'], Nticks=[5, 5])
ax.plot(X_lamMax, volume, 'k', linewidth=3)
ind = np.where(np.array(X_lamMax) == 495)[0]
ax.semilogy(X_lamMax[ind], volume[ind], 'g+', markersize=15,
markeredgewidth=3)
ax.set_ylabel('color space volume')
ax.set_xlabel('$X_{\lambda_{max}}$')
ax.text(0.2, 0.95,
('$L_{\lambda_{max}}$: ' + str(Lmax) + 'nm\n$M_{\lambda_{max}}$: '
+ str(Mmax) + 'nm\n$S_{\lambda_{max}}$: ' + str(Smax) + 'nm'),
fontsize=20,
horizontalalignment='center',
verticalalignment='top',
transform=ax.transAxes)
plt.show()
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description="Color Space: display Neitz or Stockman\
derived color spaces")
parser.add_argument("-t", "--tri", action="store_true",
help="trichromatic analysis plot")
parser.add_argument("-e", "--tetra", action="store_true",
help="tetrachromatic analysis plot")
args = parser.parse_args()
if args.tri:
trichromaticAnalysis()
if args.tetra:
tetrachromaticAnalysis()