source: trunk/src/hist_update.m @ 756

Last change on this file since 756 was 19, checked in by gostiaux, 15 years ago

the private files have been moved down to the root folder

File size: 2.2 KB
Line 
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
18function [val,HIST]=hist_update(val,HIST,C,dC)
19
20valplus=[];valminus=[];
21HISTplus=[];HISTminus=[];
22if isempty(HIST)
23    HIST=0;
24end
25siz=size(C);nbfields=siz(2);
26C=double(C);
27valmin=min(val);
28valmax=max(val);
29Cmin=min(min(C)); Cmax=max(max(C));
30if isempty(val)%no current histogram
31    val=[Cmin-dC/2:dC:Cmax+dC/2];
32else %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];
44end
45HIST=[HISTminus;HIST;HISTplus];
46if nbfields==1
47    histC=(hist(C,val))';% initiate the global histogram
48elseif 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];
53end
54HIST=HIST+histC;
Note: See TracBrowser for help on using the repository browser.