function [] = mergeFocusSegmentation(focusfolder, segmentationfolder) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Merges the fields of view for the focus and segmentation videos/data since % the two were taken from different iterations of the registration. Saves % the quadrant focus data to the segmented data into the segmentation folder % Inputs: % - focusfolder: the directory that contains the annotated focus data % - segmentationfolder: the directory that contains the masks % Outputs: (none) % - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% cd(focusfolder) A = dir('*associated.mat'); for fn = 1:length(A) cd(focusfolder) load(A(fn).name, 'maxmove'); focusmax = maxmove; tmove = sum(focusmax(1:3, :)); greenind = strfind(A(fn).name, 'Green')+4; quads = zeros(600, 600); quads = quads(tmove(3)+1:end-tmove(4), tmove(1)+1:end-tmove(2)); [d1, d2] = size(quads); quads(1:floor(d1/2), (floor(d2/2)+1):end) = 1; quads(1:floor(d1/2), 1:floor(d2/2)) = 2; quads((floor(d1/2)+1):end, 1:floor(d2/2)) = 3; quads((floor(d1/2)+1):end, (floor(d2/2)+1):end) = 4; cd(segmentationfolder) B = dir(strcat(A(fn).name(1:greenind), '*associated.mat')); load(B(1).name); segmaxmove = maxmove; C = dir(strcat(A(fn).name(1:greenind), '*projection.tif')); segproj = imread(C(1).name); [quadrants, vid2, ~, focuscrop, segmentationcrop] = convergeMaxMove(quads, segproj, focusmax, segmaxmove); if size(quadrants) ~= size(vid2) break end save(strcat(A(fn).name(1:greenind), '_matchFocusSegmentation.mat'), 'quadrants', 'focuscrop', 'segmentationcrop'); end