-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluation_bdry_image_sintel.m
86 lines (78 loc) · 2.72 KB
/
evaluation_bdry_image_sintel.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
function [thresh,cntR,sumR,cntP,sumP] = evaluation_bdry_image_sintel(inFile,gtFile, prFile, nthresh, maxDist, thinpb)
% [thresh,cntR,sumR,cntP,sumP] = boundaryPR_image(inFile,gtFile, prFile, nthresh, maxDist, thinpb)
%
% Calculate precision/recall curve.
%
% INPUT
% inFile : Can be one of the following:
% - a soft or hard boundary map in image format.
% - a collection of segmentations in a cell 'segs' stored in a mat file
% - an ultrametric contour map in 'doubleSize' format, 'ucm2'
% stored in a mat file with values in [0 1].
%
% gtFile : File containing a cell of ground truth boundaries
% prFile : Temporary output for this image.
% nthresh : Number of points in PR curve.
% MaxDist : For computing Precision / Recall.
% thinpb : option to apply morphological thinning on segmentation
% boundaries.
%
% OUTPUT
% thresh Vector of threshold values.
% cntR,sumR Ratio gives recall.
% cntP,sumP Ratio gives precision.
%
if nargin<6, thinpb = 1; end
if nargin<5, maxDist = 0.0075; end
if nargin<4, nthresh = 99; end
pb=inFile;
groundTruth=gtFile;
if ~exist('segs', 'var')
thresh = linspace(1/(nthresh+1),1-1/(nthresh+1),nthresh)';
else
if nthresh ~= numel(segs)
warning('Setting nthresh to number of segmentations');
nthresh = numel(segs);
end
thresh = 1:nthresh; thresh=thresh';
end
% zero all counts
cntR = zeros(size(thresh));
sumR = zeros(size(thresh));
cntP = zeros(size(thresh));
sumP = zeros(size(thresh));
for t = 1:nthresh,
if ~exist('segs', 'var')
bmap = (pb>=thresh(t));
else
bmap = logical(seg2bdry(segs{t},'imageSize'));
end
% thin the thresholded pb to make sure boundaries are standard thickness
if thinpb,
bmap = double(bwmorph(bmap, 'thin', inf)); % OJO
end
% accumulate machine matches, since the machine pixels are
% allowed to match with any segmentation
accP = zeros(size(bmap(:,1:1024)));
% compare to each seg in turn
for i = 1:numel(groundTruth),
% compute the correspondence
[match1,match2] = correspondPixels(bmap(:,1:1024), double(groundTruth{i}), maxDist);
% accumulate machine matches
accP = accP | match1;
% compute recall
sumR(t) = sumR(t) + sum(groundTruth{i}(:));
cntR(t) = cntR(t) + sum(match2(:)>0);
end
%'evaluationg'
% compute precision
sumP(t) = sumP(t) + sum(bmap(:));
cntP(t) = cntP(t) + sum(accP(:));
end
% output
fid = fopen(prFile,'w');
if fid==-1,
error('Could not open file %s for writing.', prFile);
end
fprintf(fid,'%10g %10g %10g %10g %10g\n',[thresh cntR sumR cntP sumP]');
fclose(fid);