Home > data-utility > main_check_frames_with_infofile.m

main_check_frames_with_infofile

PURPOSE ^

This function is written to check

SYNOPSIS ^

function checking_results = main_check_frames_with_infofile(sub_list, save_path, img_step)

DESCRIPTION ^

 This function is written to check 
 for all the cameras in each subject, whether the frame images in ALL  
 the camera folder match up exactly with the trial info frame number.
 
 Output:
 >> checking_results = main_check_frames_with_infofile(list_subjects(32));
 
 The program will first prompt all the progress:
 
 Checking done for cam01_frames_p for subject 3201
 
 Checking done for cam02_frames_p for subject 3201
 
 Checking done for cam03_frames_p for subject 3201
 
 Checking done for cam04_frames_p for subject 3201
 
 Checking done for cam07_frames_p for subject 3201
 
 Checking done for cam08_frames_p for subject 3201
 
 Checking done for cam01_frames_p for subject 3202
 
 Checking done for cam02_frames_p for subject 3202
 
 Checking done for cam03_frames_p for subject 3202
 
 Checking done for cam04_frames_p for subject 3202
 
 Frames do not match with info file in cam07_frames_p for subject 3202
 
 Checking done for cam07_frames_p for subject 3202
 
 Checking done for cam08_frames_p for subject 3202
 
 ...
 
 And at the end, it will generate a text error log file including all 
 the miss-matched frame numbers, for example:
 
 <frame_check_errorlog_3202.txt>
 Subject 3202
 
 Trial frames:
 0  2648
 5316  7944
 8183  10768
 11124  12993
 
 Checking date:
 11-7_2012_15-32
 
 ==============
 cam07_frames_p
 missing frames: 0      1   5316   5317   8183   8184  11124  11125
 extra frames: 2649   2650   7945   7946  10769  10770  12994  12995

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function checking_results = main_check_frames_with_infofile(sub_list, save_path, img_step)
0002 % This function is written to check
0003 % for all the cameras in each subject, whether the frame images in ALL
0004 % the camera folder match up exactly with the trial info frame number.
0005 %
0006 % Output:
0007 % >> checking_results = main_check_frames_with_infofile(list_subjects(32));
0008 %
0009 % The program will first prompt all the progress:
0010 %
0011 % Checking done for cam01_frames_p for subject 3201
0012 %
0013 % Checking done for cam02_frames_p for subject 3201
0014 %
0015 % Checking done for cam03_frames_p for subject 3201
0016 %
0017 % Checking done for cam04_frames_p for subject 3201
0018 %
0019 % Checking done for cam07_frames_p for subject 3201
0020 %
0021 % Checking done for cam08_frames_p for subject 3201
0022 %
0023 % Checking done for cam01_frames_p for subject 3202
0024 %
0025 % Checking done for cam02_frames_p for subject 3202
0026 %
0027 % Checking done for cam03_frames_p for subject 3202
0028 %
0029 % Checking done for cam04_frames_p for subject 3202
0030 %
0031 % Frames do not match with info file in cam07_frames_p for subject 3202
0032 %
0033 % Checking done for cam07_frames_p for subject 3202
0034 %
0035 % Checking done for cam08_frames_p for subject 3202
0036 %
0037 % ...
0038 %
0039 % And at the end, it will generate a text error log file including all
0040 % the miss-matched frame numbers, for example:
0041 %
0042 % <frame_check_errorlog_3202.txt>
0043 % Subject 3202
0044 %
0045 % Trial frames:
0046 % 0  2648
0047 % 5316  7944
0048 % 8183  10768
0049 % 11124  12993
0050 %
0051 % Checking date:
0052 % 11-7_2012_15-32
0053 %
0054 % ==============
0055 % cam07_frames_p
0056 % missing frames: 0      1   5316   5317   8183   8184  11124  11125
0057 % extra frames: 2649   2650   7945   7946  10769  10770  12994  12995
0058 
0059 if ~exist('save_path', 'var')
0060     save_path = '.';
0061 end
0062 
0063 if ~exist('img_step', 'var')
0064     img_step = 1;
0065 end
0066 
0067 exp_id = unique(round(sub_list/100));
0068 tmp_clock = clock;
0069 tmp_clock_str = sprintf('%d-%d_%d', tmp_clock(2:3), tmp_clock(1));
0070 
0071 summary_file_name = sprintf('frame_check_summary_exp%d_%s.txt', exp_id, tmp_clock_str);
0072 fsummary = fopen(fullfile(save_path, summary_file_name), 'a');
0073 
0074 for sid = 1:length(sub_list)    
0075     sub_id = sub_list(sid);
0076     checking_results(sid).sub_id = sub_id;
0077     % info_file = get_info_file_path(sub_id);
0078     % load info_file
0079     fprintf(fsummary, '%d\n', sub_id);
0080 
0081     trial_frames_sub = get_trials(sub_id);
0082     info_frame_seq = [];
0083     for tidx = 1:size(trial_frames_sub, 1);
0084         tmp_seq = trial_frames_sub(tidx,1):1:trial_frames_sub(tidx,2);
0085         info_frame_seq = [info_frame_seq; tmp_seq'];
0086     end
0087 
0088     sub_dir = get_subject_dir(sub_id);
0089     cam_list = dir(fullfile(sub_dir, '*_frames_p'));  % the list of all cameras
0090     checking_results(sid).cam_list = cam_list;
0091     num_missing_frames = nan(size(cam_list));
0092     num_extra_frames = nan(size(cam_list));
0093     
0094     exist_error_log = false;
0095     tmp_clock = clock;
0096     tmp_clock_str = sprintf('%d-%d_%d_%d-%d', tmp_clock(2:3), tmp_clock(1), tmp_clock(4:5));
0097 
0098     for camid = 1:length(cam_list)
0099         cam_name = cam_list(camid).name;
0100         cam_dir = fullfile(sub_dir, cam_name);
0101 
0102         jpg_list = dir(fullfile(cam_dir, 'img_*.jpg'));
0103         [jpg_list seq_no] = extract_img_name_list(jpg_list, img_step);
0104         sorted_seq = sort(seq_no);
0105 
0106         if length(info_frame_seq) == length(sorted_seq)
0107             is_frame_all_match = sum(info_frame_seq == sorted_seq) == length(sorted_seq);
0108         else
0109             is_frame_all_match = false;
0110         end
0111 
0112         if ~is_frame_all_match
0113             missing_frames = setdiff(info_frame_seq, sorted_seq);
0114             extra_frames = setdiff(sorted_seq, info_frame_seq);
0115             num_missing = length(missing_frames);
0116             num_extra = length(extra_frames);
0117             
0118             if  num_missing > 0
0119                 error_msg_missing = sprintf('subject %d %s missing %d frames\n', sub_id, cam_name, num_missing);
0120                 disp(error_msg_missing);
0121                 fprintf(fsummary, error_msg_missing);
0122             end            
0123             if  num_extra > 0
0124                 error_msg_extra = sprintf('subject %d %s have %d extra frames\n', sub_id, cam_name, num_extra);
0125                 disp(error_msg_extra);
0126                 fprintf(fsummary, error_msg_extra);
0127             end            
0128             
0129             num_missing_frames(camid) = num_missing;
0130             num_extra_frames(camid) = num_extra;
0131 
0132             error_msg_missing = sprintf('missing frames: %s\n', num2str(missing_frames'));
0133             error_msg_extra = sprintf('extra frames: %s\n', num2str(extra_frames'));
0134 
0135             % write error messages to file
0136             error_file_name = sprintf('frame_check_errorlog_%d_%s.txt', sub_id, tmp_clock_str);
0137             fid = fopen(fullfile(save_path, error_file_name), 'a');
0138             
0139             if ~exist_error_log
0140                 fprintf(fid, 'Subject %d\n\nTrial frames:\n', sub_id);
0141                 for tidx = 1:size(trial_frames_sub, 1)
0142                     fprintf(fid, num2str(trial_frames_sub(tidx,:)));
0143                     fprintf(fid, '\n');
0144                 end
0145                 
0146                 fprintf(fid, ['\nChecking time:\n' tmp_clock_str '\n']);
0147                 
0148                 exist_error_log = true;
0149             end
0150             
0151             fprintf(fid, '\n==============\n');
0152             fprintf(fid, [cam_name '\n']);
0153             fprintf(fid, error_msg_missing);
0154             fprintf(fid, error_msg_extra);
0155             fprintf(fid, '\n\n\n');
0156             fclose(fid);
0157         end
0158 
0159         checking_results(sid).num_missing_frames = num_missing_frames;
0160         checking_results(sid).num_extra_frames = num_extra_frames;
0161         fprintf('Checking done for %s for subject %d\n\n', cam_name, sub_id);
0162     end
0163     fprintf(fsummary, '\n\n');
0164 end
0165 fclose(fsummary);

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