-
Notifications
You must be signed in to change notification settings - Fork 93
/
panoOptimization.m
93 lines (76 loc) · 2.48 KB
/
panoOptimization.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
% path
addpath(genpath('./panoContext_code/'));
addpath(genpath('./minFunc_2012/'));
% LBFGS options
options = [];
options.display = 'none';
options.MaxIter = 100;
options.Method = 'lbfgs';
options.LS_init = 2;
% test image name
fid = fopen('../gt/panoContext_test.txt');
tline = fgetl(fid);
visual = 1;
% visualization
if visual
figure(1);
ha = tight_subplot(2,2);
end
for i = 1:53
disp(tline);
% read LaoutNet results
im = imread(['../result/res_panofull_ts_box_joint/img/' num2str(i) '.png']);
edg = imread(['../result/res_panofull_ts_box_joint/edg/' num2str(i) '.png']);
corn = imread(['../result/res_panofull_ts_box_joint/cor/' num2str(i) '.png']);
edg2 = edg;
edg = edg(:,:,1);
% max
edg_m = max(edg); edg_m = double(edg_m);
cor_m = max(corn); cor_m = double(cor_m);
[im_h, im_w, ~] = size(im);
% find peak response
[cor_id, pks, pk_loc] = getIniCor(cor_m, corn, edg_m, im_h);
% sampling
disp('sampling ...')
tic
cor_fn = samplingPanoBox(cor_id, corn, edg, edg2, im_h, im_w, options);
toc
cor_id = cor_fn;
tline = fgetl(fid);
if visual
% visual
axes(ha(1));cla;
imagesc(im); axis image; hold on;
% rescale
edg_m = (edg_m - min(edg_m))/(max(edg_m) - min(edg_m)) * 100;
edg_m = edg_m + 256-100;
plot(1:im_w, edg_m, 'r', 'LineWidth',2);
for j = 1:min(4, numel(pks))
plot([pk_loc(j) pk_loc(j)], [0, im_h], '--b', 'LineWidth',1);
end
title('Wall-wall Boundaries');
hold off;
cor_all = [cor_id;
cor_id(1,:);cor_id(3,:);cor_id(3,:);cor_id(5,:);
cor_id(5,:);cor_id(7,:);cor_id(7,:);cor_id(1,:);
cor_id(2,:);cor_id(4,:);cor_id(4,:);cor_id(6,:);
cor_id(6,:);cor_id(8,:);cor_id(8,:);cor_id(2,:)];
[ uv ] = coords2uv( cor_all, im_w, im_h );
[ xyz ] = uv2xyzN( uv);
[ lines ] = lineFromTwoPoint( xyz(1:2:end,:), xyz(2:2:end,:) );
[ panoEdgeC ] = paintParameterLine2(lines, im_w, im_h, im, 1 );
axes(ha(2));
imagesc(panoEdgeC); title('Optimized Layout'); axis image; hold on;
% corners
for j = 1:size(cor_id,1)
plot(cor_id(j,1),cor_id(j,2), '+b');
end
hold off;
axes(ha(3));
imagesc(edg); title('Edge Map'); axis image;
hold off;
axes(ha(4));
imagesc(corn); title('Corner Map'); axis image;
keyboard
end
end