Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed heatmaps
  • Loading branch information
john.wohl@uconn.edu committed Apr 12, 2020
1 parent ffb4890 commit 7c96e3f
Show file tree
Hide file tree
Showing 12 changed files with 2,342 additions and 45 deletions.
Binary file modified Output/NoImage/output-young_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Output/WithImage/output-young_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,080 changes: 1,080 additions & 0 deletions Output/visualization data/young_1.jpg/pilot_01/matrix.csv

Large diffs are not rendered by default.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,080 changes: 1,080 additions & 0 deletions Output/visualization data/young_2.jpg/pilot_01/matrix.csv

Large diffs are not rendered by default.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions gaze2.m
@@ -0,0 +1,80 @@
addpath('gbvs');
addpath('eyetrackingstory_01/pilot_data/free_ebooks');
addpath('eyetrackingstory_01/stimuli/free_ebooks/young/withbackground');
addpath('eyetrackingstory_01/stimuli/free_ebooks/old/withbackground');

output_root_blank = 'Output/NoImage/';
output_root_image = 'Output/WithImage/';

% gaze dispersion

data = readtable('samplereport_pilotdata.xlsx');

image = char('');
blank_img = repmat(255, 1, 1, 1);
file = char('');
eye = char('');
output_filename = '';
matrix = zeros(1, 1);
matrices = containers.Map;
first = true;
%height(data)
for row_index = 1:500
disp(row_index);
try
row = data(row_index, :);
string_array = table2array(row(1, {'DATA_FILE', 'image', 'EYE_TRACKED'}));
[current_file, current_image, current_eye] = string_array{:};
if(~isKey(matrices, current_image))
image_object = imread(current_image);
[img_height, img_width, img_dim] = size(image_object);
blank_img = repmat(255, img_height, img_width, img_dim);
matrices(current_image) = zeros(img_height, img_width);
end

matrix = matrices(current_image);

if(strcmp(current_eye, 'Right'))
number_array = table2array(row(1, {'RIGHT_GAZE_X', 'RIGHT_GAZE_Y'}));
else
number_array = table2array(row(1, {'LEFT_GAZE_X', 'LEFT_GAZE_Y'}));
end

if(any(isnan(number_array)))
continue
end

number_array_cell = num2cell(number_array);
[x_coord, y_coord] = number_array_cell{:};
x_coord = int16(x_coord);
y_coord = int16(y_coord);
if(x_coord > 0 && x_coord <= img_width && y_coord > 0 && y_coord <= img_height)
matrix(y_coord, x_coord) = matrix(y_coord, x_coord) + 1;
matrix(5, 5) = matrix(5, 5) + 1;
matrices(current_image) = matrix;
end
catch error
disp('Error');
disp('\n');
end
end

image_keys = keys(matrices);
for key_index = 1:length(image_keys)
current_image_cell = image_keys(key_index);
current_image = current_image_cell{:};
matrix = matrices(current_image);
image_object = imread(current_image);

matrix = imgaussfilt(matrix, 2);
matrix = rescale(matrix);
hist_blank = heatmap_overlay(blank_img, matrix);
hist_image = heatmap_overlay(image_object, matrix);

output_filename = strcat('output-', current_image, '.png');
output_filename = erase(output_filename, {'.jpg', '.edf'});
output_filename_image = strcat(output_root_image, output_filename);
output_filename_blank = strcat(output_root_blank, output_filename);
imwrite(hist_image, output_filename_image);
imwrite(hist_blank, output_filename_blank);
end
147 changes: 102 additions & 45 deletions gaze_dispersion.m
Expand Up @@ -5,6 +5,7 @@ addpath('eyetrackingstory_01/stimuli/free_ebooks/old/withbackground');

output_root_blank = 'Output/NoImage/';
output_root_image = 'Output/WithImage/';
output_root_vizdata = 'Output/visualization data/';

% gaze dispersion

Expand All @@ -16,65 +17,121 @@ file = char('');
eye = char('');
output_filename = '';
matrix = zeros(1, 1);
matrices = containers.Map;
image_maps = containers.Map;
vectors = containers.Map;
first = true;
for row_index = 1:height(data)
disp(row_index);
try
row = data(row_index, :);
string_array = table2array(row(1, {'DATA_FILE', 'image', 'EYE_TRACKED'}));
[current_file, current_image, current_eye] = string_array{:};
if(~isKey(matrices, current_image))
image_object = imread(current_image);
[img_height, img_width, img_dim] = size(image_object);
blank_img = repmat(255, img_height, img_width, img_dim);
matrices(current_image) = zeros(img_height, img_width);
end
row = data(row_index, :);
string_array = table2array(row(1, {'DATA_FILE', 'image', 'EYE_TRACKED'}));
[current_file, current_image, current_eye] = string_array{:};
subject = erase(current_file, {'.edf'});
if(~isKey(image_maps, current_image))
image_object = imread(current_image);
[img_height, img_width, img_dim] = size(image_object);
blank_img = repmat(255, img_height, img_width, img_dim);
image_maps(current_image) = containers.Map;
vectors(current_image) = containers.Map;
end
image_map = image_maps(current_image);
vector_image_set = vectors(current_image);
if(~isKey(image_map, subject))
image_map(subject) = zeros(img_height, img_width);
vector_image_set(subject) = containers.Map;
vector_subject_set = vector_image_set(subject);
vector_subject_set('x') = zeros(1, img_width);
vector_subject_set('y') = zeros(1, img_height);
vector_image_set(subject) = vector_subject_set;
end

