function [IFV, err] = ProcessImage(imagefile,origin,scale,rock_features,ice_features,invFeatureCov,Pxx,Pox)

% Loads image and return feature vector, if possible.
% cf ImageFeatureVector for documentation.
%
% returns err = -1 if failure.

plotimage = 1;
getorigin = 0;

if (imagefile(1) == '*')
   err = 1;
   IFV = -1;
   return;
end

% read image
[im, err] = ReadImage(imagefile);

if (err)
   disp(['Cannot process image ' imagefile]);
   IFV = -1;
   return
end

if (origin(1) < 0 | origin(2) < 0)
   getorigin = 1;
end

if (plotimage | getorigin) 
   clf;
   image(im);
   title(imagefile);
 %  hold on
 %  plot(origin(1),origin(2),'r*');
 %  drawnow
 %  hold off
 %  pause
   
   if (getorigin)
		[x, y] = ginput(1);
      origin = round([x y]);
   end
   hold on
   plot(origin(1), origin(2), 'r*');
end

IFV=ImageFeatureVector(im,origin,scale,rock_features,ice_features,invFeatureCov,Pxx,Pox);
