function [rock, ice] = ProcessImages(index_file, casefilename)

% [rock, ice] = ProcessImages(index_file, casefilename)
%
% Process all images in index_file, soliciting from user the origin of each image
% and sample 'ice' and 'rock' points.  Saves origins in casefile, and produces matrix
% of observations for 'rock' and 'ice'.  (Each row an observation).  These observations 
% are used to train the segmenter.

% Liam Pedersen, October 1998, FACH C-130 Hercules


%initialize variables etc.

% casefile header labels
label1 = 'IDnum  sample_id  origin_x origin_y';
CaseFileLabels = [label1];

%*****************************************************************
%*****************************************************************

% open CASE file for output.
casefile = OpenCaseFile(casefilename, CaseFileLabels);

% Open INDEX file and process each line
Err = 0; i = 1;
fid = OpenDataFile(index_file, 3);
L = readline(fid);

ice = [];
rock = [];

while (L > 0)
   S = ParseDataFileLine(L);
   
   % write first fields of S
   S.imagefile
   fprintf(casefile,'%d\t', S.idnum);
   fprintf(casefile,'%s\t', S.sample_id);
   
   %****************************
   % Process IMAGE (if possible)
   
   if (S.imagefile(1) ~= '*')
      [rock1, ice1, origin] = GetImagePoints(S.imagefile);

      % update output matrix
      rock = [rock; rock1];
      ice = [ice; ice1];
      
      fprintf(casefile,'%f\t',origin);
   else
      for i = 1:2
         fprintf(casefile,'*  ');
      end
   end
         
   drawnow
   fprintf(casefile,'\n');
   L = readline(fid);
end

% close I/O files
fclose(fid);
fclose(casefile);



%****************************************************************************
%****************************************************************************
% Extract IMAGE PIXEL feature vectors examples

function [rock, ice, origin] = GetImagePoints(imagefile)

% [rock, ice, origin] = GetImagePoints(imagefile)

% read image
im = ReadImage(imagefile);
[rock, ice, origin] = getpoints(im, [5 3]);
