% octave function loadframe.m
% loads image from dataset of pictures i took of soldier's tower
%
% Use: f1=loadframesmall(1); % converts to grey and loads first small frame
%    : [r2 g2 b2]=loadframesmall(2); % loads second frame in sequence

function [R, G, B] = loadframesmall(k);

%filename = sprintf("s%03d.jpg",k);
%if k<100
% filename = sprintf("r%03d.jpg",k);
%end%if
%if k>=100
% filename = sprintf("v%03d.jpg",k);
%end%if
filename=sprintf('s%03d.jpg',k);
if nargin ~=1
  error('loadframe: must have 1 input argument k')
end%if nargin
if nargout~=3
  if nargout ~= 1
    error('loadframe: must have 1 or 3 output arguments (Y or R, G, B)')
  end%if nargout
end%if nargout

if nargout == 3
  commandstr=['djpeg ' filename ' > deleteme_deleteme_loadframe.ppm'];
  %ans = djpeg s001.jpg > deleteme_deleteme_loadframe.ppm
  systemstr=['system(""" commandstr """)'];
  %ans = system("djpeg v001.jpg > deleteme_deleteme_loadframe.ppm")
  eval(systemstr);
  [R G B] = loadpnm('deleteme_deleteme_loadframe.ppm');
end%if
if nargout == 1
  commandstr=['djpeg -grey ' filename ' > deleteme_deleteme_loadframe.pgm'];
  systemstr=['system(""" commandstr """)'];
  eval(systemstr);
  R = loadpnm('deleteme_deleteme_loadframe.pgm');
end%if

