-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths_evalPoolGlobal.m
More file actions
172 lines (118 loc) · 4.47 KB
/
s_evalPoolGlobal.m
File metadata and controls
172 lines (118 loc) · 4.47 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
% This script demonstrates how the complementary spectral flash works
% on real data captured in a swimming pool at about 5m.
%
% Copyright, Henryk Blasinski 2017
close all;
clear all;
clc;
ieInit;
%%
set(groot,'defaultAxesColorOrder',[1 0 0; 0 1 0; 0 0 1]);
wave = 400:5:700;
nWaves = length(wave);
desiredIll = 'D65';
% If the resDir is empty, no fiures will be saved.
% resDir = fullfile(cmfRootPath,'..','Figures');
resDir = [];
fName = fullfile(cmfRootPath,'Parameters','ximeaLights');
flashSpd = ieReadSpectra(fName,wave);
flashSpd = Energy2Quanta(wave,flashSpd);
flashNorm = flashSpd/max(flashSpd(:));
nLEDs = size(flashSpd,2);
fName = fullfile(cmfRootPath,'Parameters','macbethChart');
reflRef = ieReadSpectra(fName,wave);
% Create base sensor model
fName = fullfile(cmfRootPath,'Parameters','XimeaSpectralResponsivities');
cameraResp = ieReadColorFilter(wave,fName);
sensorBase = sensorCreate('bayer (bggr)');
sensorBase = sensorSet(sensorBase,'wave',wave);
sensorBase = sensorSet(sensorBase,'size',[1024 1280]);
sensorBase = sensorSet(sensorBase,'noise flag',0);
sensorBase = sensorSet(sensorBase,'filter transmissivities',cameraResp);
cameraMat = sensorGet(sensorBase,'filter transmissivities');
nFilters = size(cameraMat,2);
dataDir = fullfile(cmfRootPath,'..','Data','Pool','2016-02-05_22-23-22');
cp = [459 644;752 653;754 467;466 458];
[ measurement, mask, cp ] = readXimeaImageStack(dataDir,2,nLEDs,'cp',cp);
%% Ambient estimate
% Global: all image pixels
[ ambientEst, ambientWghts, ambientPredictions ] = globalAmbientEst( measurement.downsampled.ambient,...
measurement.downsampled.led, ...
flashNorm,...
'alpha',1e2);
% Patch: Macbeth patches only
[ ambientEstPatch, ambientWghtsPatch, ambientPredictionsPatch ] = globalAmbientEst( measurement.patch.ambient,...
measurement.patch.led, ...
flashNorm,...
'alpha',1);
% Plot the quality of the approximation in camera RGB space
figure;
hold on; grid on; box on;
plot(squeeze(measurement.patch.ambient)',ambientPredictionsPatch','o');
xlabel('Ambient appearance');
ylabel('Approximated');
title('RGB space');
%% Render ambient approximation image
[~, ip] = renderFlashImage(zeros(size(measurement.raw.ambient)),measurement.raw.led,ambientWghts,...
sensorBase,'name','Ambient approximation');
image = ipGet(ip,'data srgb');
figure; imshow(image,'Border','tight');
if isempty(resDir) == false
fName = fullfile(resDir,sprintf('Pool_ambientApprox.eps'));
print('-depsc',fName);
end
%% Complement estimate
ill = illuminantCreate(desiredIll,wave);
desiredSpectrum = illuminantGet(ill,'photons');
[ flashEst, flashWghts ] = globalComplementEst( desiredSpectrum, ambientEst, flashNorm, cameraResp,...
'flashMode',true);
% Plot the illuminant spectra
figure;
hold on; grid on; box on;
plot(wave,ambientEst,'LineWidth',2);
plot(wave,flashNorm*flashWghts,'LineWidth',2);
xlabel('Wavelength, nm','Interpreter','Latex','FontSize',6);
set(gca,'TickLabelInterpreter','Latex');
mx = max([ambientEst(:); flashNorm*flashWghts]);
ylim([-0.05*mx 1.05*mx]);
set(gcf,'Units','Centimeters');
set(gca,'FontSize',6);
set(gcf,'PaperPosition',[1 1 4 3.25]);
if isempty(resDir) == false
fName = fullfile(resDir,sprintf('Pool_spectra.eps'));
print('-depsc',fName);
end
%% Complementary flash
% Render an image as if captured with the complementary flash.
[~, ip] = renderFlashImage(measurement.raw.ambient,measurement.raw.led,flashWghts,...
sensorBase,'name',sprintf('Computational-complement : %s',desiredIll));
image = ipGet(ip,'data srgb');
figure; imshow(image,'Border','tight');
if isempty(resDir) == false
fName = fullfile(resDir,sprintf('Pool_flashComplement.eps'));
print('-depsc',fName);
end
%% Matching flash
matchingAmbWghts = ambientWghts./max(ambientWghts);
[~, ip] = renderFlashImage(measurement.raw.ambient,measurement.raw.led,matchingAmbWghts,...
sensorBase,'name',sprintf('Computational-matching : %s',desiredIll));
image = ipGet(ip,'data srgb');
figure; imshow(image,'Border','tight');
if isempty(resDir) == false
fName = fullfile(resDir,sprintf('Pool_flashMatch.eps'));
print('-depsc',fName);
end
%% Save data
% destDir = fullfile(cmfRootPath,'..','Figures');
destDir = [];
ieImages = vcGetObjects('vcimage');
for i=1:length(ieImages)
image = ipGet(ieImages{i},'data srgb');
name = ipGet(ieImages{i},'name');
figure;
imshow(image);
title(name);
if isempty(destDir) == false
imwrite(image,fullfile(destDir,sprintf('Pool_%s.png',name)));
end
end