This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/projects/project_eyetracker/solution/fix_eye_lost.m

23 lines
905 B
Matlab

function [new_x, new_y] = fix_eye_lost(x, y, frame_index, eye_found)
% [new_x, new_y] = fix_eye_lost(x, y, frame_index, eye_found)
%
% Fixes intervals in the data in which eye detection was lost. Function uses linear interpolation.
%
% Arguments:
% x, y: vector, the eye positions
% frame_indices: vector, same length as x and y, the frame
% indices (or times)
% eye_found: vector, ones and zeros indicate whether the eye was
% reliably found by the tracker or not.
%
% Returns:
% new_x, new_y: vectors of double, the new positions
valid_x_positions = double(x(eye_found == 1));
valid_y_positions = double(y(eye_found == 1));
valid_frame_indices = double(frame_index(eye_found == 1));
new_x = interp1(valid_frame_indices, valid_x_positions, double(frame_index));
new_y = interp1(valid_frame_indices, valid_y_positions, double(frame_index));