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

% returns matrices of pixel observations in images.

%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 = ParseDataFileLineII(L);
   
   % write first fields of S
   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);