matrix = matrices(current_image);
matrix = image_map(subject);
vector_subject_set = vector_image_set(subject);
x_array = vector_subject_set('x');
y_array = vector_subject_set('y');

if(strcmp(current_eye, 'Right'))
number_array = table2array(row(1, {'RIGHT_GAZE_X', 'RIGHT_GAZE_Y'}));
else
number_array = table2array(row(1, {'LEFT_GAZE_X', 'LEFT_GAZE_Y'}));
end
if(strcmp(current_eye, 'Right'))
number_array = table2array(row(1, {'RIGHT_GAZE_X', 'RIGHT_GAZE_Y'}));
else
number_array = table2array(row(1, {'LEFT_GAZE_X', 'LEFT_GAZE_Y'}));
end

if(any(isnan(number_array)))
continue
end
if(any(isnan(number_array)))
continue
end

number_array_cell = num2cell(number_array);
[x_coord, y_coord] = number_array_cell{:};
x_coord = int16(x_coord);
y_coord = int16(y_coord);
if(x_coord > 0 && x_coord <= img_width && y_coord > 0 && y_coord <= img_height)
matrix(y_coord, x_coord) = matrix(y_coord, x_coord) + 1;
matrices(current_image) = matrix;
end
catch error
disp('Error');
disp('\n');
number_array_cell = num2cell(number_array);
[x_coord, y_coord] = number_array_cell{:};
x_coord = int16(x_coord);
y_coord = int16(y_coord);
if(x_coord > 0 && x_coord <= img_width && y_coord > 0 && y_coord <= img_height)
matrix(y_coord, x_coord) = matrix(y_coord, x_coord) + 1;
image_map(subject) = matrix;
image_maps(current_image) = image_map;

x_array(x_coord) = 1;
y_array(y_coord) = 1;
vector_subject_set('x') = x_array;
vector_subject_set('y') = y_array;
vector_image_set(subject) = vector_subject_set;
vectors(current_image) = vector_image_set;
end
end

disp('Creating heatmap images...');

image_keys = keys(matrices);
image_keys = keys(image_maps);
for key_index = 1:length(image_keys)
current_image_cell = image_keys(key_index);
current_image = current_image_cell{:};
matrix = matrices(current_image);
image_object = imread(current_image);

matrix = imgaussfilt(matrix, 2);
matrix = rescale(matrix);
hist_blank = heatmap_overlay(blank_img, matrix);
hist_image = heatmap_overlay(image_object, matrix);

output_filename = strcat('output-', current_image, '.png');
output_filename = erase(output_filename, {'.jpg', '.edf'});
output_filename_image = strcat(output_root_image, output_filename);
output_filename_blank = strcat(output_root_blank, output_filename);
imwrite(hist_image, output_filename_image);
imwrite(hist_blank, output_filename_blank);
mkdir(strcat(output_root_vizdata, current_image));
image_map = image_maps(current_image);
subject_keys = keys(image_map);
for subject_index = 1:length(subject_keys)
image_data = im2double(imread(current_image));
image_data = flip(image_data, 1);
subject_cell = subject_keys(subject_index);
subject = subject_cell{:};
mkdir(strcat(output_root_vizdata, current_image, '/', subject));
matrix = image_map(subject);
% flip over x-axis because eye-link (0,0) is at top left
matrix = flip(matrix, 1);
csv_filename = strcat(output_root_vizdata, current_image, '/', subject, '/matrix.csv');
csvwrite(csv_filename, matrix);

[row, col] = find(matrix);
plot(col, row, 'r.');
xlim([0 img_width]);
ylim([0 img_height]);
set(gcf, 'position', [0, 0, img_width, img_height]);
saveas(gcf, strcat(output_root_vizdata, current_image, '/', subject, '/scatter.png'));
clearvars gcf gca;

pts_x = linspace(0, img_width, img_width/10);
pts_y = linspace(0, img_height, img_height/10);
N = histcounts2(row(:), col(:), pts_y, pts_x);

[xG, yG] = meshgrid(-5:5);
sigma = 2.5;
g = exp(-xG.^2./(2.*sigma.^2)-yG.^2./(2.*sigma.^2));
g = g./sum(g(:));

figure, imshow(image_data), hold on;
hImg = imagesc(pts_x, pts_y, conv2(N, g, 'same'));
set(hImg, 'AlphaData', 0.6);
%imagesc(pts_x, pts_y, conv2(N, g, 'same'));
%imagesc(conv2(N, g, 'same'));
axis equal;
set(gca, 'XLim', pts_x([1 end]), 'YLim', pts_y([1 end]), 'YDir', 'normal');
saveas(gcf, strcat(output_root_vizdata, current_image, '/', subject, '/heatmap_image.png'));

clearvars gcf gca;
imagesc(pts_x, pts_y, conv2(N, g, 'same'));
axis equal;
set(gca, 'XLim', pts_x([1 end]), 'YLim', pts_y([1 end]), 'YDir', 'normal');
saveas(gcf, strcat(output_root_vizdata, current_image, '/', subject, '/heatmap.png'));

clearvars gcf gca image_data;
close all;
end
end

0 comments on commit 7c96e3f

Please sign in to comment.