function color_hist=get_lab_hist(CC,filename)

global bins min_dist
K=size(bins,1);
% min_dist is the spacing between bin centers (originally 25)

B=max(CC(:));

RGB=imread(filename);
[X,RGBmap]=cmunique(RGB);
if min(X(:))~=1 | max(X(:))~=size(RGBmap,1)
   disp('get_lab_hist: min(X(:))~=1 | max(X(:))~=size(RGBmap,1)')
%   keyboard
end

[X,RGBmap]=imapprox(X,RGBmap,min(2048,size(RGBmap,1)));
LABmap=rgb2lab(RGBmap);

if isa(X,'double') & min(X(:))>=1 & max(X(:))<=size(RGBmap,1)
   color_hist=build_hist(B,K,LABmap,CC,X,bins,min_dist);
elseif isa(X,'uint8') & min(X(:))==0 & max(X(:))<=size(RGBmap,1)-1
   color_hist=build_hist(B,K,LABmap,CC,double(X)+1,bins,min_dist);
elseif isa(X,'uint16') & min(X(:))==0 & max(X(:))<=size(RGBmap,1)-1
   color_hist=build_hist(B,K,LABmap,CC,double(X)+1,bins,min_dist);
elseif isa(X,'uint16') & min(X(:))>=1 & max(X(:))<=size(RGBmap,1)
   color_hist=build_hist(B,K,LABmap,CC,double(X),bins,min_dist);
else
   disp('neither case')
   keyboard
end



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

