% swarp, deinterlace, crop, and downsample image sequence

x = 336.00
y = 274.69
a = 9.826702635e-01
b = 2.333436093e-07
c = -1.157903449e-13

for k = 0:2:372
  dis('********* swarp_and_undsam: doing frame %d',k)
  eval(sprintf('[R G B]=loadpnm(''pic%03d.ppm'');',k))
  [M N]=size(R);
  [Rs Gs Bs] = swarp_ppm(R,G,B,x,y,a,b,c);

  % deinterlace by deletion
  disp('deinterlacing by deletion')
  disp('averageing ajacent pixels each row; assuming image width even')
  R=round((Rs(1:2:M,1:2:N)+Rs(1:2:M,2:2:N))/2);
  G=round((Gs(1:2:M,1:2:N)+Gs(1:2:M,2:2:N))/2);
  B=round((Bs(1:2:M,1:2:N)+Bs(1:2:M,2:2:N))/2);

  disp('cropping')
  R=R(8:8+220,10:10+300);
  G=G(8:8+220,10:10+300);
  B=B(8:8+220,10:10+300);

  k_out=k/2; % since even, renumber images

  eval(sprintf('savepnm(''v%03d.ppm'',R,G,B)',k_out))

end%for

