% deinterlaces and creates two output images for each input image

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

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

  [M,N] = size(R);

  disp('deinterlacing by deletion (selecting upper 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);

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

  disp('deinterlacing by deletion (selecting lower 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);

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

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

end%for

