'hist_update': update of a current global histogram by inclusion of a new field ------------------------------------------------------------------------ [val,HIST]=hist_update(val,HIST,C,dC) OUTPUT: val: vector of field values at which the histogram is determined (middle of bins) HIST(:,icolor): nbre of occurence of the field value in the bins whose middle is given by val can be a column vector, same size as val, or a matrix with three columns, for color images INPUT: val: existing field values from the current histogram, =[] if there is no current histogram HIST(:,icolor): current histogram, =[] if there is none can be a column vector (icolor=1), same size as val, or a matrix with three columns, for color images C(:,icolor): vector representing the current field values can be a column vector (icolor=1), or a matrix with three columns, for color images dC: width of the new bins extending val to account for the new field.
0001 %'hist_update': update of a current global histogram by inclusion of a new field 0002 %------------------------------------------------------------------------ 0003 %[val,HIST]=hist_update(val,HIST,C,dC) 0004 % 0005 % OUTPUT: 0006 % val: vector of field values at which the histogram is determined (middle of bins) 0007 % HIST(:,icolor): nbre of occurence of the field value in the bins whose middle is given by val 0008 % can be a column vector, same size as val, or a matrix with three columns, for color images 0009 % 0010 % INPUT: 0011 % val: existing field values from the current histogram, =[] if there is no current histogram 0012 % HIST(:,icolor): current histogram, =[] if there is none 0013 % can be a column vector (icolor=1), same size as val, or a matrix with three columns, for color images 0014 % C(:,icolor): vector representing the current field values 0015 % can be a column vector (icolor=1), or a matrix with three columns, for color images 0016 % dC: width of the new bins extending val to account for the new field. 0017 0018 function [val,HIST]=hist_update(val,HIST,C,dC) 0019 0020 valplus=[];valminus=[]; 0021 HISTplus=[];HISTminus=[]; 0022 if isempty(HIST) 0023 HIST=0; 0024 end 0025 siz=size(C);nbfields=siz(2); 0026 C=double(C); 0027 valmin=min(val); 0028 valmax=max(val); 0029 Cmin=min(min(C)); Cmax=max(max(C)); 0030 if isempty(val)%no current histogram 0031 val=[Cmin-dC/2:dC:Cmax+dC/2]; 0032 else %extending the current histogram beyond its maximum value 0033 if Cmax>=valmax+dC/2; 0034 valplus=[valmax+dC:dC:Cmax+dC/2];% we extend the values val 0035 HISTplus=zeros(length(valplus),nbfields);% we put histogram to zero at these values 0036 end 0037 %extending the current histogram below its minimum value 0038 if Cmin<=valmin-dC/2; 0039 valminus=[valmin-dC:-dC:Cmin-dC/2];% we extend the values val 0040 valminus=sort(valminus);% we reverse the order 0041 HISTminus=zeros(length(valminus),nbfields);% we put histogram to zero at these values 0042 end 0043 val=[valminus val valplus]; 0044 end 0045 HIST=[HISTminus;HIST;HISTplus]; 0046 if nbfields==1 0047 histC=(hist(C,val))';% initiate the global histogram 0048 elseif nbfields==3 0049 HIST1=(hist(C(:,1),val))'; 0050 HIST2=(hist(C(:,2),val))'; 0051 HIST3=(hist(C(:,3),val))'; 0052 histC=[HIST1 HIST2 HIST3]; 0053 end 0054 HIST=HIST+histC;