-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcreateMultipleH5_SyntheticImages.m
106 lines (95 loc) · 3.78 KB
/
createMultipleH5_SyntheticImages.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
global no_fast
no_fast = true;
% Following is sample test-case for verifying if everything is working
% correctly.
runSIRFS = true; %false;
sizePerH5 = 2;
data_path = './synImages/';
path = '../Light-Estimation/LDAN/data/synHao/' %'../data/crop_resize_maskout/';
Files=dir(path);
clear shflatten;
shflatten = [];
im = [];
normals = [];
shadings = [];
finalLoss = [];
reflectances = [];
heights = [];
num = length(Files);
for k=3:num
disp('K IS --------');
disp(k);
filename = strcat(path, Files(k).name); %'000001.jpg.png');
%fileN = imread(filename);
data = h5read(filename, '/data_1');
% reading and converting synthetic images
allFiles = uint8(permute(data, [3, 2, 1, 4]));
% enf of reading
[~, ~, ~, Size] = size(allFiles);
for j=1:Size
fileN = allFiles(:,:,:,j);
rotated = permute(fileN, [2, 1, 3]);
im = cat(4, im, rotated);
if runSIRFS
input_image = double(fileN)/255;
input_mask = all(input_image > 0,3);
output = SIRFS(input_image, input_mask, [], '');
disp(output.light);
shflatten = [ [shflatten] ; reshape(output.light, [27, 1])'];
% Normal is 64 x 64 x 3
normalOut = permute(output.normal, [2 1 3]);
normals = cat(4, normals, normalOut);
% Shading is 64 x 64 x 3
shadingOut = permute(output.shading, [2 1 3]);
shadings = cat(4, shadings, shadingOut);
% Reflectance is 64 x 64 x 3
reflOut = permute(output.reflectance, [2 1 3]);
reflectances = cat(4, reflectances, reflOut);
% Height is 64 x 64
htOut = permute(output.height, [2 1]);
heights = cat(3, heights, htOut);
% Final loss is scalar value
finalLoss = [[finalLoss]; output.final_loss];
end
if mod(k-2, sizePerH5) == 0
dataName = strcat(data_path, '/data_');
dataName = strcat(dataName, int2str((k-2) / sizePerH5));
dataName = strcat(dataName,'.h5')
h5create(dataName, '/Image', [64 64 3 sizePerH5], 'Datatype', 'uint8');
h5write(dataName, '/Image', im);
if runSIRFS
shOut = shflatten';
% Store Lighting
h5create(dataName, '/Lighting', [27 sizePerH5], 'Datatype', 'double');
h5write(dataName, '/Lighting', shOut);
% Store Normal
h5create(dataName, '/Normal', [64 64 3 sizePerH5] , 'Datatype', 'double');
h5write(dataName, '/Normal', normals);
% Store Reflectance
h5create(dataName, '/Reflectance', [64 64 3 sizePerH5], 'Datatype', 'double');
h5write(dataName, '/Reflectance', reflectances);
% Store Shading
h5create(dataName, '/Shading', [64 64 3 sizePerH5], 'Datatype', 'double');
h5write(dataName, '/Shading', shadings);
% Store Height
h5create(dataName, '/Height', [64 64 sizePerH5], 'Datatype', 'double');
h5write(dataName, '/Height', heights);
% Store Final Loss
h5create(dataName, '/FinalLoss', [sizePerH5], 'Datatype', 'double');
h5write(dataName, '/FinalLoss', finalLoss);
im = [];
shflatten = [];
normals = [];
reflectances = [];
heights = [];
finalLoss = [];
shadings = [];
end
end
end
%shfilename = [ [shfilename]; Files(k).name];
end
%csvwrite('RealImage_Celeb_000_SH.csv',shflatten);
%csvwrite('RealImage_Celeb_000_names.csv', shfilename);
%h5create('data.h5', '/Image', [64 64 3 num-2], 'Datatype', 'uint8');
%h5write('data.h5', '/Image', im);