clear all
% warning off MATLAB:conversionToLogical
warning off

params; % load parameters

size_thresh=0.01;

datapath=DATAPATH;
filelist=fopen(FILELIST,'r');

global bins min_dist actual_centers
load('necessary218.mat','bins');
% was  load('necessary218.mat','bins','min_dist');  in export.tar
% this is OK in Unix, but causes an error in Windows
d=zeros(size(bins,1));
for i=1:size(bins,1)
   for j=1:size(bins,1)
      d(i,j)=sqrt(sum((bins(i,:)-bins(j,:)).^2));
   end
end
d=d(:);      
min_dist=min(d(find(d>0)));
load('bins1244.mat','actual_centers');

datahtml=fopen([datapath 'blobworld_seg.html'],'w');
fprintf(datahtml,'<html><body>\n');

n=0;
while 1
   if feof(filelist), break, end
   imgname=fgetl(filelist);
   if isempty(imgname), break, end

   %YI LI: to process my images
   imgname=[imgname '.s192.ppm'];
   
      fprintf(1,'\n');

     n=n+1;
	 
	 path1=[datapath imgname];
	 path2=[imgname];
	 filename2=[datapath imgname];
	 filename=[IMAGEPATH imgname];
	 
	 %fprintf(1,'%s...\t',imgname);	 
	 
	    fprintf(1,'%s   \tprocessing...\n',imgname);
	    [A,Xdim,con_s,aniso_s,pol_s,phi_s]=features_preprocess(filename);

	    [I,K,Xdim,Ydim,dl_vec,Kvect,restart]=em_mdl(A,Xdim);
	    
	    CC=features_postprocess(I,K,Xdim,Ydim);
	    
	    CCclean=cleanup(CC,filename,Xdim,Ydim,4,2,2);
% YI LI: unused output
% 	    save([path1 '_clean.mat'], 'CCclean','Kvect','dl_vec',...
% 		'Xdim','Ydim','filename','K','restart');
	    make_bd_and_blobworld(CCclean,path1,filename,...
		Xdim,Ydim,size_thresh,con_s,aniso_s,pol_s);
    
    fprintf(datahtml, '<img width=%i height=%i src=%s>', ...
	     Xdim, Ydim, filename);
	 fprintf(datahtml, '<img width=%i height=%i src=%s>', ...
	     Xdim, Ydim, [path2 '_mask.jpeg']);
	 fprintf(datahtml, '<img width=%i height=%i src=%s>', ...
	     Xdim, Ydim, [path2 '_blobworld.jpeg']);
	 fprintf(datahtml, ' K=%i<P>\n', K);
end

fprintf(datahtml,'</body></html>\n');
fclose(datahtml);

fclose(filelist);
disp([int2str(n) ' images.'])



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright (c) 1997-1999. The Regents of the University
% of California (Regents). All Rights Reserved.
% 
% Permission to use, copy, modify, and distribute this software and its
% documentation for educational, research, and not-for-profit purposes,
% without fee and without a signed licensing agreement, is hereby
% granted, provided that the above copyright notice, this paragraph and
% the following two paragraphs appear in all copies, modifications, and
% distributions. Contact The Office of Technology Licensing, UC Berkeley,
% 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, (510)
% 643-7201, for commercial licensing opportunities. Created by
% Chad Carson, Serge Belongie, and Jitendra Malik, Department of Electrical
% Engineering and Computer Sciences, University of California, Berkeley.
% For technical information, contact carson@eecs.berkeley.edu.
% 
% IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
% SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
% ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
% REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
% 
% REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
% PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF
% ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION
% TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
% MODIFICATIONS.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

