Home > GVSToolbox > codeFixationsDist.m

codeFixationsDist

PURPOSE ^

identify fixations

SYNOPSIS ^

function [ fixStruct ] = codeFixationsDist( eyeTrack, windowSize, viewThreshold )

DESCRIPTION ^

 identify fixations
 June 22, 2011
 Notes: This function codes the eye track sequence according to the fixations
   It checks to make sure that the fixation is not immediately at start of
   sequence (from fixation slide) and eliminates this fixation if necessary
   We identify fixations using the IDT algorithm
 
 syntax: [ fixStruct ]  = codeFixations( eyeTrack, windowSize, viewThreshold )
 
 Inputs: 
       eyeTrack: vector  of complex (x+i*y) coordinates.  -1-i1  to identify
           missing data. Data should be scaled according to the image dimensions.  
           See function 'scaleEyeTrack'.
       windowSize: integer of consecutive frames which should be within a
           threshold of distance from one another (to be considered a
           fixation) , ( 6 is good value for 60 Hz)
       viewThreshold: euclidean distance within which eye positions are
           considered part of same fixation, 15 is a good number for 30 px
           diameter
  
 Outputs:
       fixStruct, having 
       fixStruct.fixDurVector: vector of (fx1),  for duration of fications
       fixStruct.fixPosVector: in format [ x x x ... x; 
                                                          y y y ... y]
       fixStruct.fixationVector: (N by1) vector having 0 where no fixations, then 1, 2 ,3,
           and so on for the fixations in the sequence

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % identify fixations
0002 % June 22, 2011
0003 % Notes: This function codes the eye track sequence according to the fixations
0004 %   It checks to make sure that the fixation is not immediately at start of
0005 %   sequence (from fixation slide) and eliminates this fixation if necessary
0006 %   We identify fixations using the IDT algorithm
0007 %
0008 % syntax: [ fixStruct ]  = codeFixations( eyeTrack, windowSize, viewThreshold )
0009 %
0010 % Inputs:
0011 %       eyeTrack: vector  of complex (x+i*y) coordinates.  -1-i1  to identify
0012 %           missing data. Data should be scaled according to the image dimensions.
0013 %           See function 'scaleEyeTrack'.
0014 %       windowSize: integer of consecutive frames which should be within a
0015 %           threshold of distance from one another (to be considered a
0016 %           fixation) , ( 6 is good value for 60 Hz)
0017 %       viewThreshold: euclidean distance within which eye positions are
0018 %           considered part of same fixation, 15 is a good number for 30 px
0019 %           diameter
0020 %
0021 % Outputs:
0022 %       fixStruct, having
0023 %       fixStruct.fixDurVector: vector of (fx1),  for duration of fications
0024 %       fixStruct.fixPosVector: in format [ x x x ... x;
0025 %                                                          y y y ... y]
0026 %       fixStruct.fixationVector: (N by1) vector having 0 where no fixations, then 1, 2 ,3,
0027 %           and so on for the fixations in the sequence
0028 
0029 
0030 function [ fixStruct ] = codeFixationsDist( eyeTrack, windowSize, viewThreshold )
0031 
0032     if nargin < 2
0033         windowSize = 6;
0034     end
0035     if nargin < 3
0036         viewThreshold = 15;
0037     end
0038 
0039     numSamples =  length( eyeTrack);
0040     fixationVector = zeros(numSamples ,1);  
0041     fixDurVector = zeros(numSamples ,1);  
0042     fixPosVector = zeros( 2, numSamples );
0043     startPos = 1; 
0044 
0045     fixIndex = 1;  fixLength = 0; k1 = 1;
0046     while  ( fixIndex~=-1 ) && (startPos < numSamples ) 
0047         %     [k1 fixIndex fixLength]
0048         [fixIndex fixPosition fixLength] = findFixation(  eyeTrack, windowSize, viewThreshold, startPos );
0049         startPos = fixIndex + fixLength;
0050         if  fixIndex~=-1 
0051             fixationVector( fixIndex:(fixIndex+fixLength-1)) = k1;
0052             fixPosVector(:,k1 ) = fixPosition(:);
0053             fixDurVector(k1,1) = fixLength;
0054             k1 = k1+1;
0055         end
0056         
0057     end
0058     fixPosVector(:,k1:end) = []; %clean up unused parts
0059     fixDurVector( k1+1:end) = [];
0060     
0061     
0062     % eliminate first fixation if it coincides with the
0063     % fixation slide ( start of sequence)
0064     if fixationVector(1) == 1
0065         fixationVector( fixationVector==1) = 0;
0066         fixationVector( fixationVector ~= 0 ) = fixationVector( fixationVector ~= 0 )-1;
0067         fixPosVector( :,1) = [];
0068         fixDurVector(1) = [];
0069     end
0070 
0071     fixStruct.fixPosVector = fixPosVector;
0072     fixStruct.fixDurVector = fixDurVector;
0073     fixStruct.fixationVector = fixationVector;
0074     
0075 end
0076 %---------------------------------------------------
0077 
0078 % Outputs:
0079 %      fixIndex: integer index for beginning of fixation. -1 if none found
0080 %      fixPosition: vector of the fixation position (mean of the window) -1 if none found
0081 %      fixLength: : integer specifying total length of fixation, -1 if none found
0082 
0083 function [fixIndex, fixPosition, fixLength] = findFixation(  eyeTrack, windowSize, viewThreshold, startPos )
0084 
0085     %--------------------------------------------------------
0086     %--------------- initialize -----------------------
0087 
0088     minTracksToConsider = floor( 2/3 * windowSize ); % integer, specifying minimum samples
0089                                                                                  %   tracked when calculating fixation
0090     eyeTrack =  [ real( eyeTrack(:)) imag(eyeTrack(:)) ]'; % in [ x x ... x; y y ... y ]
0091     maxPos = size( eyeTrack,2) - windowSize+1;
0092     fixPosition = -1; fixLength = -1;
0093     fixIndex = -1; % will stay -1 if none found
0094 
0095     % specify search start position
0096     if nargin < 4 || isempty( startPos )   
0097         i1 = 0;
0098     else
0099         i1 =  startPos-1;
0100     end
0101 
0102     %--------------------------------------------------------
0103     %-----------find fixation position --------------------------
0104 
0105     while (i1 < maxPos) && (fixIndex==-1)
0106 
0107         %increment, until start with not missing if necessary
0108          i1 =  i1+1;     
0109         while (i1 < maxPos) && (eyeTrack(1,i1)==-1) 
0110             i1 =  i1+1; 
0111         end
0112 
0113         % select window of windowSize samples, expand if
0114         % too much missing data or if last sample is missing
0115         i2 = 0; %for expanding window
0116         window = eyeTrack(:, i1:(i1+windowSize-1));
0117         missIdx = find( window(1,:) == -1 );
0118         window( :, missIdx ) = [];
0119         % old way
0120 %         window( window==-1) = [];
0121 %         window = reshape( window, 2,[]);
0122         while ( (size( window,2) < minTracksToConsider ) || ...
0123                     (eyeTrack(1, i1+windowSize-1+i2)==-1)  ) ...
0124                      && (i1+i2)<maxPos  % do not expand too far
0125             i2 = i2+1;
0126             window = eyeTrack(:, i1:(i1+windowSize-1+i2));
0127             missIdx = find( window(1,:) == -1 );
0128             window( :, missIdx ) = [];
0129             % old way
0130     %         window( window==-1) = [];
0131     %         window = reshape( window, 2,[]);
0132         end
0133 
0134         % determine if fixation based on viewThreshold
0135 
0136         %         window = reshape( window, 2,[]);
0137         if size( window,2) >= minTracksToConsider %handle missing data
0138             
0139             %         dist = ( repmat(mean(window,2),1,size(window,2)) - window);
0140             %         dist = sqrt(sum(dist.^2,1));
0141             dist = calc2Dist( mean(window,2), window); %euclidean distance from mean to all
0142             if max( dist ) < viewThreshold
0143                 fixIndex = i1; %store fixation position
0144                 fixPosition =  mean(window,2);
0145             end        
0146         end    
0147 
0148     end
0149 
0150     %---------------------------------------------------------
0151     %-----------find fixation duration ( if fixation found)------------
0152 
0153     if  fixIndex ~= -1
0154 
0155         % initialize for keeping track/convenience
0156         eyeTrack(:,1:fixIndex-1) = [];
0157         missingIndices = 1:size(eyeTrack,2);
0158         knownIndices = missingIndices( eyeTrack(1,:)~=-1);
0159         missingIndices( eyeTrack(1,:)~=-1) = [];
0160         eyeTrack( :, missingIndices) = [];  
0161 
0162          % find furthest index within threshold distance
0163          dist = calc2Dist( fixPosition, eyeTrack);
0164          i1 =1;
0165          while  (i1<=length(dist)) && (dist(i1) < viewThreshold) 
0166              i1 = i1+1; 
0167          end;      
0168          fixLength = knownIndices(i1-1);
0169 
0170     end
0171 
0172 end

Generated on Tue 01-Jul-2014 12:35:04 by m2html © 2005