Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Median1D.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef __Median1D_hh__
26 #define __Median1D_hh__
27 
28 #include <bias_config.h>
29 #include <vector>
30 
31 namespace BIAS
32 {
33  /** @class Median1D
34  @brief Computes the median and p-quantile of a vector.
35  The vectors is stored internally and sorted using std::sort.
36  Hence this class should be used only with basic data types.
37  @note For even vector sizes, the lower median is computed.
38  @ingroup g_mathalgo
39  @author esquivel 11/2013
40  */
41  template <class DataType> class BIASMathAlgo_EXPORT Median1D
42  {
43  public:
44 
45  Median1D() {}
46 
47  ~Median1D() {}
48 
49  /** @brief Compute median and store sorted vector internally. */
50  Median1D(const std::vector<DataType> &vec) { Compute(vec); }
51 
52  /** @brief Compute median and store sorted vector internally. */
53  void Compute(const std::vector<DataType> &vec);
54 
55  /** @brief Return computed median. */
56  inline DataType GetMedian() const { return Median_; }
57 
58  /** @brief Compute and return p-quantile of vector. */
59  DataType GetQuantile(double p) const;
60 
61  /** @brief Return median of absolute differences to median (X84 rule). */
62  inline DataType GetX84() const { return GetX84(Values_, Median_); }
63 
64  /** @brief Return median of absolute differences to median (X84 rule)
65  for given vector without storing it internally. */
66  DataType GetX84(const std::vector<DataType> &vec, DataType median) const;
67 
68  protected:
69 
70  DataType Median_;
71  std::vector<DataType> Values_;
72 
73  };
74 
75 }
76 
77 #endif // __Median1D_hh__
DataType GetMedian() const
Return computed median.
Definition: Median1D.hh:56
DataType GetX84() const
Return median of absolute differences to median (X84 rule).
Definition: Median1D.hh:62
DataType Median_
Definition: Median1D.hh:70
Computes the median and p-quantile of a vector.
Definition: Median1D.hh:41
Median1D(const std::vector< DataType > &vec)
Compute median and store sorted vector internally.
Definition: Median1D.hh:50
std::vector< DataType > Values_
Definition: Median1D.hh:71