function [r,c, crow, ccol, pim0] = findpos(fname)
% Usage: [r,c, crow, ccol, image] = findpos(fname)
%    fname: image's filename
%    r: row vector
%    c = column vector
%    crow: row coordinate of center
%    ccol: column coordinate of center
%    image: image 

pause off
echo off
im0=imread(fname); 

num = 6;
cnt = 1;

% adjust threshold until a single object is detected
while ( (num ~= 1) & (cnt ~= 11) )

   bw0=im2bw(im0, (cnt/10.0)*mean2(im0)/255); 
   bw0=not(bw0);
  
   [l,num]=bwlabel(bw0,8); % label the objects
   cnt = cnt+1;

end


if ( num == 1)

  % find rows and columns of object 1

  [r,c]=find(l == 1);

  crow = round(mean(r));
  ccol = round(mean(c));
  pim0=im0;
  pim0((crow-10):(crow+10),ccol)=255;
  pim0(crow,(ccol-10):(ccol+10))=255;
  figure, imshow(pim0);
  
else 
    
  'Could not find the object!'
   r = 0; c = 0; crow= 0; ccol = 0;
   
end 
