-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate_fixMaps.m
182 lines (131 loc) · 5 KB
/
generate_fixMaps.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
% Zoya Bylinskii (January 2016)
% figrim.mit.edu/index_eyetracking.html
%addpath('../utils/');
%load('allImages_release.mat');
load('allImages_fillers.mat');
fixmapdir = 'FIXATIONMAPS_fillers';
fixlocdir = 'FIXATIONLOCS_fillers';
todisplay = 0; % whether or not to display the visualizations created
tosave = 1; % whether or not to save the visualizations created
%% recreate the FIXATIONMAPS and FIXATIONLOCS directories
if tosave
mkdir(fixmapdir);
mkdir(fixlocdir);
end
for j = 1:length(allImages)
fprintf('On image %d of %d\n',j,length(allImages));
whichusers = 1:length(allImages(j).userdata);
im = imread(allImages(j).impath);
[m,n,~] = size(im);
[averageSaliencyMap,fixLocs] = compMapsLocsForImage(allImages,j,whichusers,m,n);
curdir = fullfile(fixmapdir,allImages(j).category);
curdir2 = fullfile(fixlocdir,allImages(j).category);
if ~exist(curdir,'dir')
mkdir(curdir);
mkdir(curdir2);
end
if tosave
imwrite(averageSaliencyMap,fullfile(curdir,allImages(j).filename));
save(fullfile(curdir2,allImages(j).filename(1:end-4)),'fixLocs');
end
if todisplay
omap = heatmap_overlay(im,averageSaliencyMap);
figure; imshow(omap); pause
close all;
end
end
%% plot the fixation maps and locs generated
if todisplay
figure;
for i = 1:length(allImages)
subplot(1,3,1); imshow(allImages(i).impath);
subplot(1,3,2); imshow(fullfile(fixmapdir,allImages(i).category,allImages(i).filename));
load(fullfile(fixlocdir,allImages(i).category,[allImages(i).filename(1:end-4),'.mat']));
subplot(1,3,3); imshow(fixLocs); pause;
end
end
%% plot the fixation maps on top of image
if todisplay
figure;
for i =50:length(allImages)
i
im = imread(allImages(i).impath);
averageSaliencyMap = im2double(imread(fullfile(fixmapdir,allImages(i).category,allImages(i).filename)));
omap = heatmap_overlay(im,averageSaliencyMap);
imshow(omap); pause
end
end
%% generate the spotlight fixation maps
if tosave, mkdir('SpotlightIms'); end
for j = 1:length(allImages)
j
whichusers = 1:length(allImages(j).userdata);
im = imread(allImages(j).impath);
[m,n,~] = size(im);
[averageSaliencyMap,fixLocs] = compMapsLocsForImage(allImages,j,whichusers,m,n);
spot = plotSpotlight(im,averageSaliencyMap,5);
if tosave, imwrite(spot,fullfile('SpotlightIms',allImages(j).filename)); end
if todisplay
omap = heatmap_overlay(im,averageSaliencyMap);
subplot(1,2,1); imshow(omap);
subplot(1,2,2); imshow(spot);
pause
end
end
%% plot fixation maps per observer per image
if todisplay
perm = randperm(length(allImages));
for jj = 1:length(allImages)
%%
j = perm(jj);
im = imread(allImages(j).impath);
[m,n,~] = size(im);
whichusers = [];
for ii = 1:length(allImages(j).userdata)
if ~isempty(allImages(j).userdata(ii).fixations) && ...
isfield(allImages(j).userdata(ii).fixations,'enc') && ...
~isempty(allImages(j).userdata(ii).fixations.enc)
whichusers = [whichusers,ii];
end
end
figure;
d1 = floor(sqrt(length(whichusers))); d2 = ceil(length(whichusers)/d1);
for ii = 1:length(whichusers)
[averageSaliencyMap,fixLocs] = compMapsLocsForImage(allImages,j,whichusers(ii),m,n,'enc');
omap = heatmap_overlay(im,averageSaliencyMap);
subplot(d1,d2,ii); imshow(omap);
end
pause; close all;
end
end
%% plot fixation maps per observer for all 3 image repetitions (enc,rec,rec2)
if todisplay
perm = randperm(length(allImages));
for jj = 1:length(allImages)
%%
j = perm(jj);
im = imread(allImages(j).impath);
[m,n,~] = size(im);
whichusers = [];
for ii = 1:length(allImages(j).userdata)
if ~isempty(allImages(j).userdata(ii).fixations) && ...
isfield(allImages(j).userdata(ii).fixations,'enc') && ...
~isempty(allImages(j).userdata(ii).fixations.enc)
whichusers = [whichusers,ii];
end
end
for ii = 1:length(whichusers)
figure;
[averageSaliencyMap,fixLocs] = compMapsLocsForImage(allImages,j,whichusers(ii),m,n,'enc');
omap = heatmap_overlay(im,averageSaliencyMap);
subplot(1,3,1); imshow(omap);
[averageSaliencyMap,fixLocs] = compMapsLocsForImage(allImages,j,whichusers(ii),m,n,'rec');
omap = heatmap_overlay(im,averageSaliencyMap);
subplot(1,3,2); imshow(omap);
[averageSaliencyMap,fixLocs] = compMapsLocsForImage(allImages,j,whichusers(ii),m,n,'rec2');
omap = heatmap_overlay(im,averageSaliencyMap);
subplot(1,3,3); imshow(omap);
pause; close all;
end
end
end