[8] | 1 | %'hist_update': update of a current global histogram by inclusion of a new field
|
---|
| 2 | %------------------------------------------------------------------------
|
---|
| 3 | %[val,HIST]=hist_update(val,HIST,C,dC)
|
---|
| 4 | %
|
---|
| 5 | % OUTPUT:
|
---|
| 6 | % val: vector of field values at which the histogram is determined (middle of bins)
|
---|
| 7 | % HIST(:,icolor): nbre of occurence of the field value in the bins whose middle is given by val
|
---|
| 8 | % can be a column vector, same size as val, or a matrix with three columns, for color images
|
---|
| 9 | %
|
---|
| 10 | % INPUT:
|
---|
| 11 | % val: existing field values from the current histogram, =[] if there is no current histogram
|
---|
| 12 | % HIST(:,icolor): current histogram, =[] if there is none
|
---|
| 13 | % can be a column vector (icolor=1), same size as val, or a matrix with three columns, for color images
|
---|
| 14 | % C(:,icolor): vector representing the current field values
|
---|
| 15 | % can be a column vector (icolor=1), or a matrix with three columns, for color images
|
---|
| 16 | % dC: width of the new bins extending val to account for the new field.
|
---|
| 17 |
|
---|
| 18 | function [val,HIST]=hist_update(val,HIST,C,dC)
|
---|
| 19 |
|
---|
| 20 | valplus=[];valminus=[];
|
---|
| 21 | HISTplus=[];HISTminus=[];
|
---|
| 22 | if isempty(HIST)
|
---|
| 23 | HIST=0;
|
---|
| 24 | end
|
---|
| 25 | siz=size(C);nbfields=siz(2);
|
---|
| 26 | C=double(C);
|
---|
| 27 | valmin=min(val);
|
---|
| 28 | valmax=max(val);
|
---|
| 29 | Cmin=min(min(C)); Cmax=max(max(C));
|
---|
| 30 | if isempty(val)%no current histogram
|
---|
| 31 | val=[Cmin-dC/2:dC:Cmax+dC/2];
|
---|
| 32 | else %extending the current histogram beyond its maximum value
|
---|
| 33 | if Cmax>=valmax+dC/2;
|
---|
| 34 | valplus=[valmax+dC:dC:Cmax+dC/2];% we extend the values val
|
---|
| 35 | HISTplus=zeros(length(valplus),nbfields);% we put histogram to zero at these values
|
---|
| 36 | end
|
---|
| 37 | %extending the current histogram below its minimum value
|
---|
| 38 | if Cmin<=valmin-dC/2;
|
---|
| 39 | valminus=[valmin-dC:-dC:Cmin-dC/2];% we extend the values val
|
---|
| 40 | valminus=sort(valminus);% we reverse the order
|
---|
| 41 | HISTminus=zeros(length(valminus),nbfields);% we put histogram to zero at these values
|
---|
| 42 | end
|
---|
| 43 | val=[valminus val valplus];
|
---|
| 44 | end
|
---|
| 45 | HIST=[HISTminus;HIST;HISTplus];
|
---|
| 46 | if nbfields==1
|
---|
| 47 | histC=(hist(C,val))';% initiate the global histogram
|
---|
| 48 | elseif nbfields==3
|
---|
| 49 | HIST1=(hist(C(:,1),val))';
|
---|
| 50 | HIST2=(hist(C(:,2),val))';
|
---|
| 51 | HIST3=(hist(C(:,3),val))';
|
---|
| 52 | histC=[HIST1 HIST2 HIST3];
|
---|
| 53 | end
|
---|
| 54 | HIST=HIST+histC;
|
---|