-
Notifications
You must be signed in to change notification settings - Fork 0
/
per.py
executable file
·163 lines (127 loc) · 5.57 KB
/
per.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
163
# Calculates singularity for each chroma (n) (--chroma n) and gives grid for when a chroma is fixed (--grid)
import numpy as np
import scipy as sp
import math
import csv
import matplotlib.pyplot as plt
from numpy import *
import sys
import argparse
from munsell_wcs import build_wcs_map, build_chiplist, lookup_chip, create_chroma_grid
daylight_data = np.genfromtxt('/home/aurimas/Amgen/amgen_2013/data/lut.fi/daylight/baso4.asc', delimiter = '')
daylight_data_1 = np.genfromtxt('/home/aurimas/Amgen/amgen_2013/data/lut.fi/daylight/tree.asc', delimiter = '')
daylight_data_2 = np.genfromtxt('/home/aurimas/Amgen/amgen_2013/data/lut.fi/daylight/sky.asc', delimiter = '')
reflectance_data = np.genfromtxt('/home/aurimas/Amgen/amgen_2013/data/lut.fi/mglossy_all/munsell380_780_1_glossy.asc', delimiter = '')
sensitivity_data = np.genfromtxt('/home/aurimas/Amgen/perception/linss2_10e_1.csv', delimiter = ',')
baso4 = daylight_data.T;
tree = daylight_data_1.T;
sky = daylight_data_2.T;
print '-' * 33
A = zeros((3,3,1600,))
B1 = zeros(1600)
B2 = zeros(1600)
c = csv.writer(open("eigenvalues.csv", "w"))
for x in range(1600):
U0 = zeros((3,15))
U1 = zeros((3,15))
V0 = zeros((3,15))
V1 = zeros((3,15))
for k in range(15):
for i in range(3):
U0[i,k] = np.sum(np.multiply(sensitivity_data[0:388:4,i+1],tree[0:97,k]))
U1[i,k] = np.sum(np.multiply(sensitivity_data[0:388:4,i+1],baso4[0:97,k]))
V0[i,k] = np.sum(np.multiply(np.multiply(sensitivity_data[0:388:4,i+1],reflectance_data[10:398:4,x]),tree[0:97,k]))
V1[i,k] = np.sum(np.multiply(np.multiply(sensitivity_data[0:388:4,i+1],reflectance_data[10:398:4,x]),baso4[0:97,k]))
U2 = zeros((3,22))
V2 = zeros((3,22))
for l in range(22):
for j in range(3):
U2[j, l] = np.sum(np.multiply(sensitivity_data[0:388:4,j+1],sky[0:97,l]))
V2[j, l] = np.sum(np.multiply(np.multiply(sensitivity_data[0:388:4,j+1],reflectance_data[10:398:4,x]),sky[0:97,l]))
U = np.concatenate((U0,U1,U2),axis=1)
V = np.concatenate((V0,V1,V2),axis=1)
U_pinv = np.linalg.pinv(U)
A[:,:,x] = np.dot(V,U_pinv)
D,E = linalg.eig(A[:,:,x]);
if D.dtype == np.complex128:
D=D.real
B1[x] = abs (D[0]) / abs(D[1]) # special case 1: first type of singularity - variation in incoming light produces strong variation in the reflected light along one direction
#print B1[x]
B2[x] = abs(D[1]) / abs(D[2]) # special case 2: second type of singularity - variation in incoming light only produces strong variations in the reflected light along two directions
b1 = B1.max()
b1_1 = B1.min()
b2 = B2.max()
B = zeros(1600)
for x in range (1600):
B[x] = max(B1[x]/b1,B2[x]/b2)
wcs_map = build_wcs_map()
chips = build_chiplist()
wcs_chip = wcs_map['C2']
parser = argparse.ArgumentParser(description='Calculate Singularity')
parser.add_argument('--chroma', type=int, default=-1)
parser.add_argument('--grid', action='store_true', default=False)
args = parser.parse_args()
hue_x = np.empty((8, 40))
hue_b1 = np.empty((8, 40))
hue_b2 = np.empty((8, 40))
for row in xrange(1, 9):
R = chr(ord('A') + row)
for col in xrange(1, 41):
idx = '%s%d' % (R, col)
wcs_chip = wcs_map[idx]
if args.chroma > 0:
chroma = args.chroma
do_fallback = True
do_fallthrough = True
else:
chroma = wcs_chip['chroma']
do_fallback = True
do_fallthrough = False
chip = lookup_chip(wcs_chip['hue'], wcs_chip['value'], chroma, chips, fallback=do_fallback, fallthrough=do_fallthrough)
# print idx, chip['index'], B[chip['index']]
hue_x[row-1, col-1] = B[chip['index']]
hue_b1[row-1, col-1] = B1[chip['index']]
hue_b2[row-1, col-1] = B2[chip['index']]
fig = plt.figure()
ax = fig.add_subplot([1,2][args.grid],1,1)
plt.imshow(hue_x, interpolation='nearest')
chroma_str = ('WCS', '%d' % args.chroma)
ax.set_title('Singularities for %s' % chroma_str[args.chroma > 0])
plt.gca().invert_yaxis()
plt.yticks([0, 1, 2, 3, 4, 5, 6, 7], ['B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'])
plt.colorbar(shrink=[0.8])
fig.set_size_inches(30,5)
cbar = plt.colorbar(shrink=[0.6,0.6][args.grid])
#cbar.set_ticks(xrange(np.min(B[:]), np.max(B[:]), ))
#fig_b1 = plt.figure() # First type of singularity: strong variation along one direction
#ax_b1 = fig_b1.add_subplot([1,2][args.grid],1,1)
#plt.imshow(hue_b1, interpolation='nearest')
#chroma_str = ('WCS', '%d' % args.chroma)
#ax_b1.set_title('Singularity along one direction for chroma %s' % chroma_str[args.chroma > 0])
#plt.gca().invert_yaxis()
#plt.yticks([0, 1, 2, 3, 4, 5, 6, 7], ['B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'])
#cbar = plt.colorbar(shrink=[0.27, 0.5][args.grid])
#print B1
#print ('-') * 33
#fig_b2 = plt.figure() # Second type of singularity: strong variation along two directions
#ax_b2 = fig_b2.add_subplot([1,2][args.grid],1,1)
#plt.imshow(hue_b2, interpolation='nearest')
#chroma_str = ('WCS', '%d' % args.chroma)
#ax_b2.set_title('Singularity along two directions for chroma %s' % chroma_str[args.chroma > 0])
#plt.gca().invert_yaxis()
#plt.yticks([0, 1, 2, 3, 4, 5, 6, 7], ['B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'])
#cbar = plt.colorbar(shrink=[0.27, 0.5][args.grid])
##print B2
print ('-') * 33
if args.grid:
ax = fig.add_subplot(2,1,2)
ax.set_title('Chroma grid')
grid = create_chroma_grid(wcs_map, chips, args.chroma) #np.empty((8, 40))
pic = plt.imshow(grid, interpolation='nearest')
plt.gca().invert_yaxis()
plt.yticks([0, 1, 2, 3, 4, 5, 6, 7], ['B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'])
cbar = plt.colorbar(pic, shrink=0.5)
cbar.set_ticks(xrange(2, 18, 2))
# fig.set_dpi(200)
plt.savefig('WCS Singularity.eps',dpi=300)
plt.show()