function [vid1, vid2, nmaxmove, crop1, crop2] = convergeMaxMove(ivid1, ivid2, maxmove1, maxmove2) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Crops two videos that have been registered with iterative registration to %a view that merges the two registration coordinates % Inputs: % - ivid1: Input video from the first registration % - ivid2: Input video from the second registration % - maxmove1: The cropping values used to generate the first % video % - maxmove2: The cropping values used to generate the second video % Output: % - vid1: The first input video converted to the merged field of view % - vid2: The second input video converted to the merged field of view % - nmaxmove: The cropping matrix that should be used on the original % uncropped data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% vid1 = ivid1; vid2 = ivid2; dvid1 = size(vid1); dvid2 = size(vid2); m1 = sum(maxmove1(1:end-1, :),1); m2 = sum(maxmove2(1:end-1, :),1); %Identify where cropping for video 1 is larger than video 2 and vice verse mdiff = m1-m2; nchange1 = [1 dvid1(2) 1 dvid1(1)]; nchange2 = [1 dvid2(2) 1 dvid2(1)]; m1ind = find(mdiff < 0); m2ind = find(mdiff > 0); %Use the difference in cropped values to determine how much more to crop %from each video so that they're in the same field of view nmaxmove = m1; nmaxmove(m1ind) = m2(m1ind); m1d = abs(mdiff); m2d = abs(mdiff); m1d(m2ind) = 0; m2d(m1ind) = 0; m1d([2 4]) = -m1d([2 4]); m2d([2 4]) = -m2d([2 4]); nchange1 = nchange1+m1d; nchange2= nchange2+m2d; crop1 = nchange1; crop2 = nchange2; vid1 = vid1(crop1(3):crop1(4), crop1(1):crop1(2), :); vid2 = vid2(crop2(3):crop2(4), crop2(1):crop2(2), :); end