-
Notifications
You must be signed in to change notification settings - Fork 93
/
sample_opt_pano_joint.m
169 lines (157 loc) · 6.43 KB
/
sample_opt_pano_joint.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
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
function [cor_ini, score_all] = sample_opt_pano(cor_id, im_w, im_h, corn, edg, edg2, options)
score_all = 0;
[wall_d, x, f] = pano_line_solver(cor_id, im_w, options); % bos-shape case
cor_id_t = cor_id;
d_m = 0;
% initialization
for j = 1:2:size(cor_id_t,1)
theta_y = pi*cor_id_t(j+1,2)/im_h-pi/2;
theta_y_ = pi/2 - pi*cor_id_t(j,2)/im_h;
d = abs(cot(theta_y));
d_m = d_m + d/wall_d((j+1)/2);
end
d_m = d_m/4;
cor_ini = [];
for j = 1:2:size(cor_id_t,1)
line_d = d_m*wall_d((j+1)/2);
line_theta_y = acot(line_d);
line_y = (line_theta_y + pi/2)*im_h/pi;
cor_ini = [cor_ini;cor_id_t(j,1) line_y];
cor_ini = [cor_ini;cor_id_t(j,1) line_y];
end
score_btn = interp2(corn,cor_ini(2:2:end,1),cor_ini(2:2:end,2));
score_btn = sum(log(score_btn));
% add floor score
cor_all = [cor_ini(2,:);cor_ini(4,:);cor_ini(4,:);cor_ini(6,:);
cor_ini(6,:);cor_ini(8,:);cor_ini(8,:);cor_ini(2,:)];
[ uv ] = coords2uv( cor_all, im_w, im_h );
[ xyz ] = uv2xyzN( uv);
[ lines ] = lineFromTwoPoint( xyz(1:2:end,:), xyz(2:2:end,:) );
im = zeros(im_h, im_w, 3);
[ panoEdgeC ] = paintParameterLine_my(lines, im_w, im_h, im);
score_fl = zeros(1,4);
score_fl(1) = max(max(edg2(:,:,3).*(panoEdgeC(:,:,1) == 1)));
score_fl(2) = max(max(edg2(:,:,3).*(panoEdgeC(:,:,1) == 2)));
score_fl(3) = max(max(edg2(:,:,3).*(panoEdgeC(:,:,1) == 3)));
score_fl(4) = max(max(edg2(:,:,3).*(panoEdgeC(:,:,1) == 4)));
score_fl = sum(log(score_fl));
score_btn = score_btn + score_fl;
% sampling
% horizontal, bottoms
d_m_max = d_m + d_m*0.1;
d_m_min = d_m - d_m*0.1;
score_best = -Inf;
for j = d_m_min:d_m*0.02:d_m_max
cor_opt = [];
for k = 1:2:size(cor_id_t,1)
line_d = j*wall_d((k+1)/2);
line_theta_y = acot(line_d);
line_y = (line_theta_y + pi/2)*im_h/pi;
cor_opt = [cor_opt;cor_id_t(k,1) line_y];
end
% compute score
score = interp2(corn,cor_opt(:,1),cor_opt(:,2));
score = sum(log(score));
cor_all = [cor_opt(1,:);cor_opt(2,:);cor_opt(2,:);cor_opt(3,:);
cor_opt(3,:);cor_opt(4,:);cor_opt(4,:);cor_opt(1,:)];
[ uv ] = coords2uv( cor_all, im_w, im_h );
[ xyz ] = uv2xyzN( uv);
[ lines ] = lineFromTwoPoint( xyz(1:2:end,:), xyz(2:2:end,:) );
[ panoEdgeC ] = paintParameterLine_my(lines, im_w, im_h, im);
score_fl = zeros(1,4);
score_fl(1) = max(max(edg2(:,:,3).*(panoEdgeC(:,:,1) == 1)));
score_fl(2) = max(max(edg2(:,:,3).*(panoEdgeC(:,:,1) == 2)));
score_fl(3) = max(max(edg2(:,:,3).*(panoEdgeC(:,:,1) == 3)));
score_fl(4) = max(max(edg2(:,:,3).*(panoEdgeC(:,:,1) == 4)));
score_fl = sum(log(score_fl));
score = score + score_fl;
if score > score_best
score_best = score;
cor_best = cor_opt;
d_m_best = j;
end
end
if score_best > score_btn
cor_ini(2:2:end,:) = cor_best;
else
score_best = score_btn;
d_m_best = d_m;
end
score_all = score_all + score_best;
% horizontal, top
h_m = 0;
for j = 1:2:size(cor_id_t,1)
theta_y_ = pi/2 - pi*cor_id_t(j,2)/im_h;
d = d_m_best*wall_d((j+1)/2);
h = d*tan(theta_y_);
h_m = h_m + h;
end
h_m = h_m/4;
for j = 1:2:size(cor_id_t,1)
line_d = d_m_best*wall_d((j+1)/2);
line_y_ = atan(h_m/line_d);
line_y_ = (pi/2-line_y_)*im_h/pi;
cor_ini(j,2) = line_y_;
end
score_tp = interp2(corn,cor_ini(1:2:end,1),cor_ini(1:2:end,2));
score_tp = sum(log(score_tp));
% add ceiling score
cor_all = [cor_ini(1,:);cor_ini(3,:);cor_ini(3,:);cor_ini(5,:);
cor_ini(5,:);cor_ini(7,:);cor_ini(7,:);cor_ini(1,:)];
[ uv ] = coords2uv( cor_all, im_w, im_h );
[ xyz ] = uv2xyzN( uv);
[ lines ] = lineFromTwoPoint( xyz(1:2:end,:), xyz(2:2:end,:) );
im = zeros(im_h, im_w, 3);
[ panoEdgeC ] = paintParameterLine_my(lines, im_w, im_h, im);
score_cl = zeros(1,4);
score_cl(1) = max(max(edg2(:,:,2).*(panoEdgeC(:,:,1) == 1)));
score_cl(2) = max(max(edg2(:,:,2).*(panoEdgeC(:,:,1) == 2)));
score_cl(3) = max(max(edg2(:,:,2).*(panoEdgeC(:,:,1) == 3)));
score_cl(4) = max(max(edg2(:,:,2).*(panoEdgeC(:,:,1) == 4)));
score_cl = sum(log(score_cl));
score_tp = score_tp + 0.5*score_cl;
h_m_max = h_m + h_m*0.1;
h_m_min = h_m - h_m*0.1;
score_best = -Inf;
for j = h_m_min:h_m*0.02:h_m_max
cor_opt = [];
for k = 1:2:size(cor_ini,1)
line_d = d_m_best*wall_d((k+1)/2);
line_y_ = atan(j/line_d);
line_y_ = (pi/2-line_y_)*im_h/pi;
cor_opt = [cor_opt;cor_ini(k,1) line_y_];
end
% compute score
score = interp2(corn,cor_opt(:,1),cor_opt(:,2));
score = sum(log(score));
if 1
% add ceiling score
cor_all = [cor_opt(1,:);cor_opt(2,:);cor_opt(2,:);cor_opt(3,:);
cor_opt(3,:);cor_opt(4,:);cor_opt(4,:);cor_opt(1,:)];
[ uv ] = coords2uv( cor_all, im_w, im_h );
[ xyz ] = uv2xyzN( uv);
[ lines ] = lineFromTwoPoint( xyz(1:2:end,:), xyz(2:2:end,:) );
im = zeros(im_h, im_w, 3);
[ panoEdgeC ] = paintParameterLine_my(lines, im_w, im_h, im);
score_cl = zeros(1,4);
score_cl(1) = max(max(edg2(:,:,2).*(panoEdgeC(:,:,1) == 1)));
score_cl(2) = max(max(edg2(:,:,2).*(panoEdgeC(:,:,1) == 2)));
score_cl(3) = max(max(edg2(:,:,2).*(panoEdgeC(:,:,1) == 3)));
score_cl(4) = max(max(edg2(:,:,2).*(panoEdgeC(:,:,1) == 4)));
score_cl = sum(log(score_cl));
score = score + 0.5*score_cl;
end
if score > score_best
score_best = score;
cor_best = cor_opt;
h_m_best = j;
end
end
if score_best > score_tp
cor_ini(1:2:end,:) = cor_best;
else
score_best = score_tp;
h_m_best = h_m;
end
score_all = score_all + score_best;
end