% deinterlaces by selecting lower field
% then crop
%
% lens distortion assumed to be negligible


% Toshiba IKUM42A, with 11mm lens (since 5.5mm lens is quite rectilinear,
%                                  i assume 11mm lens even more so)


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


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

  disp('deinterlacing by deletion (selecting lower field)')
  disp('averageing ajacent pixels each row; assuming image width even')
  R=round((R(1:2:M,1:2:N)+R(1:2:M,2:2:N))/2);
  G=round((G(1:2:M,1:2:N)+G(1:2:M,2:2:N))/2);
  B=round((B(1:2:M,1:2:N)+B(1:2:M,2:2:N))/2);

  %disp('cropping 1 pixel off top and left, and 2 pixels of bottom and right')
  %R=R(2:2+239,2:2+319);
  %G=G(2:2+239,2:2+319);
  %B=B(2:2+239,2:2+319);
  disp('cropping')
  R=R(2:2+239,6:6+309);
  G=G(2:2+239,6:6+309);
  B=B(2:2+239,6:6+309);

  k_out=k; % possibly renumber images if downsampling sequence in time

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

end%for

