-
Notifications
You must be signed in to change notification settings - Fork 9
/
Demo_evaluation.m
104 lines (85 loc) · 3.7 KB
/
Demo_evaluation.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
clear; close all
dir_db = './DB/YorkUrbanDB';
addpath(genpath('./toolbox/'));
addpath('./funcs/')
load([dir_db '/our_annotation/Image_ID_List.mat']); % We get Image_ID_List
num_im = size(Image_ID_List, 1);
name_method = {'\fontname{times}Linelet'};
method2test = {'linelet'};
num_method = length(method2test);
dir_method = {'proposed'};
var_method = {'line_own'};
stats(num_method,1) = struct('prec', [], 'rec', [], 'iou', []);
bSaveResult = false;
% True positive conditions
eval_param.thres_dist = 1;
eval_param.thres_ang = pi*5/180;
eval_param.thres_length_ratio = .75; % .75 (Con1) or .5 (Con2)
for i_im = 1 : num_im
try
str_im = sprintf('%s/%s/%s.jpg', dir_db, Image_ID_List(i_im).name, Image_ID_List(i_im).name);
im = imread(str_im);
imw = im; imw(:) = 255;
im_gray = rgb2gray(im);
size_im = size(im_gray);
% load line gnd
str_gnd = sprintf('%s/our_annotation/%s_GND.mat', dir_db, Image_ID_List(i_im).name);
if ~exist(str_gnd, 'file'), continue; end
load(str_gnd); % we get line_gnd
line_gnd = unique(line_gnd, 'rows');
% Remove invalid ground truth
idx_invalid = find( line_gnd(:,1) == 0 & line_gnd(:,2) == 0 & line_gnd(:,3) == 0 & line_gnd(:,4) == 0 );
line_gnd(idx_invalid,:) = [];
% Rearrange line segment so that elements become (x1, y1, x2, y2, center_x, center_y, length, angle)
cp = [line_gnd(:,1) + line_gnd(:,3) line_gnd(:,2) + line_gnd(:,4)]/2;
dx = line_gnd(:,3) - line_gnd(:,1); dy = line_gnd(:,4) - line_gnd(:,2);
line_gnd = [line_gnd, cp, sqrt(dx.^2 + dy.^2), atan2(dy, dx)];
for k = 1:num_method
% Load estimation results
str_est = sprintf('result/proposed/%s.mat', Image_ID_List(i_im).name);
if ~exist(str_est, 'file'), continue; end
load(str_est);
idxH = ll_Valid_Hor1(:,1) >= ll_Valid_Hor1(:,2);
idxV = ll_Valid_Ver1(:,1) >= ll_Valid_Ver1(:,2);
line_own = [ls_est_Hor1(idxH,:); ls_est_Ver1(idxV,:)];
eval( sprintf('line_est = %s;', var_method{k}) );
dir_vec = repmat(line_est(:,4), 1, 2)/2.*[cos(line_est(:,3)) sin(line_est(:,3))];
x1 = line_est(:,1:2) + dir_vec;
x2 = line_est(:,1:2) - dir_vec;
line_est = [x1 x2 line_est(:,1:2) line_est(:,4) line_est(:,3)];
% Evaluate
if size(line_est,1) > 0
[pr, re, iou] = evaluate_line_segment(line_est, line_gnd, eval_param);
stats(k).prec(i_im,:) = pr;
stats(k).rec(i_im,:) = re;
stats(k).iou(i_im,:) = iou;
else
stats(k).prec(i_im,:) = 0;
stats(k).rec(i_im,:) = 0;
stats(k).iou(i_im,:) = 0;
end
end
catch err
fprintf('error at i_im: %d.\n', i_im);
rethrow(err);
end
end
%% Display scores
AP = zeros(num_method, 1);
AR = zeros(num_method, 1);
IOU = zeros(num_method, 1);
for k = 1:num_method
AP(k) = mean(stats(k).prec,1);
AR(k) = mean(stats(k).rec,1);
IOU(k) = mean(stats(k).iou,1);
end
F_sc = 2 * (AP .* AR) ./ (AP + AR);
fig = figure(1); clf;
axes1 = axes('Parent',fig,'Layer','top','FontWeight','bold','FontSize',12,...
'FontName','Times New Roman', 'XTick', 1:num_method, 'XTickLabel',name_method);
box(axes1,'on'); hold(axes1,'on');
title('Average precision and recall')
bar([AP, AR, IOU, F_sc])
hleg = legend('AP', 'AR', 'IOU', 'F-score', 'Location', 'nw');
fprintf('Final scores...\n');
[AP, AR, IOU, F_sc]