-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.m
106 lines (75 loc) · 3.56 KB
/
demo.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
%% Load Data
data_shapes = {'armadillo', 'bunny', 'cube', 'dragon', 'pyramid', 'sphere'};
param_variants = {'_orth_pplastic_diffuse_0_deg_fov.mat', ...
'_persp_pplastic_diffuse_10_deg_fov.mat', ...
'_persp_pplastic_diffuse_20_deg_fov.mat', ...
'_persp_pplastic_diffuse_30_deg_fov.mat', ...
'_persp_pplastic_diffuse_40_deg_fov.mat', ...
'_persp_pplastic_diffuse_50_deg_fov.mat', ...
'_persp_pplastic_diffuse_60_deg_fov.mat', ...
'_persp_pplastic_diffuse_70_deg_fov.mat', ...
'_persp_pplastic_diffuse_80_deg_fov.mat', ...
'_persp_pplastic_diffuse_90_deg_fov.mat'};
poolObj = gcp('nocreate');
if isempty(poolObj)
% parpool('local', 8);
parpool('Processes', 8);
end
parfor i = 1:length(data_shapes)
current_shape = data_shapes{i};
for j = 1:length(param_variants)
current_param = param_variants{j};
data_path = strcat('./data/', current_shape, current_param);
% disp(class(data_path));
% disp(strcat('Start processing: ', data_path));
[py_normals_hfpol, py_normals_propagation, py_normals_lambertian] = compute_normals(data_path);
parsave(strcat('./outputs/', current_shape, current_param), py_normals_hfpol, py_normals_propagation, py_normals_lambertian);
end
end
delete(poolObj);
function parsave(fname, py_normals_hfpol, py_normals_propagation, py_normals_lambertian)
save(fname, 'py_normals_hfpol', 'py_normals_propagation', 'py_normals_lambertian');
end
function [py_normals_hfpol, py_normals_propagation, py_normals_lambertian] = compute_normals(path_to_data)
% load sampleData.mat
% load ('./data/pyramid_persp_pplastic_diffuse_40_deg_fov.mat');
load(path_to_data, "dolp", "aolp", "unpol", "spec", "mask");
rho_est = transpose(dolp);
phi_est = transpose(aolp);
Iun_est = transpose(unpol);
% clear images aolp dolp unpol;
spec = transpose(spec);
mask = transpose(mask);
% Assume refractive index = 1.5 | 1.3 for Aluminium.
n = 1.5;
s = [0 0 10]';
% % ? theta_est replaced with rho_est
[s, ~, ~] = findLight(rho_est, phi_est, Iun_est, mask & ~spec, 3, s);
% Compute angles, taking into account different model for specular pixels
rho_est_combined = rho_diffuse(rho_est, n);
rho_est_combined(spec) = rho_spec(rho_est(spec), n);
phi_est_combined = phi_est;
phi_est_combined(spec) = mod(phi_est(spec) + pi / 2, pi);
%% LambertianSfP
[~, lamb_height] = LambertianSFP(rho_est, phi_est, mask, n, ...
s + [0.0001; 0; 0], ones(size(Iun_est)), Iun_est);
[hx, hy, hz] = surfnorm(lamb_height);
py_normals_lambertian = cat(3, hx, hy, hz);
%% HfPol:
% Compute boundary prior azimuth angles and weight
[azi, Bdist] = boundaryPrior(mask);
hfpol_height = HfPol(rho_est_combined, min(1, Iun_est), phi_est_combined, s, ...
mask, false, spec, azi, Bdist);
clear Iun_est phi_est_combined rho_est_combined s spec azi Bdist;
[hx, hy, hz] = surfnorm(hfpol_height);
py_normals_hfpol = cat(3, hx, hy, hz);
%% Propagation:
[~, propagation_height] = Propagation(rho_est, phi_est, mask, n);
[hx, hy, hz] = surfnorm(propagation_height);
py_normals_propagation = cat(3, hx, hy, hz);
end
% function [] = plot_height_data(height_data)
% figure;
% surf(height_data, 'EdgeColor', 'none', 'FaceColor', [0 0 1], 'FaceLighting', ...
% 'gouraud', 'AmbientStrength', 0, 'DiffuseStrength', 1); axis equal; light
% end