-
Notifications
You must be signed in to change notification settings - Fork 0
/
predictingChromaticity.m
235 lines (190 loc) · 6.42 KB
/
predictingChromaticity.m
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
clear, clc, close all
%% Pre-flight
% Display Settings
plt.disp = 1; % Display figures?
d = DGdisplaydefaults;
% MB settings
min_l_scale = 0.62;
max_l_scale = 0.82;
max_s_scale = 0.05;
% Plot saving settings
plt.print = 0; % Save
if plt.print
warning('plt.print is enabled - you sure? This will overwrite existing figures.')
end
base = 'C:\Users\cege-user\Dropbox\Documents\MATLAB\Melanopsin_Computational\figs\predictingChromaticity';
%% Load Data
[T_SPD, T_SRF, T_SSF, T_lum, S_sh] = melcomp_loader(...
'SPD','Granada_sub',...
'SRF','Vrhel_nat_1',...
'SSF','SS10',...
'lum','CIE_10',...
'mel_offset',0);
%% Colorimetry
[LMSRI, lsri] = melcomp_colorimetry(T_SPD, T_SRF, T_SSF, T_lum, S_sh);
% generate colorimetry for the light source itself
[LMSRI_neutral, lsri_neutral] = melcomp_colorimetry(T_SPD, ones(S_sh(3),1), T_SSF, T_lum, S_sh);
%% Basic MB plot
if plt.disp
figure, hold on
DrawChromaticity('MB10')
% Plot surfaces
for i=1:size(T_SRF,2)
scatter(lsri(1,i,:),lsri(2,i,:),d.s,'filled','MarkerFaceAlpha',d.MFA)
end
% Plot illuminant only
scatter(lsri_neutral(1,:),lsri_neutral(2,:),d.s,'k','filled','MarkerFaceAlpha',d.MFA)
xticks([min(xlim),max(xlim)])
yticks([min(ylim),max(ylim)])
end
if plt.print
save2pdf([base,'\BasicMB_1.pdf'])
end
xlim([min_l_scale max_l_scale]);
ylim([0 max_s_scale]);
cleanTicks
if plt.print
save2pdf([base,'\BasicMB_2.pdf'])
end
%% First level signals
if plt.disp
figure('Position',[100,100,500,800]), hold on
views = {2,[90,0],[0,0]};
for j = 1:3
subplot(3,1,j), hold on
%DrawChromaticity('MB10')
for i=1:size(T_SRF,2)
scatter3(lsri_neutral(1,1,:),lsri_neutral(2,1,:),LMSRI(5,i,:),d.s,'filled','MarkerFaceAlpha',d.MFA)
end
scatter3(lsri_neutral(1,1,:),lsri_neutral(2,1,:),LMSRI_neutral(5,1,:),d.s,'k','filled','MarkerFaceAlpha',d.MFA)
view(views{j})
xlim([min_l_scale, max_l_scale])
ylim([0, max_s_scale])
cleanTicks
xlabel('{\itl}_{MB}');
ylabel('{\its}_{MB}');
zlabel('{\itI}');
end
end
if plt.print
save2pdf([base,'\CvsI.pdf'])
end
%% Second level signals
t = NaN;
if plt.disp
plt.names={'L','M','S','R','I'};
plt.N1 = [1,3,1,2,1,2]; % Plot numbers
plt.N2 = [2,5,3,3,5,5];
figure('Position',[100,100,500,800],'Renderer','opengl')
for i=1:6
sp(i)=subplot(3,2,i);
hold on
for j=1:size(T_SRF,2)
scatter3(sp(i),lsri_neutral(1,1,:),lsri_neutral(2,1,:),...
LMSRI(plt.N1(i),j,:)./LMSRI(plt.N2(i),j,:),...
d.s,'filled','MarkerFaceAlpha',d.MFA)
t(length(t)+1) = abs(min(min(corrcoef(lsri_neutral(2,1,:),LMSRI(plt.N1(i),j,:)./LMSRI(plt.N2(i),j,:)))));
end
scatter3(sp(i),lsri_neutral(1,1,:),lsri_neutral(2,1,:),...
LMSRI_neutral(plt.N1(i),1,:)./LMSRI_neutral(plt.N2(i),1,:),...
d.s,'k','filled','MarkerFaceAlpha',d.MFA)
xlabel('{\itl}_{MB}');
ylabel('{\its}_{MB}');
zlabel(sprintf('%s/%s',plt.names{plt.N1(i)},plt.names{plt.N2(i)}));
%axis fill; grid off
view(sp(i),[0,0]);
axis manual
xticks([])
yticks([])
end
plt.auto_rotate = 0;
plt.saveGif = 0; %save a 360 gif?
if plt.auto_rotate
spInd = [1,4,5,7,8,9];
k=1;
while k<360
for j = spInd
camorbit(sp(j),1,0,'data',[0 0 1]);
end
drawnow
if plt.saveGif
filename = [base,'\allComboSignals_rotating.gif'];% - 'signal combination'
frame = getframe(gcf);
im = frame2im(frame);
[A,map] = rgb2ind(im,256);
if k == 1
imwrite(A,map,filename,'gif','LoopCount',Inf,'DelayTime',0.005);
else
imwrite(A,map,filename,'gif','WriteMode','append','DelayTime',0.005);
end
k=k+1;
end
end
end
end
if plt.print
save2pdf([base,'\allComboSignals.pdf'])
end
avcc = nanmean(t); %average correlation coefficient, for l_MB only
stdcc = nanstd(t); %std correlation coefficient
%% Random Data
% Repeat of above, but with random data
LMSRI_rand = (randn(size(LMSRI,1),1,size(LMSRI,3))+5)*20;
for i=1:size(T_SPD,2)
lsri_rand(1:2,:,i) = LMSToMacBoyn(LMSRI_rand(1:3,:,i),T_SSF(:,1:3)',T_lum');
t_r(:,:,i) = LMSToMacBoyn(LMSRI_rand([1,2,4],:,i),[T_SSF(:,1:2)';T_SSF(:,4)'],T_lum');
t_i(:,:,i) = LMSToMacBoyn(LMSRI_rand([1,2,5],:,i),[T_SSF(:,1:2)';T_SSF(:,5)'],T_lum');
end
lsri_rand(3,:,:) = t_r(2,:,:); clear t_r
lsri_rand(4,:,:) = t_i(2,:,:); clear t_i
%------------% Repeat of previous section
if plt.disp
plt.names={'L','M','S','R','I'};
plt.N1 = [1,3,1,2,1,2]; % Plot numbers
plt.N2 = [2,5,3,3,5,5];
figure('Position',[100,100,500,800],'Renderer','opengl')
for i=1:6
sp(i)=subplot(3,2,i);
hold on
scatter3(sp(i),lsri_rand(1,1,:),lsri_rand(2,1,:),...
LMSRI_rand(plt.N1(i),1,:)./LMSRI_rand(plt.N2(i),1,:),...
d.s,'b','filled','MarkerFaceAlpha',d.MFA)
xlabel('{\itl}_{MB}');
ylabel('{\its}_{MB}');
zlabel(sprintf('%s/%s',plt.names{plt.N1(i)},plt.names{plt.N2(i)}));
%axis fill; grid off
view(sp(i),[0,0]);
axis manual
xticks([])
yticks([])
end
plt.auto_rotate = 0;
plt.saveGif = 0; %save a 360 gif?
if plt.auto_rotate
spInd = [1,4,5,7,8,9];
k=1;
while k<360
for j = spInd
camorbit(sp(j),1,0,'data',[0 0 1]);
end
drawnow
if plt.saveGif
filename = [base,'\allComboSignals_rotating_rand.gif'];% - 'signal combination'
frame = getframe(gcf);
im = frame2im(frame);
[A,map] = rgb2ind(im,256);
if k == 1
imwrite(A,map,filename,'gif','LoopCount',Inf,'DelayTime',0.005);
else
imwrite(A,map,filename,'gif','WriteMode','append','DelayTime',0.005);
end
k=k+1;
end
end
end
end
view(sp(3),[99,5]) %these will change slightly - random data
view(sp(4),[75,-10])
if plt.print
save2pdf([base,'\allComboSignals_rand.pdf'])
end