function process2()

%addResult4UpFullPathStatic('Bathroom.mp4', 'Bathroom/');

addResult4UpFullPathDish('Dishwasher.mp4', 'Dishwasher/');
addResult4UpFullPath('DinoPear.mp4', 'DinoPear/');
addResult4UpFullPathFreeze('DinoPearFreeze.mp4', 'DinoPear/');
addResult4UpFullPathStatic('Bedroom.mp4', 'Bedroom/');

%addResult4UpFullPathD('teaser.mp4', 'PhoneBooth/input_rgb.mp4', 'Color (input)', 'PhoneBooth/input_tof.mp4', 'Depth (input)', 'PhoneBooth/torf_rgb.mp4', 'TöRF RGB (Ours)','PhoneBooth/torf_depth.mp4', 'TöRF Depth (Ours)')
%addResult3UpFullPath('output1.mp4', 'Photocopier/input_tof.mp4', 'Depth errors from phase wrapping', 'Photocopier/torf_depth.mp4', 'Ours: Reduced errors', 'Photocopier/videonerf_depth.mp4', 'Incorrect depth propagating in VideoNeRF')
%addResult2UpFullPath('output2.mp4', 'DeskBox/input_tof.mp4', 'Depth errors from low reflectance', 'DeskBox/torf_depth.mp4', 'Ours: Reduced errors');
%addResult2UpFullPath('output3.mp4', 'Cupboard/input_tof.mp4', 'Depth errors from multi-path interference', 'Cupboard/torf_depth.mp4', 'Ours: Robust to multi-path interference');
%addResult4UpFullPath('PhoneBooth.mp4', 'PhoneBooth/');
%addResult4UpFullPathFreeze('PhoneBoothFreeze.mp4', 'PhoneBooth/');
%addResult4UpFullPath('Cupboard.mp4', 'Cupboard/');
%addResult4UpFullPathFreeze('CupboardFreeze.mp4', 'Cupboard/');
%addResult4UpFullPath('Photocopier.mp4', 'Photocopier/');
%addResult4UpFullPathFreeze('PhotocopierFreeze.mp4', 'Photocopier/');
%addResult4UpFullPath('DeskBox.mp4', 'DeskBox/');
%addResult4UpFullPathFreeze('DeskBoxFreeze.mp4', 'DeskBox/');
%addResult4UpFullPath('StudyBook.mp4', 'StudyBook/');
%addResult4UpFullPathFreeze('StudyBookFreeze.mp4', 'StudyBook/');

end


function addResult2UpFullPath(out1, fn1, txt1, fn2, txt2)
reader1 = VideoReader(fn1);
reader2 = VideoReader(fn2);
writer = VideoWriter(out1,'MPEG-4');

writer.FrameRate = reader2.FrameRate;
writer.Quality = 50;
open(writer);

itr = 0;

