Home > data-import > make_eye_xy.m

make_eye_xy

PURPOSE ^

eye_range.txt is a tab-delimited file in extra_p of each subject folder

SYNOPSIS ^

function make_eye_xy(IDs, corp, ranges)

DESCRIPTION ^

eye_range.txt is a tab-delimited file in extra_p of each subject folder
and specifies the range of eye data as indicated by the red bar in the
first and last frames of cam01 and cam02. The first line of eye_range.txt
is the child onset and offset, while the second line is for parent. This
script also filters out data points outside of bound pixel width and
height. It assumes 640 x 480 resolution.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function make_eye_xy(IDs, corp, ranges)
0002 %eye_range.txt is a tab-delimited file in extra_p of each subject folder
0003 %and specifies the range of eye data as indicated by the red bar in the
0004 %first and last frames of cam01 and cam02. The first line of eye_range.txt
0005 %is the child onset and offset, while the second line is for parent. This
0006 %script also filters out data points outside of bound pixel width and
0007 %height. It assumes 640 x 480 resolution.
0008 
0009 % IDs = 3408;
0010 % corp = [1];
0011 
0012 xmax = 640;
0013 ymax = 480;
0014 % addpath('./gaze');
0015 
0016 if numel(num2str(IDs(1))) > 2
0017     sid = IDs;
0018 else
0019     sid = list_subjects(IDs);
0020 end
0021 if numel(sid) > 1
0022     if exist('ranges', 'var') && ~isempty(ranges)
0023         error('Cannot specify ranges if more than one sid');
0024     end
0025     for s = 1:numel(sid)
0026         make_eye_xy_v2(sid(s), corp);
0027     end
0028     return
0029 end
0030 
0031 if ~exist('ranges', 'var') || isempty(ranges)
0032     %look for eye_range.txt in extra_p
0033     fn = fullfile(get_subject_dir(sid), 'extra_p', 'eye_range.txt');
0034     ranges = dlmread(fn, '\t');
0035     ranges = (num2cell(ranges,2))';
0036     ranges = ranges(corp);
0037 end
0038 
0039 if ~iscell(ranges)
0040     ranges = {ranges};
0041 end
0042 
0043 person = {'child' 'parent'};
0044 
0045 sub_dir = get_subject_dir(sid);
0046 sub_dir_extra_p = [sub_dir '/extra_p'];
0047 dirs = {sub_dir sub_dir_extra_p};
0048 txtendings = {'.txt' '_eye.txt'};
0049 
0050 prefix = strfind(sub_dir, '__');
0051 prefix = {[sub_dir(prefix:end) '_'] ''};
0052 
0053 for p = 1:numel(corp)
0054     personid = person{corp(p)};
0055     range = ranges{p};
0056     if range(1) ~= -1
0057         for d = 1:numel(dirs)
0058             for t = 1:numel(txtendings)
0059                 for f = 1:numel(prefix);
0060                     eye_file = sprintf('%s/%s%s%s', dirs{d}, prefix{f}, personid, txtendings{t});
0061                     if exist(eye_file, 'file')
0062                         disp('Found eye file');
0063                         if ~exist('foundfile', 'var')
0064                             foundfile = eye_file;
0065                         end
0066                     end
0067                 end
0068             end
0069         end
0070         if ~exist('foundfile', 'var')
0071             disp(['Could not find eye text file for ' personid]);
0072             break
0073         end
0074         eye_file = foundfile; disp(eye_file);
0075         clear foundfile;
0076         
0077         stop = 0;
0078         
0079         fid = fopen(eye_file, 'r');
0080         allrows = {};
0081         idx = 1;
0082         %open and read file line by line until 'recordFrameCount' is reached
0083         while stop == 0
0084             tline = fgetl(fid);
0085             if strfind(tline, 'recordFrameCount')
0086                 headers = textscan(tline, '%s');
0087                 fgetl(fid); %skip blank line
0088                 tline = fgetl(fid); %get first line of data
0089                 while tline ~= -1
0090                     allrows{idx,1} = tline;
0091                     tline = fgetl(fid);
0092                     idx = idx + 1;
0093                 end
0094                 stop = 1;
0095             end
0096         end
0097         fclose(fid);
0098         
0099         bw = cellfun(@(A) strtrim(A), allrows, 'un', 0);
0100         tmp = cellfun(@(A) strsplit(A, ' '), bw, 'un', 0);
0101         alldata = vertcat(tmp{:});
0102         headers = headers{1};
0103         %find correct indices for headers
0104         porxidx = ismember(headers, 'porX');
0105         poryidx = ismember(headers, 'porY');
0106         sfcidx = ismember(headers, 'sceneFrameCount');
0107         if sum(sfcidx) == 0
0108             sfcidx = ismember(headers, 'movieFrameCount');
0109         end
0110         %get the relevant columns in the data
0111         reldata = horzcat(alldata(:,sfcidx), alldata(:,porxidx), alldata(:,poryidx));
0112         reldata = str2double(reldata);
0113         %get data in range
0114         ib = find(reldata(:,1) == range(1));
0115         ie = find(reldata(:,1) == range(2));
0116         xydata = reldata(ib:ie,[2 3]);
0117         %filter data
0118         xydata(xydata(:,1)>xmax,:) = NaN;
0119         xydata(xydata(:,1)<0,:) = NaN;
0120         
0121         xydata(xydata(:,2)>ymax,:) = NaN;
0122         xydata(xydata(:,2)<0,:) = NaN;
0123         
0124         %get subject information
0125         tinfo = get_timing(sid);
0126         base = (0:size(xydata,1)-1)';
0127         base = base/tinfo.camRate;
0128         %create the time sequence
0129         timebase = base + tinfo.camTime;
0130         eye_data = [timebase xydata(:,[1 2])];
0131 
0132         %% start checking and saving
0133         if ismember(sid, get_rescale_gaze_subject_list)
0134             is_record_var = true;
0135             enable_visualize_heatmap = false;
0136             enable_check_visualize_range = false;
0137             frame_offset = 0; %by default
0138             check_save_eye_xy_variables(sid, eye_data, personid, ...
0139                 frame_offset, is_record_var, enable_visualize_heatmap, enable_check_visualize_range);
0140         else
0141             %record variables
0142             record_variable(sid, sprintf('cont2_eye_xy_%s', personid), [timebase xydata(:,[1 2])]);
0143             record_variable(sid, sprintf('cont_eye_x_%s', personid), [timebase xydata(:,1)]);
0144             record_variable(sid, sprintf('cont_eye_y_%s', personid), [timebase xydata(:,2)]);
0145         end
0146     end
0147 end

Generated on Wed 24-May-2017 00:00:56 by m2html © 2005