-
Notifications
You must be signed in to change notification settings - Fork 6
/
prCount.m
60 lines (47 loc) · 1.43 KB
/
prCount.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
function [precision, recall] = prCount(GroundTruth, SaliencyMap)
% for the ground truth of dataset ASD: convert rgb to gray
GroundTruth = double(GroundTruth); %%double for rgb2gray
gtsize=size(GroundTruth);
if numel(gtsize)>2
GroundTruth = rgb2gray(GroundTruth);
end
smsize=size(SaliencyMap);
if numel(smsize)>2
SaliencyMap = rgb2gray(SaliencyMap);
end
% make the size of GroungTruth and SaliencyMap the same
[gtH, gtW] = size(GroundTruth);
[algH, algW] = size(SaliencyMap);
if gtH~=algH || gtW~=algW
SaliencyMap = imresize(SaliencyMap, [gtH, gtW]);
end
GroundTruth=logical(GroundTruth); %%binarization
SaliencyMap = SaliencyMap(:);
GroundTruth = GroundTruth(:);
[nx,ny]=size(SaliencyMap);
if (nx~=1 && ny~=1)
error('first argument must be a vector');
end
[mx,my]=size(GroundTruth);
if (mx~=1 && my~=1)
error('second argument must be a vector');
end
if (length(GroundTruth) ~= length(SaliencyMap))
error('score and target must have same length');
end
instance_count = ones(length(SaliencyMap),1);
thresh=0:255;
total_positive = sum(GroundTruth);
%total_negative = sum(instance_count - GroundTruth);
if total_positive==0
precision = [];
recall = [];
return;
end
precision = zeros(length(thresh),1);
recall = zeros(length(thresh),1);
for i = 1:256
idx = (SaliencyMap >= (i-1));
precision(i) = sum(GroundTruth(idx)) / (sum(instance_count(idx))+eps);
recall(i) = sum(GroundTruth(idx)) / total_positive;
end