-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp_numLeds_onePlot.m
More file actions
280 lines (202 loc) · 8.79 KB
/
p_numLeds_onePlot.m
File metadata and controls
280 lines (202 loc) · 8.79 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
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
% This script is very similar to p_numLeds.m wit the exception that all
% plots are generated in one figure (for presentation purposes).
%
% Copyright, Henryk Blasinski 2017.
close all;
clear all;
clc;
% Provide non-empty destPath to save figure files.
destPath = [];
% destPath = fullfile(cmfRootPath,'..','Figures');
fName = fullfile(cmfRootPath,'Results','uniformApproxV3.mat');
load(fName);
set(groot,'defaultAxesColorOrder',[1 0 0; 0 1 0; 0 0 1]);
%% Version 1: (Figure. 5)
% Fix the illuminant chromaticity, vary the number and positions of leds,
% camera spectral responsivity. Show pixel approximation scatter plots,
% illuminant spectra estimates and illuminant chromaticity estimates.
% Pick regularization strength
figure;
set(gcf,'Position',[55 183 1373 912]);
set(gcf,'PaperPosition',[1 1 13 9]);
for a=10
% Pick illuminant chromaticity index
for xx=5
for yy=5
spd = xy2Spectrum( xVec(xx), yVec(yy), wave );
if sum(isnan(spd)) > 0
continue,
end
spdXYZ = ieXYZFromPhotons(spd,wave);
spdxy = spdXYZ(1:2)/sum(spdXYZ);
for s=1:nLedSets
nLEDs = length(ledSets{s});
spdEst = zeros(nWaves,nCameras);
spdEstXYZ = zeros(3,nCameras);
spdEstxy = zeros(2,nCameras);
for c=1:nCameras
spdEst(:,c) = flashSpd(:,ledSets{s})*squeeze(wghtEst(xx,yy,1:nLEDs,c,s,a));
spdEst(:,c) = spdEst(:,c)/max(spdEst(:,c));
spdEstXYZ(:,c) = ieXYZFromPhotons(spdEst(:,c)*10^10,wave);
spdEstxy(:,c) = spdEstXYZ(1:2,c)/sum(spdEstXYZ(:,c));
end
subplot(3,nLedSets,s);
hold on; grid on; box on;
chromaticityPlot([],'gray',256,false);
plot(spdxy(1),spdxy(2),'rd','lineWidth',2,'markerSize',10);
title(sprintf('%i LEDs',nLEDs));
for i=1:nLEDs
xyz = ieXYZFromPhotons(flashSpd(:,ledSets{s}(i)),wave);
plot(xyz(1)/sum(xyz),xyz(2)/sum(xyz),'+','lineWidth',2,'markerSize',10,'color',[0.5 0.5 0.5]);
end
plot(spdEstxy(1,:),spdEstxy(2,:),'kx');
xlabel('CIE x');
ylabel('CIE y');
appear = [measurement{xx,yy,:}];
appear = [appear(:).patch];
appear = [appear(:).ambient];
appear = appear./repmat(max(max(appear,[],1),[],3),[3 1 10*11]);
appear = permute(appear,[3,2,1]);
appear = reshape(appear,[10*11*nCameras,3]);
approx = squeeze(channelEstLin(xx,yy,:,:,:,s,a));
approx = permute(approx,[1,3,2]);
approx = reshape(approx,[11*10*nCameras, 3]);
subplot(3,nLedSets,s+nLedSets);
hold on; grid on; box on;
plot(approx,appear,'.');
xlim([0 1]);
ylim([0 1]);
xlabel('Approximated');
ylabel('Measured');
%}
avgSpdEst = mean(spdEst,2);
minSpdEst = min(spdEst,[],2);
maxSpdEst = max(spdEst,[],2);
spdTrue = spd/max(spd(:));
gf = spdTrue(:)\avgSpdEst(:);
err = sqrt(mean((spdTrue(:)*gf - avgSpdEst(:)).^2));
subplot(3,nLedSets,s+2*nLedSets);
hold on; grid on; box on;
fl = fill([wave; flipud(wave)],[maxSpdEst; flipud(minSpdEst)],[1 0.8 0.8]);
pl = plot(wave,[spdTrue*gf, avgSpdEst],'LineWidth',2);
set(pl(1),'Color','g');
set(pl(2),'Color','r');
set(fl,'EdgeColor','none');
xlabel('Wavelength, nm');
xlim([min(wave), max(wave)]);
% Direct least squares fit, we compute the approximation
% error up to a multiplicative scale on the estimate (i.e.
% first we find a gain parameter that minimizes the error,
% and then compute the error).
cvx_begin quiet
variable lsWeights(nLEDs,1)
minimize norm(spdTrue*gf - flashNorm(:,ledSets{s})*lsWeights)
subject to
flashNorm(:,ledSets{s})*lsWeights >= 0
cvx_end
errLs = sqrt(mean((spdTrue(:)*gf - flashNorm(:,ledSets{s})*lsWeights).^2));
plot(wave,flashNorm(:,ledSets{s})*lsWeights,'--b','LineWidth',2);
xlabel('Wavelength, nm');
ylabel('Intensity, au');
end
end
end
end
if ~isempty(destPath)
fName = fullfile(destPath,'variation_nLEDs.eps');
print('-depsc',fName);
end
%% Version 2 (Figure 6)
% Fix the number of LEDs, vary the illuminant chromaticity and camera
% spectral responsivity curves.
close all;
% Select the chromaticity indices of interest.
xxSel = [2 2 3 3 6];
yySel = [2 6 3 6 3];
a = 1; % Smoothness penalty
s = 5; % The fifth led set containing 7 LEDs
figure;
set(gcf,'Position',[55 183 1373 912]);
set(gcf,'PaperPosition',[1 1 13 9]);
for i=1:length(xxSel)
xx=xxSel(i);
yy=yySel(i);
spd = xy2Spectrum( xVec(xx), yVec(yy), wave );
if sum(isnan(spd)) > 0
continue,
end
spdXYZ = ieXYZFromPhotons(spd,wave);
spdxy = spdXYZ(1:2)/sum(spdXYZ);
nLEDs = length(ledSets{s});
spdEst = zeros(nWaves,nCameras);
spdEstXYZ = zeros(3,nCameras);
spdEstxy = zeros(2,nCameras);
for c=1:nCameras
spdEst(:,c) = flashSpd(:,ledSets{s})*squeeze(wghtEst(xx,yy,1:nLEDs,c,s,a));
spdEst(:,c) = spdEst(:,c)/max(spdEst(:,c));
spdEstXYZ(:,c) = ieXYZFromPhotons(spdEst(:,c)*10^10,wave);
spdEstxy(:,c) = spdEstXYZ(1:2,c)/sum(spdEstXYZ(:,c));
end
subplot(3,length(xxSel),i);
hold on; grid on; box on;
chromaticityPlot([],'gray',256,false);
plot(spdxy(1),spdxy(2),'rd','lineWidth',2,'markerSize',10);
title(sprintf('xy = (%.2f,%.2f)',xVec(xx),yVec(yy)));
for j=1:nLEDs
xyz = ieXYZFromPhotons(flashSpd(:,ledSets{s}(j)),wave);
plot(xyz(1)/sum(xyz),xyz(2)/sum(xyz),'+','lineWidth',2,'markerSize',10,'color',[0.5 0.5 0.5]);
end
plot(spdEstxy(1,:),spdEstxy(2,:),'kx');
xlabel('CIE x');
ylabel('CIE y');
appear = [measurement{xx,yy,:}];
appear = [appear(:).patch];
appear = [appear(:).ambient];
appear = appear./repmat(max(max(appear,[],1),[],3),[3 1 10*11]);
appear = permute(appear,[3,2,1]);
appear = reshape(appear,[10*11*nCameras,3]);
approx = squeeze(channelEstLin(xx,yy,:,:,:,s,a));
approx = permute(approx,[1,3,2]);
approx = reshape(approx,[11*10*nCameras, 3]);
subplot(3,length(xxSel),i + length(xxSel));
hold on; grid on; box on;
plot(approx,appear,'.');
xlim([0 1]);
ylim([0 1]);
xlabel('Approximated');
ylabel('Measured');
set(gca,'YTick',0:0.2:1);
avgSpdEst = mean(spdEst,2);
minSpdEst = min(spdEst,[],2);
maxSpdEst = max(spdEst,[],2);
spdTrue = spd/max(spd(:));
gf = spdTrue(:)\avgSpdEst(:);
err = sqrt(mean((spdTrue(:)*gf - avgSpdEst(:)).^2));
subplot(3,length(xxSel),i+2*length(xxSel));
hold on; grid on; box on;
fl = fill([wave; flipud(wave)],[maxSpdEst; flipud(minSpdEst)],[1 0.8 0.8]);
pl = plot(wave,[spdTrue*gf, avgSpdEst],'LineWidth',2);
set(pl(1),'Color','g');
set(pl(2),'Color','r');
set(fl,'EdgeColor','none');
xlabel('Wavelength, nm');
xlim([min(wave), max(wave)]);
% Direct least squares fit, we compute the approximation
% error up to a multiplicative scale on the estimate (i.e.
% first we find a gain parameter that minimizes the error,
% and then compute the error).
cvx_begin
variable lsWeights(nLEDs,1)
minimize norm(spdTrue*gf - flashNorm(:,ledSets{s})*lsWeights)
subject to
flashNorm(:,ledSets{s})*lsWeights >= 0
cvx_end
errLs = sqrt(mean((spdTrue(:)*gf - flashNorm(:,ledSets{s})*lsWeights).^2));
plot(wave,flashNorm(:,ledSets{s})*lsWeights,'--b','LineWidth',2);
xlabel('Wavelength, nm');
ylabel('Intensity, au');
end
if ~isempty(destPath)
fName = fullfile(destPath,'variation_Chromaticity.eps');
print('-depsc',fName);
end