-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
generate_training_data.m
48 lines (35 loc) · 1.39 KB
/
generate_training_data.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
%%
% Copyright (c) 2020-present, Mahmoud Afifi
%
% Please, cite the following paper if you use this code:
%
% Mahmoud Afifi and Michael S. Brown. Interactive White Balancing for
% Camera-Rendered Images. In Color and Imaging Conference (CIC), 2020.
%
% Email: mafifi@eecs.yorku.ca | m.3afifi@gmail.com
%%
function data = generate_training_data(TrDir)
images = imageDatastore(TrDir);
images = images.Files;
startpooling (6); %comment it if you do not have parallel computing toolbox
ills = zeros(length(images),3);
mfs = zeros(length(images),33);
parfor i = 1 : length(images) %use for instead of parfor if you do not have parallel computing toolbox
[~,basename,ext] = fileparts(images{i});
currname = [basename ext];
parts = strsplit(currname,'_');
parts = parts(1:end-2);
basename = '';
for p = 1 : length(parts)
basename = [basename parts{p} '_'];
end
gtname = [basename 'G_AS.png'];
I = im2double(imread(fullfile(TrDir,currname)));
GT = im2double(imread(fullfile(TrDir,gtname)));
ills(i,:) = illumgray(I); %grayworld estimation (you can replace it with other ill estimation
%methods, but be sure that you will use the same method in the testing phase).
mfs(i,:) = reshape(PHI(reshape(I,[],3))\reshape(GT,[],3),1,[]); %compute polynomial mapping function
end
data.mapping_Funcs = mfs;
data.ills = ills;
save('data.mat','data','-v7.3');