Home > data-import > supporting_functions > main_create_eye_center_dist_vars.m

main_create_eye_center_dist_vars

PURPOSE ^

[eye_xy blob_centers min_dist mean_dist] =

SYNOPSIS ^

function main_create_eye_center_dist_vars(sub_id, agent_type, img_w, img_h, eye_w, eye_h, is_record_vars)

DESCRIPTION ^

 [eye_xy blob_centers min_dist mean_dist] =

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function main_create_eye_center_dist_vars(sub_id, agent_type,  img_w, img_h, eye_w, eye_h, is_record_vars)
0002 % [eye_xy blob_centers min_dist mean_dist] =
0003 
0004 % MAIN_EXP29_DETECT_OBJECTS: Segment three objects (and skin) for
0005 % camera 6 of experiment 29; Only image frames within trials will be
0006 % processed.
0007 %
0008 % Input:
0009 %   sub_list: The list of ubjects
0010 %   img_step:  Only process 1 frame in every img_step; default value is 1 (process all the image frames.
0011 %   overwrite_flag: If it is true, the output of this program will overwrite pre-existing segmentation result images.
0012 %                   Default value is true;
0013 %
0014 % Note: To do segmentation on subject 2901's images, the color parameter
0015 % need to be changed in function detect_color_object.
0016 %
0017 %  Hongwei Shen, 03/25/2011
0018 %  Re-write by: txu@indiana.edu
0019 %  Update Apr. 3, 2013
0020 
0021 if ~exist('is_record_vars', 'var')
0022     is_record_vars = 0;
0023 end
0024 %
0025 % if ~exist('img_w', 'var')
0026 %     img_w = 360; % the number of columns = the width of the image by default
0027 % end
0028 %
0029 % if ~exist('img_h', 'var')
0030 %     img_h = 240; % the number of rows = the height of the image by default
0031 % end
0032 
0033 % max_distance = sqrt(img_w^2 + img_h^2);
0034 center_xy = [img_w/2 img_h/2];
0035 max_dist = distance(center_xy', [0 0]');
0036 
0037 error_log = {};
0038 error_count = 0;
0039     
0040 eye_var_name = ['cont2_eye_xy_' agent_type];
0041 if has_variable(sub_id, eye_var_name)
0042     eye_xy = get_variable(sub_id, eye_var_name);
0043 
0044     trial_times = get_trial_times(sub_id);
0045     if eye_xy(end,1) < (trial_times(end, 2)-0.05)
0046         [trial_times(1, 1) trial_times(end, 2)]
0047         [eye_xy(1,1) eye_xy(end,1)]
0048         fprintf('Trial end time %d, eye dat end time %d', trial_times(end, 2), eye_xy(end,1));
0049         error('Subject %d variable %s missing within trial values!', sub_id, eye_var_name);
0050     end
0051     eye_xy = eye_xy(eye_xy(:,1) >= trial_times(1, 1) & eye_xy(:,1) <= trial_times(end, 2), :);
0052 
0053     time = eye_xy(:,1);
0054 %         eye_xy = align_streams(time, {eye_xy});      %  align eye_data to the time stamps
0055 %         eye_xy = [time eye_xy];
0056     eye_xy(:,2) = eye_xy(:,2)/eye_w * img_w; % HARD CODING, mapping
0057     eye_xy(:,3) = eye_xy(:,3)/eye_h * img_h; % HARD CODING, mapping
0058 else
0059     warning('missing eye xy variable');
0060     return
0061 end
0062 
0063 N = length(time);
0064 center_dist = NaN(N, 1);
0065 
0066 for eidx = 1:N
0067 %         this_eye_time = eye_xy(eidx, 1);
0068     this_eye_xy = eye_xy(eidx, 2:end);
0069 
0070     if this_eye_xy(1) > eye_w || this_eye_xy(2) > eye_h
0071         error('Subject %d eye data out of range!', sub_id);
0072     end
0073 
0074 %     center_xy
0075 %     this_eye_xy
0076     center_dist(eidx) = distance(center_xy', this_eye_xy');
0077 
0078     if center_dist(eidx) > max_dist
0079         error('Subject %d invalid distance value!', sub_id);
0080     end
0081 end
0082 
0083 % cont_eye_dist-to-center_child/parent
0084 if is_record_vars
0085     record_variable(sub_id, ['cont_eye_dist-to-center_' agent_type], [time center_dist]);
0086 end
0087 
0088 end
0089 
0090

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