Home > demos > demo_visualize_eye_gaze_heatmap.m

demo_visualize_eye_gaze_heatmap

PURPOSE ^

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 clear all;
0002 
0003 exp_id = 32;
0004 % save_path = ['M:\experiment_' int2str(exp_id) '\gaze_heatmap_by_subject'];
0005 save_path = '.';
0006 img_w = 720;
0007 img_h = 480;
0008 agent = 'parent';
0009 % agent = 'child';
0010 var_name = ['cont2_eye_xy_' agent];
0011 graph_format = 'png';
0012 
0013 %%
0014 sub_list = list_subjects(exp_id);
0015 
0016 if ~exist('save_path', 'dir')
0017     mkdir(save_path);
0018 end
0019 
0020 drawing_method = 1;
0021 
0022 for sidx = 1:length(sub_list)
0023 %     sidx = 1;
0024     sub_id = sub_list(sidx);
0025     
0026     if ~has_variable(sub_id, var_name)
0027         fprintf('\n%s does not exist for sub %d\n', var_name, sub_id);
0028         continue
0029     end
0030     
0031     eye_data = get_variable(sub_id, var_name);
0032     
0033     h = figure;
0034     set(h, 'Position', [100 50 1200 900]);
0035     data_size = size(eye_data(:, 2));
0036     x_data = eye_data(:, 2);
0037     y_data = eye_data(:, 3);
0038     
0039     x_percentage = sum(~isnan(x_data))/length(x_data);
0040     y_percentage = sum(~isnan(y_data))/length(y_data);
0041     
0042     if x_percentage == y_percentage
0043         gaze_quality = y_percentage;
0044     else
0045         gaze_quality = min(x_percentage, y_percentage);
0046     end
0047     
0048     if drawing_method == 1                
0049         x_range = [min(x_data) max(x_data)];
0050         y_range = [min(y_data) max(y_data)];
0051         
0052         x_plot = [x_range(1) x_range(1) x_range(2) x_range(2)];
0053         y_plot = [y_range(1) y_range(2) y_range(2) y_range(1)];
0054         
0055         hold on;
0056         fill(x_plot, y_plot, 'k');        
0057         plot(x_data, y_data, 'y.', 'MarkerSize', 1)
0058         hold off;
0059         
0060 %         xlim(x_range);
0061 %         ylim(y_range);
0062         xlim([0 img_w]);
0063         ylim([0 img_h]);
0064     elseif drawing_method == 2 && false % this method not in use
0065         plot_matrix = zeros(img_h, img_w);
0066         for edidx = 1: size(x_data)
0067             index_column = floor(x_data(edidx))+1;
0068             index_row = 480-floor(y_data(edidx));
0069             
0070             if index_row < 1
0071                 index_row = 1;
0072             end
0073             
0074             if index_column > 720
0075                 index_column = 720;
0076             end
0077             
0078             if ~isnan(index_column) && ~isnan(index_row)
0079                 plot_matrix(index_row, index_column) = ...
0080                     plot_matrix(index_row, index_column) + 1;
0081             end
0082         end
0083         
0084         imagesc(plot_matrix, [0 10])
0085         colormap(jet)
0086         
0087     elseif drawing_method == 3 && false % this method not in use
0088         for edidx = 1: size(x_data)
0089             draw_rect(x_data(edidx), y_data(edidx));
0090         end
0091     %     hold on;
0092     %
0093     %     for eidx = 1:size(eye_data, 1)
0094     %         this_eye_xy = eye_data(eidx, 2:3);
0095     %         plot(this_eye_xy(1), this_eye_xy(2));
0096     %     end
0097     %     hold off
0098         x_range = [min(eye_data(:,2)) max(eye_data(:,2))];
0099         y_range = [min(eye_data(:,2)) max(eye_data(:,3))];
0100         xlim(x_range);
0101         ylim(y_range);
0102 %         whitebg('black');
0103     end
0104     
0105     textstr = sprintf('%d %s %.4f valid gaze data', sub_id, agent, gaze_quality);
0106     annotation('textbox', [0.7 0.86 0.1 0.1], 'String', textstr, 'Color', 'r', 'BackgroundColor', 'k', 'FitBoxToText', 'on');
0107 
0108     filename = sprintf('%d_%s_gaze_heatmap', sub_id, agent);
0109     saveas(h, fullfile(save_path, filename), graph_format);
0110     close(h);
0111 % pause
0112 end

Generated on Tue 23-May-2017 03:00:58 by m2html © 2005