-
Notifications
You must be signed in to change notification settings - Fork 18
/
eval_edge.m
44 lines (38 loc) · 1.65 KB
/
eval_edge.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
% Command to run.
% (echo "data_dir = '../output/epoch-x-test'"; cat eval_edge.m)|matlab -nodisplay -nodesktop -nosplash
data_dir = '/path/to/your/predicts'
% Data directory data_dir should be defined outside.
fprintf('Data dir: %s\n', data_dir);
addpath(genpath('./hed/eval/edges'));
addpath(genpath('./hed/eval/toolbox.badacost.public'));
% Section 1: NMS process (formerly nms_process.m from HED repo).
disp('NMS process...')
mat_dir = fullfile(data_dir, 'mat');
nms_dir = fullfile(data_dir, 'nms');
mkdir(nms_dir)
files = dir(mat_dir);
files = files(3:end,:); % It means all files except ./.. are considered.
mat_names = cell(1,size(files, 1));
nms_names = cell(1,size(files, 1));
for i = 1:size(files, 1),
mat_names{i} = files(i).name;
nms_names{i} = [files(i).name(1:end-4), '.png']; % Output PNG files.
end
for i = 1:size(mat_names,2),
matObj = matfile(fullfile(mat_dir, mat_names{i})); % Read MAT files.
varlist = who(matObj);
x = matObj.(char(varlist));
E=convTri(single(x),1);
[Ox,Oy]=gradient2(convTri(E,4));
[Oxx,~]=gradient2(Ox); [Oxy,Oyy]=gradient2(Oy);
O=mod(atan(Oyy.*sign(-Oxy)./(Oxx+1e-5)),pi);
E=edgesNmsMex(E,O,1,5,1.01,4);
imwrite(uint8(E*255),fullfile(nms_dir, nms_names{i}))
end
% Section 2: Evaluate the edges (formerly EvalEdge.m from HED repo).
disp('Evaluate the edges...');
gtDir = '/path/to/BSDS500/data/groundTruth/test';
resDir = fullfile(data_dir, 'nms');
[ODS,~,~,~,OIS,~,~,AP,R50] = edgesEvalDir('resDir',resDir,'gtDir',gtDir, 'thin', 1, 'pDistr',{{'type','parfor'}},'maxDist',0.0075);
fprintf('final results:\n ODS %f \nOIS %f \nAP %f \nR50 %f\n', ODS, OIS, AP, R50)
% figure; edgesEvalPlot(resDir,'HED');