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 | %=======================================================================
|
---|
19 | % Copyright 2008-2015, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
|
---|
20 | % http://www.legi.grenoble-inp.fr
|
---|
21 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
|
---|
22 | %
|
---|
23 | % This file is part of the toolbox UVMAT.
|
---|
24 | %
|
---|
25 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
26 | % it under the terms of the GNU General Public License as published
|
---|
27 | % by the Free Software Foundation; either version 2 of the license,
|
---|
28 | % or (at your option) any later version.
|
---|
29 | %
|
---|
30 | % UVMAT is distributed in the hope that it will be useful,
|
---|
31 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
32 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
33 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
34 | %=======================================================================
|
---|
35 |
|
---|
36 | function [val,HIST]=hist_update(val,HIST,C,dC)
|
---|
37 |
|
---|
38 | valplus=[];valminus=[];
|
---|
39 | HISTplus=[];HISTminus=[];
|
---|
40 | if isempty(HIST)
|
---|
41 | HIST=0;
|
---|
42 | end
|
---|
43 | siz=size(C);nbfields=siz(2);
|
---|
44 | C=double(C);
|
---|
45 | valmin=min(val);
|
---|
46 | valmax=max(val);
|
---|
47 | Cmin=min(min(C)); Cmax=max(max(C));
|
---|
48 | if isempty(val)%no current histogram
|
---|
49 | val=[Cmin-dC/2:dC:Cmax+dC/2];
|
---|
50 | else %extending the current histogram beyond its maximum value
|
---|
51 | if Cmax>=valmax+dC/2;
|
---|
52 | valplus=[valmax+dC:dC:Cmax+dC/2];% we extend the values val
|
---|
53 | HISTplus=zeros(length(valplus),nbfields);% we put histogram to zero at these values
|
---|
54 | end
|
---|
55 | %extending the current histogram below its minimum value
|
---|
56 | if Cmin<=valmin-dC/2;
|
---|
57 | valminus=[valmin-dC:-dC:Cmin-dC/2];% we extend the values val
|
---|
58 | valminus=sort(valminus);% we reverse the order
|
---|
59 | HISTminus=zeros(length(valminus),nbfields);% we put histogram to zero at these values
|
---|
60 | end
|
---|
61 | val=[valminus val valplus];
|
---|
62 | end
|
---|
63 | HIST=[HISTminus;HIST;HISTplus];
|
---|
64 | if nbfields==1
|
---|
65 | histC=(hist(C,val))';% initiate the global histogram
|
---|
66 | elseif nbfields==3
|
---|
67 | HIST1=(hist(C(:,1),val))';
|
---|
68 | HIST2=(hist(C(:,2),val))';
|
---|
69 | HIST3=(hist(C(:,3),val))';
|
---|
70 | histC=[HIST1 HIST2 HIST3];
|
---|
71 | end
|
---|
72 | HIST=HIST+histC;
|
---|