function [] = consensusFocus(folder,saveloc) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Generates the consensus dataset for the focus annotation. Any frame with 3 %or more people marking it as out of focus is kept as out of focus in the %consensus dataset % Inputs: % - folder: Input string of the folder with the datasets % - saveloc: Save location for the .mat consensus data % Outputs: (none) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% cd(folder) %Assemble the reviewers A = dir('reviewer*'); cd(strcat(A(3).folder, '\', A(3).name)) %Get the datasets matnames = dir('*appliedRegistration.mat') vidDuration = {}; savecons = zeros(length(matnames), 2400, 4); savepass = zeros(length(matnames), 2400, 4); for fn = 1:length(matnames) %go through the videos consensusmat = zeros(2400, 4); for fold = 1:length(A) %Go through the graders and determine which frames have 3 or more %people marking them as out of focus cd(strcat(A(fold).folder, '\', A(fold).name)) checkdir = dir(matnames(fn).name); duration = []; %Generate a framexquadrant check of which frames were labeled as %out of focus if ~isempty(checkdir) load(matnames(fn).name) gradermat = zeros(2400, 4); for period = 1:size(focusTable, 1) for quad = 1:4 if focusTable(period, quad+2) == 1 if focusTable(period, 1) == 0 focusTable(period, 1) = 1; end gradermat(focusTable(period, 1):focusTable(period, 2), quad) = gradermat(focusTable(period, 1):focusTable(period, 2), quad)+1; end end duration = cat(1, duration, focusTable(period, 2)-focusTable(period, 1)); end totaltime(fn, fold) = sum(duration); vidDuration{fn, fold} = duration; gradermat(find(gradermat)) = 1; consensusmat = consensusmat+gradermat; else totaltime(fn, fold) = NaN; end end %Condense consensusmat to a timex1 vector of the times where 3 or more %graders marked a quadrant as out of focus passmat = zeros(size(consensusmat)); savecons(fn, :, :) = consensusmat; passind = find(consensusmat >= 3); passmat(passind) = 1; passvec = sum(passmat, 2); passvec(passvec > 1) = 1; %Identify the start and stop frames for each contiguous set of frames %that are labeled as out of fucs starts = strfind([0 passvec'], [0 1]); ends = strfind([passvec' 0], [1 0]); consensustotal(fn) = sum(passvec); savepass(fn, :, :) = passmat; focusTable = []; %Go through each set of contiguous frames and assemble the table of the appropriate %quadrants as in or out of focus for chunk = 1:length(starts) focind = starts(chunk):ends(chunk); startframe = focind(1); startquad = passmat(focind(1), :); for frame = focind checkquad = passmat(frame, :); if all(startquad == checkquad) endframe = frame; else tabvec = [startframe endframe startquad]; startframe = frame; startquad = checkquad; focusTable = cat(1, focusTable, tabvec); end end tabvec = [startframe frame checkquad]; focusTable = cat(1, focusTable, tabvec); end savename = strcat(saveloc, matnames(fn).name); save(savename, 'focusTable'); end %Plot some sanity checks for the data plot(totaltime*0.05) hold on plot(consensustotal*0.05, 'ko') xlabel('Video number') ylabel('Time (s)') legend({'1', '2', '3', '4', '5', 'Consensus'}) figure order = [2 1 3 4]; for fn = 1:length(matnames) for sp = 1:4 subplot(2, 2, order(sp)) plot(squeeze(savecons(fn, :, sp)), 'b') hold on plot(squeeze(savepass(fn, :, sp))*5, 'k') xlabel('Frame numner') ylabel('Consensus') legend({'Consensus', 'Accepted frames'}) ylim([0 5]) xlim([0 2400]) end altname = strrep(matnames(fn).name, '_', ' '); sgtitle(altname) pause clf end