%% Simulate interlacing

clear all; clc; clf;
vr = videoReader('../hv30-pf30-clip2.mpg');

%%
seek(vr,165);  image1 = getframe(vr); 
seek(vr,166);  image2 = getframe(vr);  

%%

i1 = image1(460:665,980:1200,:);
i2 = image2(460:665,980:1200,:);

f1=i1; f1(2:2:end,:,:)=255;
f2=i2; f2(1:2:end,:,:)=255;

interlaced = f1;   
interlaced(2:2:end,:,:) = f2(2:2:end,:,:);
imshow(interlaced);

deint = deintTemporalMean(interlaced);

subplot(231); imshow(f1);
subplot(232); imshow(f2);
subplot(233); imshow(interlaced);
subplot(235); imshow(deint);
subplot(236); imshow(i1);
%imshow(imtile({f1;f2;interlaced;deint;i1},10));

%%

imwrite(i1,'../taxi/progressive.png');
imwrite(f1(1:2:end,:,:),'../taxi/top.png');
imwrite(f2(2:2:end,:,:),'../taxi/bottom.png');
imwrite(interlaced,'../taxi/interlaced.png');
imwrite(deint,'../taxi/deinterlaced.png');