-
Notifications
You must be signed in to change notification settings - Fork 0
/
esSampleProtoMap.m
107 lines (95 loc) · 3.42 KB
/
esSampleProtoMap.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
105
106
107
function [M_tMap, protoMap protoMap_raw normSal] = esSampleProtoMap(sMap,...
currFrame,...
nBestProto)
%esSampleProtoMap - Generates the patch map M(t)
%
% Synopsis
% [protoMap protoMap_raw normSal] = esSampleProtoMap(sMap,currFrame, nBestProto)
%
% Description
% In a first step generates the raw patch map by thresholding the normalized salience map
% so as to achieve 95% significance level for deciding whether the given saliency values are
% in the extreme tails
% In a second step get the N_V best patches ranked through their size and returns the actual
% M(t) map
%
%
% Inputs ([]s are optional)
% (matrix) sMap the salience map, 0/1 overlay representation
% (matrix) currFrame the current frame
% (integer) nBestProto the N_V most valuable patches
%
%
% Outputs ([]s are optional)
% (matrix) M_tMap the patch map M(t)
% (matrix) protoMap the object layer representation of patch map M(t)
% (matrix) protoMap_raw the raw patch map
% (matrix) normSal the normalized salience map
%
%
%
% Requirements
% Image Processing toolbox
%
% References
% [1] G. Boccignone and M. Ferraro, Ecological Sampling of Gaze Shifts
% IEEE Trans. Systems Man Cybernetics - Part B (to appear)
%
%
% Author
% Giuseppe Boccignone <Giuseppe.Boccignone(at)unimi.it>
%
%
% Changes
% 12/12/2012 First Edition
%
protoMap_raw= false(size(sMap)); % allocating space for the raw map
% Normalizing salience
normSal=sMap;
maxsal=max(max(normSal));
minsal=min(min(normSal));
normSal= (normSal-minsal)./(maxsal-minsal);
normSal=normSal*100;
% Salience thresholding
% Method 1: adaptive on mu
%mu=mean2(sal);
%stdv=std2(sal);
%ind=find(sal>=4*mu); %standard measure 3*mu
% Method 2: percentile based
ind=find(normSal >= prctile(normSal(:),90));
protoMap_raw(ind)=1;
protoMap_raw(ind)= currFrame(ind);
% Samples the N_V best patches
openingwindow=7;
M_tMap = esSampleNbestProto(protoMap_raw,nBestProto,openingwindow);
protoMap= M_tMap;
fbw = M_tMap==0;
protoMap(fbw) = 1;
fbw = M_tMap==1;
protoMap(fbw) = 0;
end
% -------------------------------------------------
function M_tMap = esSampleNbestProto(protoMap_raw, nBest, win)
%esSampleNbestProto - Samples the N_V best patches ranked through their size and returns the actual
% M(t) map
% Use morphological operations
se = strel('disk',win);
protoMap_raw = imopen(protoMap_raw,se);
% Calculating 8 connected components via Rosenfeld and Pfaltz
[L,obj] = bwlabel(protoMap_raw,8);
% Returns the foreground connected component in the binary image
% supplied that have the specified ranked size(s).
maxL = max(L(:)); % max number of connected components
h = hist(L(find(protoMap_raw)),[1:maxL]); % find indexes of labeled elements, by column scanning,
% and compute occurence of labels from 1 to maxL
[sh,sr] = sort(-h); % sorting with respect to the number of occurrence
% sh is the num occurrences (negative: -8 -6 -4 -2),
% sr = corresponding labels
M_tMap = protoMap_raw & 0;
if nBest > maxL
nBest = maxL;
end
for i=1:nBest
M_tMap = M_tMap | (L==sr(i)) ; % returns the nBest by dimension
end
end