Home > data-import > main_object_position.m

main_object_position

PURPOSE ^

SYNOPSIS ^

function main_object_position(subid, corp)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function main_object_position(subid, corp)
0002 
0003 if numel(subid) > 1
0004     for s = 1 : numel(subid)
0005         fprintf('%d out of %d\n', s, numel(subid));
0006         main_object_position(subid(s), corp);
0007     end
0008     return
0009 end
0010 
0011 
0012 if strcmp(corp, 'child')
0013     camid = 5;
0014 elseif strcmp(corp, 'parent')
0015     camid = 6;
0016 else
0017     disp('corp argument must be parent or child');
0018 end
0019 
0020 
0021 trials = get_trials(subid);
0022 
0023 [frames filetype prefix] = start_end(subid, camid, trials(1), trials(end));
0024 
0025 
0026 object_min_distance = zeros(5, numel(frames));
0027 object_mean_distance = zeros(5, numel(frames));
0028 
0029 type = {'jpg' 'tif'};
0030 ft_other = type{~ismember(type, filetype)};
0031 
0032 for i = 1 : numel(frames)
0033     f_num = frames(i);
0034     img_file = sprintf('%s/img_%d_seg.%s', prefix, f_num, filetype);
0035     try
0036         img = imread(img_file);
0037     catch exception
0038         try
0039             img_file = sprintf('%s/img_%d_seg.%s', prefix, f_num, ft_other);
0040         catch exception2
0041         end
0042     end
0043            
0044         
0045     if max(max(img)) == 1
0046         img = img == 1;
0047     else
0048         img = img >= 50;
0049     end
0050     
0051     xmax = size(img, 2);
0052     ymax = size(img, 1);
0053     xcenter = xmax/2;
0054     ycenter = ymax/2;
0055     max_distance = sqrt(xcenter^2 + ycenter^2);
0056     
0057     segs = seperate_seg(img);
0058     
0059     if mod(f_num, 250) == 0
0060         fprintf('%d out of %d\n', f_num, frames(end));
0061     end
0062     
0063     
0064     for m = 2:4
0065         area = regionprops(bwconncomp(segs{m}),'PixelList', 'Area', 'Centroid');
0066         
0067         dmin = max_distance; % a big number
0068         dsum = 0;
0069         npixel = 0;
0070         for n = 1 : size(area,1)
0071             % compute the min
0072             temp = min(distance([xcenter; ycenter], area(n).PixelList'));
0073             %                     disp(temp)
0074             if (temp < dmin)
0075                 dmin = temp;
0076             end;
0077             
0078             dsum = dsum + area(n).Area * distance([xcenter;ycenter], area(n).Centroid');
0079             npixel = npixel + area(n).Area;
0080         end;
0081         
0082         object_min_distance(m,i) = dmin/max_distance;
0083         if npixel > 0
0084             object_mean_distance(m,i) = (dsum/npixel)/max_distance;
0085         else
0086             object_mean_distance(m,i) = 1;
0087         end;
0088         
0089     end
0090 end
0091 disp(size(object_min_distance));
0092 
0093 times = make_time(subid, frames);
0094 disp(size(times));
0095 
0096 for seg = 2:4
0097     vals = object_min_distance(seg, :)';
0098     var_name = sprintf('cont_vision_min-dist_obj%d_%s', seg-1, corp);
0099     record_variable(subid, var_name, [times, vals]);
0100 
0101 %     vals = object_mean_distance(seg, :)';
0102 %     var_name = sprintf('cont_vision_mean-dist_obj%d_%s', seg-1, corp);
0103 %     record_variable(subid, var_name, [times, vals]);
0104 
0105 end % for
0106 
0107 %     function [frames filetype prefix] = start_end(subid, camid, start, last)
0108 %         dir_name = get_subject_dir(subid);
0109 %         prefix = sprintf('%s/cam0%d_frames_p', dir_name, camid);
0110 %         frames = zeros(last+10, 2);
0111 %         filetype = 'jpg';
0112 %         for f = start:last
0113 %             img_file1 = sprintf('%s/img_%d_seg.%s', prefix, f, filetype);
0114 %             if exist(img_file1, 'file')
0115 %                 if start == 0;
0116 %                     frames(f+1, :) = [f 1];
0117 %                 else
0118 %                     frames(f,:) = [f 1];
0119 %                 end
0120 %             elseif exist(strrep(img_file1, 'jpg', 'tif'), 'file')
0121 %                 filetype = 'tif';
0122 %                 if start == 0;
0123 %                     frames(f+1, :) = [f 1];
0124 %                 else
0125 %                     frames(f,:) = [f 1];
0126 %                 end
0127 %             end
0128 %         end
0129 %         log = frames(:,2) == 0;
0130 %         frames(log,:) = [];
0131 %         frames = frames(:,1);
0132 %     end
0133 
0134 
0135 
0136 end

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