while hasFrame(reader2)
   if (iseven(itr))
       img1 = resizeImg(reader1);
       img1 = padarray(img1,[20 5],255);
       img1 = insertText(img1,[5, 0],txt1,'FontSize',15,'BoxColor',...
        'white','BoxOpacity',0,'TextColor','black');
   end
   img2 = resizeImg(reader2);
   img2 = padarray(img2,[20 5],255);
   img2 = insertText(img2,[5, 0],txt2,'FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   img = cat(2,img1,img2);
   img = img(1:end-14,:,:);
   writeVideo(writer,img);
   
   itr = itr + 1;
end

close(writer);
end

function addResult3UpFullPath(out1, fn1, txt1, fn2, txt2, fn3, txt3)
reader1 = VideoReader(fn1);
reader2 = VideoReader(fn2);
reader3 = VideoReader(fn3);
writer = VideoWriter(out1,'MPEG-4');

writer.FrameRate = reader2.FrameRate;
writer.Quality = 50;
open(writer);

itr = 0;

while hasFrame(reader2)
    if (iseven(itr))
       img1 = resizeImg(reader1);
       img1 = padarray(img1,[20 5],255);
       img1 = insertText(img1,[5, 0],txt1,'FontSize',15,'BoxColor',...
        'white','BoxOpacity',0,'TextColor','black');
    end
   img2 = resizeImg(reader2);
   img2 = padarray(img2,[20 5],255);
   img2 = insertText(img2,[5, 0],txt2,'FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   img3 = resizeImg(reader3);
   img3 = padarray(img3,[20 5],255);
   img3 = insertText(img3,[5, 0],txt3,'FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   img = cat(2,img1,img2,img3);
   img = img(1:end-14,:,:);
   writeVideo(writer,img);
   
   itr = itr + 1;
end

close(writer);
end

function addResult4UpFullPathD(out1, fn1, txt1, fn2, txt2, fn3, txt3, fn4, txt4)
reader1 = VideoReader(fn1);
reader2 = VideoReader(fn2);
reader3 = VideoReader(fn3);
reader4 = VideoReader(fn4);
writer = VideoWriter(out1,'MPEG-4');

writer.FrameRate = 2*reader2.FrameRate;
writer.Quality = 50;
open(writer);

itr = 0;

while hasFrame(reader2)
    if (iseven(itr))
       img1 = resizeImg(reader1);
       img1 = padarray(img1,[20 5],255);
       img1 = insertText(img1,[5, 0],txt1,'FontSize',15,'BoxColor',...
        'white','BoxOpacity',0,'TextColor','black');
    end
    if (iseven(itr))
   img2 = resizeImg(reader2);
   img2 = padarray(img2,[20 5],255);
   img2 = insertText(img2,[5, 0],txt2,'FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
    end
   img3 = resizeImg(reader3);
   img3 = padarray(img3,[20 5],255);
   img3 = insertText(img3,[5, 0],txt3,'FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   img4 = resizeImg(reader4);
   img4 = padarray(img4,[20 5],255);
   img4 = insertText(img4,[5, 0],txt4,'FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   img = cat(2,img1,img2,img3,img4);
   img = img(1:end-14,:,:);
   writeVideo(writer,img);
   
   itr = itr + 1;
end

close(writer);
end

function addResult4UpFullPathFreeze(out1, fn1)
reader1 = VideoReader(strcat(fn1, 'input_rgb.mp4'));
reader2 = VideoReader(strcat(fn1, 'torf_rgb_freezeframe.mp4'));
reader3 = VideoReader(strcat(fn1, 'videonerf_rgb_freezeframe.mp4'));
reader4 = VideoReader(strcat(fn1, 'nsff_rgb_freezeframe.mp4'));
reader5 = VideoReader(strcat(fn1, 'input_tof.mp4'));
reader6 = VideoReader(strcat(fn1, 'torf_depth_freezeframe.mp4'));
reader7 = VideoReader(strcat(fn1, 'videonerf_depth_freezeframe.mp4'));
reader8 = VideoReader(strcat(fn1, 'nsff_depth_freezeframe.mp4'));
writer = VideoWriter(out1,'MPEG-4');

writer.FrameRate = reader2.FrameRate;
writer.Quality = 50;
open(writer);

itr = 0;

while hasFrame(reader2)
    if (itr == 0)
       for k = 1:15
        img1 = resizeImg(reader1);
       end
       frm = img1;
    else
       img1 = frm;
    end
    img1 = padarray(img1,[20 5],255);
    img1 = insertText(img1,[5, 0],'Input RGB','FontSize',15,'BoxColor',...
        'white','BoxOpacity',0,'TextColor','black');
    if (hasFrame(reader2))
        img2 = resizeImg(reader2);
    else
        img2 = 0.*frm;
    end
   img2 = padarray(img2,[20 5],255);
   img2 = insertText(img2,[5, 0],'TöRF RGB (Ours)','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   if (hasFrame(reader3))
        img3 = resizeImg(reader3);
        %img3 = imresize(img3,0.5);
    else
        img3 = 0.*frm;
   end
   img3 = padarray(img3,[20 5],255);
   img3 = insertText(img3,[5, 0],'VideoNeRF RGB','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   if (hasFrame(reader4))
        img4 = resizeImg(reader4);
    else
        img4 = 0.*frm;
    end
   img4 = padarray(img4,[20 5],255);
   img4 = insertText(img4,[5, 0],'NSFF RGB','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');

size(img1)
size(img2)
size(img3)
size(img4)
   img = cat(2,img1,img2,img3,img4);
   img_top = img(1:end-14,:,:);
   
   if (itr == 0)
       for k = 1:15
       img1 = resizeImg(reader5);
       end
       frm2 = img1;
   else
       img1 = frm2;
   end
   img1 = padarray(img1,[20 5],255);
   img1 = insertText(img1,[5, 0],'Input Derived Time-of-Flight Depth','FontSize',15,'BoxColor',...
        'white','BoxOpacity',0,'TextColor','black');
    if (hasFrame(reader6))
        img2 = resizeImg(reader6);
    else
        img2 = 0.*frm;
    end
   img2 = padarray(img2,[20 5],255);
   img2 = insertText(img2,[5, 0],'TöRF Depth (Ours)','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   if (hasFrame(reader7))
        img3 = resizeImg(reader7);
    else
        img3 = 0.*frm;
   end
   img3 = padarray(img3,[20 5],255);
   img3 = insertText(img3,[5, 0],'VideoNeRF Depth','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   if (hasFrame(reader8))
        img4 = resizeImg(reader8);
    else
        img4 = 0.*frm;
    end
   img4 = padarray(img4,[20 5],255);
   img4 = insertText(img4,[5, 0],'NSFF Depth','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
size(img1)
size(img2)
size(img3)
size(img4)
   img = cat(2,img1,img2,img3,img4);
   img_bottom = img(1:end-14,:,:);
   
   writeVideo(writer,cat(1,img_top,img_bottom));
   
   itr = itr + 1;
end

close(writer);
end

function addResult4UpFullPath(out1, fn1)
reader1 = VideoReader(strcat(fn1, 'input_rgb.mp4'));
reader2 = VideoReader(strcat(fn1, 'torf_rgb.mp4'));
reader3 = VideoReader(strcat(fn1, 'videonerf_rgb.mp4'));
reader4 = VideoReader(strcat(fn1, 'nsff_rgb.mp4'));
reader5 = VideoReader(strcat(fn1, 'input_tof.mp4'));
reader6 = VideoReader(strcat(fn1, 'torf_depth.mp4'));
reader7 = VideoReader(strcat(fn1, 'videonerf_depth.mp4'));
reader8 = VideoReader(strcat(fn1, 'nsff_depth.mp4'));
writer = VideoWriter(out1,'MPEG-4');

writer.FrameRate = reader2.FrameRate;
writer.Quality = 50;
open(writer);

itr = 0;

while hasFrame(reader2)
    if (iseven(itr))
       img1 = resizeImg(reader1);
       frm = img1;
    else
       img1 = frm;
    end
    img1 = padarray(img1,[20 5],255);
    img1 = insertText(img1,[5, 0],'Input RGB','FontSize',15,'BoxColor',...
        'white','BoxOpacity',0,'TextColor','black');
    if (hasFrame(reader2))
        img2 = resizeImg(reader2);
    else
        img2 = 0.*frm;
    end
   img2 = padarray(img2,[20 5],255);
   img2 = insertText(img2,[5, 0],'TöRF RGB (Ours)','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   if (hasFrame(reader3))
        img3 = resizeImg(reader3);
        %img3 = imresize(img3,0.5);
    else
        img3 = 0.*frm;
   end
   img3 = padarray(img3,[20 5],255);
   img3 = insertText(img3,[5, 0],'VideoNeRF RGB','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   if (hasFrame(reader4))
        img4 = resizeImg(reader4);
    else
        img4 = 0.*frm;
    end
   img4 = padarray(img4,[20 5],255);
   img4 = insertText(img4,[5, 0],'NSFF RGB','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');

size(img1)
size(img2)
size(img3)
size(img4)
   img = cat(2,img1,img2,img3,img4);
   img_top = img(1:end-14,:,:);
   
   if (iseven(itr))
       img1 = resizeImg(reader5);
       frm2 = img1;
   else
       img1 = frm2;
   end
   img1 = padarray(img1,[20 5],255);
   img1 = insertText(img1,[5, 0],'Input Derived Time-of-Flight Depth','FontSize',15,'BoxColor',...
        'white','BoxOpacity',0,'TextColor','black');
    if (hasFrame(reader6))
        img2 = resizeImg(reader6);
    else
        img2 = 0.*frm;
    end
   img2 = padarray(img2,[20 5],255);
   img2 = insertText(img2,[5, 0],'TöRF Depth (Ours)','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   if (hasFrame(reader7))
        img3 = resizeImg(reader7);
    else
        img3 = 0.*frm;
   end
   img3 = padarray(img3,[20 5],255);
   img3 = insertText(img3,[5, 0],'VideoNeRF Depth','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   if (hasFrame(reader8))
        img4 = resizeImg(reader8);
    else
        img4 = 0.*frm;
    end
   img4 = padarray(img4,[20 5],255);
   img4 = insertText(img4,[5, 0],'NSFF Depth','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
size(img1)
size(img2)
size(img3)
size(img4)
   img = cat(2,img1,img2,img3,img4);
   img_bottom = img(1:end-14,:,:);
   
   writeVideo(writer,cat(1,img_top,img_bottom));
   
   itr = itr + 1;
end

close(writer);
end

function addResult4UpFullPathStatic(out1, fn1)
reader1 = VideoReader(strcat(fn1, 'nerf_rgb_2views.mp4'));
reader2 = VideoReader(strcat(fn1, 'nerf_depth_2views.mp4'));
reader3 = VideoReader(strcat(fn1, 'torf_rgb_2views.mp4'));
reader4 = VideoReader(strcat(fn1, 'torf_depth_2views.mp4'));
reader5 = VideoReader(strcat(fn1, 'nerf_rgb_4views.mp4'));
reader6 = VideoReader(strcat(fn1, 'nerf_depth_4views.mp4'));
reader7 = VideoReader(strcat(fn1, 'torf_rgb_4views.mp4'));
reader8 = VideoReader(strcat(fn1, 'torf_depth_4views.mp4'));
writer = VideoWriter(out1,'MPEG-4');

writer.FrameRate = reader2.FrameRate;
writer.Quality = 50;
open(writer);

itr = 0;

while hasFrame(reader2)
    if (1)
       img1 = resizeImg(reader1);
       frm = img1;
    else
       img1 = frm;
    end
    img1 = padarray(img1,[20 5],255);
    img1 = insertText(img1,[5, 0],'NeRF RGB (2 views)','FontSize',15,'BoxColor',...
        'white','BoxOpacity',0,'TextColor','black');
    if (hasFrame(reader2))
        img2 = resizeImg(reader2);
    else
        img2 = 0.*frm;
    end
   img2 = padarray(img2,[20 5],255);
   img2 = insertText(img2,[5, 0],'NeRF Depth (2 views)','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   if (hasFrame(reader3))
        img3 = resizeImg(reader3);
        %img3 = imresize(img3,0.5);
    else
        img3 = 0.*frm;
   end
   img3 = padarray(img3,[20 5],255);
   img3 = insertText(img3,[5, 0],'TöRF RGB (Ours; 2 views)','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   if (hasFrame(reader4))
        img4 = resizeImg(reader4);
    else
        img4 = 0.*frm;
    end
   img4 = padarray(img4,[20 5],255);
   img4 = insertText(img4,[5, 0],'TöRF Depth (Ours; 2 views)','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');

size(img1)
size(img2)
size(img3)
size(img4)
   img = cat(2,img1,img2,img3,img4);
   img_top = img(1:end-14,:,:);
   
   if (1)
       img1 = resizeImg(reader5);
       frm2 = img1;
   else
       img1 = frm2;
   end
   img1 = padarray(img1,[20 5],255);
   img1 = insertText(img1,[5, 0],'NeRF RGB (4 views)','FontSize',15,'BoxColor',...
        'white','BoxOpacity',0,'TextColor','black');
    if (hasFrame(reader6))
        img2 = resizeImg(reader6);
    else
        img2 = 0.*frm;
    end
   img2 = padarray(img2,[20 5],255);
   img2 = insertText(img2,[5, 0],'NeRF Depth (4 views)','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   if (hasFrame(reader7))
        img3 = resizeImg(reader7);
    else
        img3 = 0.*frm;
   end
   img3 = padarray(img3,[20 5],255);
   img3 = insertText(img3,[5, 0],'TöRF RGB (Ours; 4 views)','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   if (hasFrame(reader8))
        img4 = resizeImg(reader8);
    else
        img4 = 0.*frm;
    end
   img4 = padarray(img4,[20 5],255);
   img4 = insertText(img4,[5, 0],'TöRF Depth (Ours; 4 views)','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
size(img1)
size(img2)
size(img3)
size(img4)
   img = cat(2,img1,img2,img3,img4);
   img_bottom = img(1:end-14,:,:);
   
   writeVideo(writer,cat(1,img_top,img_bottom));
   
   itr = itr + 1;
end

close(writer);
end

function addResult4UpFullPathDish(out1, fn1)
reader1 = VideoReader(strcat(fn1, 'input_rgb.mp4'));
reader2 = VideoReader(strcat(fn1, 'torf_rgb.mp4'));
reader3 = VideoReader(strcat(fn1, 'videonerf_rgb.mp4'));
reader4 = VideoReader(strcat(fn1, 'nsff_rgb.mp4'));
reader5 = VideoReader(strcat(fn1, 'input_depth.mp4'));
reader6 = VideoReader(strcat(fn1, 'torf_depth.mp4'));
reader7 = VideoReader(strcat(fn1, 'videonerf_depth.mp4'));
reader8 = VideoReader(strcat(fn1, 'nsff_depth.mp4'));
writer = VideoWriter(out1,'MPEG-4');

writer.FrameRate = reader2.FrameRate;
writer.Quality = 50;
open(writer);

itr = 0;

while hasFrame(reader2)
    if (iseven(itr))
       img1 = resizeImg(reader1);
       frm = img1;
    else
       img1 = frm;
    end
    img1 = padarray(img1,[20 5],255);
    img1 = insertText(img1,[5, 0],'Input RGB','FontSize',15,'BoxColor',...
        'white','BoxOpacity',0,'TextColor','black');
    if (hasFrame(reader2))
        img2 = resizeImg(reader2);
    else
        img2 = 0.*frm;
    end
   img2 = padarray(img2,[20 5],255);
   img2 = insertText(img2,[5, 0],'TöRF RGB (Ours)','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   if (hasFrame(reader3))
        img3 = resizeImg(reader3);
        %img3 = imresize(img3,0.5);
    else
        img3 = 0.*frm;
   end
   img3 = padarray(img3,[20 5],255);
   img3 = insertText(img3,[5, 0],'VideoNeRF RGB','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   if (hasFrame(reader4))
        img4 = resizeImg(reader4);
    else
        img4 = 0.*frm;
    end
   img4 = padarray(img4,[20 5],255);
   img4 = insertText(img4,[5, 0],'NSFF RGB','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');

size(img1)
size(img2)
size(img3)
size(img4)
   img = cat(2,img1,img2,img3,img4);
   img_top = img(1:end-14,:,:);
   
   if (iseven(itr))
       img1 = resizeImg(reader5);
       frm2 = img1;
   else
       img1 = frm2;
   end
   img1 = padarray(img1,[20 5],255);
   img1 = insertText(img1,[5, 0],'Input Derived Time-of-Flight Depth','FontSize',15,'BoxColor',...
        'white','BoxOpacity',0,'TextColor','black');
    if (hasFrame(reader6))
        img2 = resizeImg(reader6);
    else
        img2 = 0.*frm;
    end
   img2 = padarray(img2,[20 5],255);
   img2 = insertText(img2,[5, 0],'TöRF Depth (Ours)','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   if (hasFrame(reader7))
        img3 = resizeImg(reader7);
    else
        img3 = 0.*frm;
   end
   img3 = padarray(img3,[20 5],255);
   img3 = insertText(img3,[5, 0],'VideoNeRF Depth','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
   if (hasFrame(reader8))
        img4 = resizeImg(reader8);
    else
        img4 = 0.*frm;
    end
   img4 = padarray(img4,[20 5],255);
   img4 = insertText(img4,[5, 0],'NSFF Depth','FontSize',15,'BoxColor',...
    'white','BoxOpacity',0,'TextColor','black');
size(img1)
size(img2)
size(img3)
size(img4)
   img = cat(2,img1,img2,img3,img4);
   img_bottom = img(1:end-14,:,:);
   
   writeVideo(writer,cat(1,img_top,img_bottom));
   
   itr = itr + 1;
end

close(writer);
end

function img = resizeImg(frame)
    img = readFrame(frame);
    img = imresize(img, [240 320]);
    %sz = size(img);
    %sz
    %tmp = imresize(img, [240 sz(2).*240./sz(1)  ]);
    %img = zeros(240,320,3);
    %floor((320-size(tmp,2))./2)
    %img(:,floor((320-size(tmp,2))./2)+(1:size(tmp,2)),:) = tmp;
    %img = uint8(img);
end