Home > data-import > supporting_functions > lib > main_detect_objects_eye_dist_3.m

main_detect_objects_eye_dist_3

PURPOSE ^

Re-write by: txu@indiana.edu update date: Oct. 15, 2013

SYNOPSIS ^

function [time, blob_size_all, blob_center_all, blob_dyn_all, eye_mean_dist, eye_min_dist, center_mean_dist, center_min_dist] = main_detect_objects_eye_dist_3(sub_id, jpg_folder, output_folder, agent_type, obj_num, obj_params, is_record_eye_vars, seg_image_overwrite_flag, seg_image_format, img_step)

DESCRIPTION ^

  Re-write by: txu@indiana.edu update date: Oct. 15, 2013

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [time, blob_size_all, blob_center_all, blob_dyn_all, eye_mean_dist, eye_min_dist, center_mean_dist, center_min_dist] = main_detect_objects_eye_dist_3(sub_id, jpg_folder, output_folder, agent_type, obj_num, obj_params, is_record_eye_vars, seg_image_overwrite_flag, seg_image_format, img_step)
0002 %  Re-write by: txu@indiana.edu update date: Oct. 15, 2013
0003 
0004 if obj_num > 3
0005     error('This script is for processing experiments with 3 objects only');
0006 end
0007 
0008 if ~exist('img_step', 'var')
0009     img_step = 1;
0010 end
0011 
0012 if ~exist('seg_image_overwrite_flag', 'var')
0013     seg_image_overwrite_flag = false;
0014 end
0015 
0016 if ~exist('seg_image_format', 'var')
0017     seg_image_format = 'png';
0018 end
0019 
0020 ratio = 0.5;    % resize the images before object detection to increase processing speed.
0021 
0022 if ~exist(output_folder, 'dir')
0023     mkdir(output_folder);
0024 end
0025 
0026 if ismember(sub_id, list_subjects(14))
0027     max_distance_half = 1;
0028 else
0029     max_distance_half = 0;
0030 end
0031 jpg_list = dir(fullfile(jpg_folder, '*img_*.jpg'));  % hard coding
0032 
0033 img_seq_pos = -1;
0034 jpg_list = sort_file_name_by_seq(jpg_list, img_seq_pos);  
0035 [jpg_list, seq_no] = extract_img_name_list(jpg_list, img_step, img_seq_pos);
0036 time = frame_num2time(seq_no, sub_id);
0037 
0038 N = length(jpg_list);
0039 
0040 blob_size_all = nan(N,(obj_num+1));
0041 blob_center_all = nan(N,(obj_num+1)*2);
0042 blob_dyn_all = nan(N,(obj_num+1));
0043 
0044 if is_record_eye_vars
0045     eye_var_name = ['cont2_eye_xy_' agent_type];
0046     if ~has_variable(sub_id, eye_var_name)
0047         fprintf('Subject %d does not have variable cont2_eye_xy_%s\n', sub_id, agent_type)
0048         is_record_eye_vars = false;
0049     else
0050         eye_xy = get_variable(sub_id, eye_var_name);
0051         eye_xy = eye_xy(eye_xy(:,1) >= time(1) & eye_xy(:,1) <= time(end), :);
0052         eye_xy = align_streams(time, {eye_xy});      %  align eye_data to the time stamps
0053         eye_xy = [time eye_xy];
0054     end
0055 end
0056 
0057 eye_mean_dist = NaN(N, obj_num+2);
0058 eye_min_dist  = NaN(N, obj_num+2);
0059 center_mean_dist = NaN(N, obj_num+2);
0060 center_min_dist  = NaN(N, obj_num+2);
0061 
0062 fprintf('frame       ');
0063 
0064 for j=1:N
0065     fprintf('\b\b\b\b\b\b%5d:', seq_no(j));
0066 
0067     jpg = jpg_list(j).name;       
0068     img = imread(fullfile(jpg_folder, jpg));
0069     img = imresize(img, ratio);
0070 
0071     [img_h, img_w] = size(img(:,:,1));
0072     total_pix = img_h*img_w;
0073 
0074     [blob_size, blob_center, blob_cells] = ...
0075         detect_color_object(img, agent_type, obj_num, obj_params);
0076     
0077     if is_record_eye_vars
0078         this_eye_xy = eye_xy(j, 2:end);
0079         [eye_mean_one, eye_min_one, center_mean_one, center_min_one] = cal_eye2obj_dist(this_eye_xy, obj_num, ratio, blob_cells, max_distance_half);
0080         eye_mean_dist(j, :) = eye_mean_one;
0081         eye_min_dist(j, :) = eye_min_one;
0082         center_mean_dist(j, :) = center_mean_one;
0083         center_min_dist(j, :) = center_min_one;
0084     else
0085         [~, ~, center_mean_one, center_min_one] = cal_eye2obj_dist([], obj_num, ratio, blob_cells, max_distance_half);
0086         center_mean_dist(j, :) = center_mean_one;
0087         center_min_dist(j, :) = center_min_one;
0088     end
0089 
0090     % combine four binary images into one.
0091     seg_img = combine_obj_detection_results(blob_cells(1:4), img_h, img_w);
0092     if j == 1
0093         blob_dyn = nan(1,obj_num+1);
0094     else
0095         blob_dyn = cal_dyn_obj_size(obj_num, total_pix, prev_blob_cells, blob_cells);
0096     end
0097     prev_blob_cells = blob_cells;
0098 
0099     blob_size_all(j,:) = blob_size;
0100     blob_center_all(j,:) = blob_center;
0101     blob_dyn_all(j,:) = blob_dyn;
0102         
0103     if seg_image_overwrite_flag
0104         output_file_name = fullfile(output_folder, sprintf('img_%g_seg.%s', seq_no(j), seg_image_format));
0105         imwrite(seg_img, output_file_name);
0106     end    
0107 end
0108 if max_distance_half
0109     center_mean_dist(isnan(center_mean_dist)) = 1;
0110     center_min_dist(isnan(center_min_dist)) = 1;
0111 end
0112

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