-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAUC_Borji.m
executable file
·85 lines (69 loc) · 2.76 KB
/
AUC_Borji.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
% created: Zoya Bylinskii, Aug 2014
% Based on code by Ali Borji
% This measures how well the saliencyMap of an image predicts the ground
% truth human fixations on the image.
% ROC curve created by sweeping through threshold values at fixed step size
% until the maximum saliency map value;
% true positive (tp) rate correspond to the ratio of saliency map values above
% threshold at fixation locations to the total number of fixation locations
% false positive (fp) rate correspond to the ratio of saliency map values above
% threshold at random locations to the total number of random locations
% (as many random locations as fixations, sampled uniformly from
% ALL IMAGE PIXELS), averaging over Nsplits number of selections of
% random locations.
function [score,res] = AUC_Borji(saliencyMap, fixationMap, Nsplits, stepSize, toPlot)
% saliencyMap is the saliency map
% fixationMap is the human fixation map (binary matrix)
% Nsplits is number of random splits
% stepSize is for sweeping through saliency map
% if toPlot=1, displays ROC curve
if nargin < 5, toPlot = 0; end
if nargin < 4, stepSize = .1; end
if nargin < 3, Nsplits = 100; end
% If there are no fixations to predict, return NaN
if ~any(fixationMap)
score=NaN;
disp('no fixationMap');
return
end
% make the saliencyMap the size of the image of fixationMap
if size(saliencyMap, 1)~=size(fixationMap, 1) || size(saliencyMap, 2)~=size(fixationMap, 2)
saliencyMap = imresize(saliencyMap, size(fixationMap));
end
% normalize saliency map
saliencyMap = (saliencyMap-min(saliencyMap(:)))/(max(saliencyMap(:))-min(saliencyMap(:)));
S = saliencyMap(:);
F = fixationMap(:);
Sth = S(F>0); % sal map values at fixation locations
Nfixations = length(Sth);
Npixels = length(S);
% for each fixation, sample Nsplits values from anywhere on the sal map
r = randi([1 Npixels],[Nfixations,Nsplits]);
randfix = S(r); % sal map values at random locations
% calculate AUC per random split (set of random locations)
auc = nan(1,Nsplits);
for s = 1:Nsplits
curfix = randfix(:,s);
allthreshes = fliplr([0:stepSize:max([Sth;curfix])]);
tp = zeros(length(allthreshes)+2,1);
fp = zeros(length(allthreshes)+2,1);
tp(1)=0; tp(end) = 1;
fp(1)=0; fp(end) = 1;
for i = 1:length(allthreshes)
thresh = allthreshes(i);
tp(i+1) = sum((Sth >= thresh))/Nfixations;
fp(i+1) = sum((curfix >= thresh))/Nfixations;
end
auc(s) = trapz(fp,tp);
end
score = mean(auc); % mean across random splits
res{1} = tp;
res{2} = fp;
if toPlot
subplot(121); imshow(saliencyMap, []); title('SaliencyMap with fixations to be predicted');
hold on;
[y, x] = find(fixationMap);
plot(x, y, '.r');
subplot(122); plot(fp, tp, '.b-'); title(['Area under ROC curve: ', num2str(score)])
end
end