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

main_detect_objects_5

PURPOSE ^

Re-write by: txu@indiana.edu update date: Sep. 22, 2014

SYNOPSIS ^

function [time, blob_size_all, blob_center_all, blob_dyn_all, center_mean_dist_all, center_min_dist_all] = main_detect_objects_5(sub_id, jpg_folder, output_folder, agent_type, obj_num, obj_params, seg_image_overwrite_flag, seg_image_format, img_step)

DESCRIPTION ^

  Re-write by: txu@indiana.edu update date: Sep. 22, 2014

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, center_mean_dist_all, center_min_dist_all] = main_detect_objects_5(sub_id, jpg_folder, output_folder, agent_type, obj_num, obj_params, seg_image_overwrite_flag, seg_image_format, img_step)
0002 %  Re-write by: txu@indiana.edu update date: Sep. 22, 2014
0003 
0004 if obj_num ~= 5
0005     error('This script is for processing experiments with 5 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 jpg_list = dir(fullfile(jpg_folder, 'img_*.jpg'));  % hard coding
0027 
0028 img_seq_pos = -1;
0029 jpg_list = sort_file_name_by_seq(jpg_list, img_seq_pos);  
0030 [jpg_list, seq_no] = extract_img_name_list(jpg_list, img_step, img_seq_pos);
0031 time = frame_num2time(seq_no, sub_id);
0032 
0033 N = length(jpg_list);
0034 
0035 blob_size_all = nan(N,(obj_num+1));
0036 blob_center_all = nan(N,(obj_num+1)*2);
0037 blob_dyn_all = nan(N,(obj_num+1));
0038 center_mean_dist_all = NaN(N, obj_num+2);
0039 center_min_dist_all = NaN(N, obj_num+2);
0040 
0041 fprintf('frame       ');
0042 
0043 for j=1:8300        
0044     fprintf('\b\b\b\b\b\b%5d:', seq_no(j));
0045     jpg = jpg_list(j).name;       
0046     img = imread(fullfile(jpg_folder, jpg));
0047     img = imresize(img, ratio);
0048 
0049     [img_h, img_w] = size(img(:,:,1));
0050     total_pix = img_h*img_w;
0051 
0052     [blob_size, blob_center, blob_cells] = ...
0053         detect_color_object_5(img, agent_type, obj_num, obj_params);
0054     [center_mean_dist, center_min_dist] = cal_center2obj_dist(obj_num, blob_cells);
0055 
0056     % combine four binary images into one.
0057     seg_img = combine_obj_detection_results(blob_cells, img_h, img_w);
0058     if j == 1
0059         blob_dyn = nan(1,obj_num+1);
0060     else
0061         blob_dyn = cal_dyn_obj_size(obj_num, total_pix, prev_blob_cells, blob_cells);
0062     end
0063     prev_blob_cells = blob_cells;
0064 
0065     blob_size_all(j,:) = blob_size;
0066     blob_center_all(j,:) = blob_center;
0067     blob_dyn_all(j,:) = blob_dyn;
0068     center_mean_dist_all(j,:) = center_mean_dist;
0069     center_min_dist_all(j,:) = center_min_dist;
0070 
0071     if seg_image_overwrite_flag
0072         output_file_name = fullfile(output_folder, sprintf('img_%g_seg.%s', seq_no(j), seg_image_format));
0073         imwrite(seg_img, output_file_name);
0074     end
0075 end
0076

Generated on Tue 23-May-2017 02:00:59 by m2html © 2005