Home > data-analysis > modules > gaze > fixation_code > assign_fixation_roi.m

assign_fixation_roi

PURPOSE ^

This function assign a roi value to each fixation from cstream_roi.

SYNOPSIS ^

function fix_roi = get_fixation_roi(time, fix_time, fix_durations, cstream_roi)

DESCRIPTION ^

 This function assign a roi value to each fixation from cstream_roi.
 Majority vote approach is adopted when there are multiple roi in one
 fixation.
 
 Inputs:
   time:           time stamps from raw data cont_x, cont_y
    fix_time:       onset time stamp of each fixation, n by 1
   fix_durations:  duration of each fixation
   cstream_roi:    cstream of roi data from human coding
 
 Outputs:
   fix_roi:        roi for each fixation, n by 1

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function fix_roi = get_fixation_roi(time, fix_time, fix_durations, cstream_roi)
0002 
0003 % This function assign a roi value to each fixation from cstream_roi.
0004 % Majority vote approach is adopted when there are multiple roi in one
0005 % fixation.
0006 %
0007 % Inputs:
0008 %   time:           time stamps from raw data cont_x, cont_y
0009 %    fix_time:       onset time stamp of each fixation, n by 1
0010 %   fix_durations:  duration of each fixation
0011 %   cstream_roi:    cstream of roi data from human coding
0012 %
0013 % Outputs:
0014 %   fix_roi:        roi for each fixation, n by 1
0015 %
0016 
0017 roi = align_streams(time, {cstream_roi});
0018 fix_mask = zeros(length(time),1);
0019 fix_indexes = nan(size(fix_time,1),2);
0020 
0021 for tidx = 1:size(fix_time,1)
0022     start_time = fix_time(tidx);
0023     end_time = start_time + fix_durations(tidx);
0024     x_mask = time <= end_time & time >= start_time;
0025     x_find = find(x_mask);
0026     fix_mask = fix_mask | x_mask;
0027     fix_indexes(tidx,1) = x_find(1);
0028     fix_indexes(tidx,2) = x_find(end);
0029 end
0030 
0031 
0032 fix_roi = zeros(size(fix_indexes,1),1);
0033 roi(~fix_mask) = 0;
0034 
0035 roi_nan_x = isnan(roi);
0036 roi(roi_nan_x) = 0;
0037 
0038 for i = 1:size(fix_indexes, 1)
0039 %     i = 4;
0040     start_idx = fix_indexes(i,1);
0041     end_idx = fix_indexes(i,2);
0042 
0043     fix_roi_one = roi(start_idx:end_idx);
0044     
0045     fix_is_zero_x = fix_roi_one == 0;
0046         
0047     if sum(fix_is_zero_x)
0048         temp_I = find(fix_is_zero_x);                
0049 
0050         if temp_I(1) ~= 1
0051             fix_roi_one(fix_is_zero_x) = fix_roi_one(temp_I(1)-1);
0052         elseif temp_I(end) < length(fix_is_zero_x)
0053             fix_roi_one(fix_is_zero_x) = fix_roi_one(temp_I(end)+1);
0054         else
0055             if start_idx ~= 1
0056                 fix_roi_one(fix_is_zero_x) = roi(start_idx-1);
0057             end
0058         end
0059     end
0060     
0061     fix_unique_one = unique(fix_roi_one);
0062     
0063     % is consistant
0064     if size(fix_unique_one) == 1
0065         fix_roi(i) = fix_unique_one(1);
0066     else
0067             
0068         fix_uniqiue_num = nan(1,length(fix_unique_one));
0069             
0070         for j = 1:length(fix_unique_one)
0071             temp = fix_unique_one(j);
0072             fix_uniqiue_num(j) = sum(fix_roi_one==temp);
0073         end
0074         
0075         temp1 = fix_uniqiue_num(1);
0076         isequal = (fix_uniqiue_num == temp1);
0077         if sum(isequal) == length(fix_uniqiue_num)
0078             fix_roi(i) = fix_roi_one(1);
0079         else           
0080             [max_temp max_idx] = max(fix_uniqiue_num);
0081             fix_roi(i) = fix_unique_one(max_idx);
0082         end
0083 
0084     end
0085     
0086 %     if length(fix_unique_one) > 1
0087 %         disp([time(start_idx) time(end_idx)]);
0088 %         fix_roi(i)
0089 %         disp('**************************************')
0090 %         pause;
0091 %     end
0092 end

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