Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Gauss.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 
26 #ifndef __Gauss_hh__
27 #define __Gauss_hh__
28 
29 #include "Convolution.hh"
30 
31 #define D_GAUSS_FAST_GREY 0x01
32 
33 namespace BIAS {
34  /** @class Gauss
35  @ingroup g_filter
36  @brief smoothing with gaussian kernel
37 
38  Parameters are sigma and ratio, optionally you can set half window size,
39  which is computed from the other parameters otherwise.
40  The gaussian kernel is separabel, using vector convolution
41  The Gaussian function is truncated, when the ratio between the maximum
42  kernel element and the actual kernel element falls below ratio.
43 
44  If you have a one-channel (typically grey) image, the fast FilterGrey
45  method comes into play, which calls the appropriate fast FilterNxNGrey
46  function according to your sigma and cutoffratio. The fast functions work
47  on the whole image and dont care about the roi in the src image.
48 
49  @author woelk 09/2004, koeser 06/2005 */
50  template <class InputStorageType, class OutputStorageType>
51  class BIASFilter_EXPORT Gauss
52  : public Convolution<InputStorageType, OutputStorageType>
53  {
54  public:
55  Gauss();
57  ~Gauss();
58 
59  /** @brief sets gauss kernel if params changed and calls convolution or
60  fast grey implementation if possible */
61  virtual int Filter(const Image<InputStorageType>& src,
63 
64  /** @brief sets gauss kernel if params changed and calls convolution */
65  virtual int FilterFloat(const Image<InputStorageType>& src,
67 
68  /** @brief sets gauss kernel if params changed and calls convolution */
69  virtual int FilterInt(const Image<InputStorageType>& src,
71 
72  /** @brief wrapper around FilterNxNGrey, which decides on sigma and
73  cutoffratio which filter to apply and how often
74  @param ResetROI reset the roi during filtering
75  @author koeser 06/2005 */
76  virtual int FilterGrey(const Image<InputStorageType>& src,
78  bool ResetROI = false);
79 
80  /** @brief fast, approximate, direct implementation, ignoring wrap-arounds,
81  roi is updated but ignored
82  @author koeser 06/2005 */
83  virtual int Filter3x3Grey(const Image<InputStorageType>& src,
85 
86  /** @brief fast, approximate, direct implementation, ignoring wrap-arounds,
87  roi is updated but ignored
88  @author koeser 06/2005 */
89  virtual int Filter5x5Grey(const Image<InputStorageType>& src,
91 
92  /** @brief fast, approximate, direct implementation, ignoring wrap-arounds,
93  roi is updated but ignored
94  Keep src value of test point if any value under filtermask is below
95  threshold.
96  */
97  virtual int Filter3x3GreyThreshold(const Image<InputStorageType>& src,
99  float threshold = 0.0);
100 
101  /** @brief fast, approximate, direct implementation, ignoring wrap-arounds,
102  roi is updated but ignored.
103  Keep src value of test point if any value under filtermask is below
104  threshold.
105  */
106  virtual int Filter5x5GreyThreshold(const Image<InputStorageType>& src,
108  float threshold = 0.0);
109 
110  /** @brief fast, approximate, direct implementation, ignoring wrap-arounds,
111  roi is updated but ignored
112  @author koeser 06/2005 */
113  virtual int Filter7x7Grey(const Image<InputStorageType>& src,
115 
116 
117  /** @brief fast, approximate, direct implementation, ignoring wrap-arounds,
118  roi is updated but ignored
119  @author koeser 06/2014 */
120  virtual int Filter7x7RGB(const Image<InputStorageType>& src,
122 
123  /** @brief fast, approximate, direct implementation, ignoring wrap-arounds,
124  roi is updated but ignored
125  @author koeser 06/2014 */
126  virtual int Filter7x7RGBA(const Image<InputStorageType>& src,
128 
129 
130  /** @brief 7x7 gauss filtering, values below threshold are ignored
131  useful for depth map filtering
132  @author koeser 04/2007 */
133  int
134  Filter7x7GreyIgnoreBelowThreshold(const Image<InputStorageType>& src,
136  const InputStorageType& thresh);
137 
138 
139  /** @brief fast, approximate, direct implementation, ignoring wrap-arounds,
140  roi is updated but ignored
141  @author koeser 06/2005 */
142  virtual int Filter9x9Grey(const Image<InputStorageType>& src,
144 
145  /** @brief fast, approximate, direct implementation, ignoring wrap-arounds,
146  roi is updated but ignored
147  @author koeser 06/2005 */
148  virtual int Filter11x11Grey(const Image<InputStorageType>& src,
150 
151  /** @brief fast, approximate, direct implementation, ignoring wrap-arounds,
152  roi is updated but ignored
153  @author koeser 06/2005 */
154  virtual int Filter13x13Grey(const Image<InputStorageType>& src,
156 
158  { return new Gauss<InputStorageType, OutputStorageType>(*this); }
159 
160  /////////////////////////////////////////////////////////////////////////
161 
162  inline void SetSigma(const double si) { _GaussSigma=si; }
163 
164  inline double GetSigma() const { return _GaussSigma; }
165 
166  inline void SetRatio(const double ratio) { _GaussRatio=ratio; }
167 
168  inline double GetRatio() const { return _GaussRatio; }
169 
170  /** define the half win size of the kernel, if AdjustSigma is true
171  sigma is computed according to the cut-off ratio, otherwise the ratio
172  is adapted to the sigma */
173  inline void SetHalfWinSize(const int hws, bool AdjustSigma=true)
174  {
175  if (AdjustSigma) {
176  _GaussSigma = sqrt((double)hws*(double)hws/(-2.0*log(_GaussRatio)));
177  } else {
178  _GaussRatio = 0.5*(exp(((double)hws*(double)hws)
179  /(-2.0*(_GaussSigma)*(_GaussSigma)))+
180  exp(((double)(hws+1.0)*(double)(hws+1.0))
181  /(-2.0*(_GaussSigma)*(_GaussSigma)))) ;
182  }
183  }
184 
185 
186  // these are interfaces for class Tracker is Track is instantiated
187  // with out param object
188  double GetSigma(){ return _GaussSigma;};
189  double GetRatio(){ return _GaussRatio;};
190 
191  protected:
192 
193  /// the parameter
194  /// sigma of gaussian kernel
195  double _GaussSigma;
196  /// minimum ratio of 1D kernel center and border, ignore smaller entries
197  double _GaussRatio;
198  // the parameter at the time of the last call of _CalculateKernels
199  // (for caching)
200  double _LastSigma, _LastRatio;
201 
202  /// calculates the kernel
203  void _CalculateKernels(double Sigma, double Ratio);
204 
208 
209  /// to allow for iterated gauss convolution saving the intermediate
210  /// image we need a different instance, this is caused by template concept
213 
214  }; // class
215 
216 } // namespace
217 
218 
219 
220 #endif // __Gauss_hh__
Gauss< InputStorageType, OutputStorageType > * _GaussIO
Definition: Gauss.hh:212
generic convolution class.
Definition: Convolution.hh:66
void SetHalfWinSize(const int hws, bool AdjustSigma=true)
define the half win size of the kernel, if AdjustSigma is true sigma is computed according to the cut...
Definition: Gauss.hh:173
double _GaussRatio
minimum ratio of 1D kernel center and border, ignore smaller entries
Definition: Gauss.hh:197
smoothing with gaussian kernel
Definition: Gauss.hh:51
double GetRatio() const
Definition: Gauss.hh:168
virtual Gauss< InputStorageType, OutputStorageType > * Clone() const
Definition: Gauss.hh:157
double GetRatio()
Definition: Gauss.hh:189
void SetSigma(const double si)
Definition: Gauss.hh:162
Gauss< OutputStorageType, OutputStorageType > * _GaussOO
to allow for iterated gauss convolution saving the intermediate image we need a different instance...
Definition: Gauss.hh:211
void SetRatio(const double ratio)
Definition: Gauss.hh:166
double _LastSigma
Definition: Gauss.hh:200
double GetSigma()
Definition: Gauss.hh:188
double GetSigma() const
Definition: Gauss.hh:164