% deinterlaces and creates two output images for each input image

more off

hak('determine if running this deletes files after downsized: ^c if not sure')

filt=popat_filt;  % generates a 7 tap filter with some "kick"

for k = 0:56
  dis('deinterlace doing frame %d',k)
  eval(sprintf('[R G B]=loadpnm(''images/v%03d.ppm'');',k))

  [M,N] = size(R);

  disp('deinterlacing by deletion (selecting lower field)')
  disp('averageing ajacent pixels each row; assuming image width even')
  % Rout=round((R(2:2:M,1:2:N)+R(2:2:M,2:2:N))/2);
  % Gout=round((G(2:2:M,1:2:N)+G(2:2:M,2:2:N))/2);
  % Bout=round((B(2:2:M,1:2:N)+B(2:2:M,2:2:N))/2);
  Rout=clip255(conv2(ovesambot(R(2:2:M,:)),filt,'same'));
  Gout=clip255(conv2(ovesambot(G(2:2:M,:)),filt,'same'));
  Bout=clip255(conv2(ovesambot(B(2:2:M,:)),filt,'same'));

  eval(sprintf('savepnm(''images/pic%03d.ppm'',Rout,Gout,Bout)',2*k))

  disp('deinterlacing by deletion (selecting upper field)')
  disp('averageing ajacent pixels each row; assuming image width even')
  % Rout=round((R(1:2:M,1:2:N)+R(1:2:M,2:2:N))/2);
  % Gout=round((G(1:2:M,1:2:N)+G(1:2:M,2:2:N))/2);
  % Bout=round((B(1:2:M,1:2:N)+B(1:2:M,2:2:N))/2);
  Rout=clip255(conv2(ovesamtop(R(1:2:M,:)),filt,'same'));
  Gout=clip255(conv2(ovesamtop(G(1:2:M,:)),filt,'same'));
  Bout=clip255(conv2(ovesamtop(B(1:2:M,:)),filt,'same'));

  eval(sprintf('savepnm(''images/pic%03d.ppm'',Rout,Gout,Bout)',2*k+1))

  %% eval(sprintf('!rm v%03d.ppm',k))

end%for
