source: trunk/src/hist_update.m @ 1093

Last change on this file since 1093 was 1093, checked in by g7moreau, 4 years ago
  • Update Copyright to 2021
File size: 3.1 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
18%=======================================================================
19% Copyright 2008-2021, LEGI UMR 5519 / CNRS UGA 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
36function [val,HIST]=hist_update(val,HIST,C,dC)
37
38valplus=[];valminus=[];
39HISTplus=[];HISTminus=[];
40if isempty(HIST)
41    HIST=0;
42end
43siz=size(C);nbfields=siz(2);
44C=double(C);
45valmin=min(val);
46valmax=max(val);
47Cmin=min(min(C)); Cmax=max(max(C));
48if isempty(val)%no current histogram
49    val=[Cmin-dC/2:dC:Cmax+dC/2];
50else %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];
62end
63HIST=[HISTminus;HIST;HISTplus];
64if nbfields==1
65    histC=(hist(C,val))';% initiate the global histogram
66elseif 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];
71end
72HIST=HIST+histC;
Note: See TracBrowser for help on using the repository browser.