Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FilterBase.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 __FilterBase_hh__
27 #define __FilterBase_hh__
28 
29 #include <Base/Image/Image.hh>
30 
31 #include <string>
32 #include <vector>
33 
34 #define D_FILTERBASE_CALLSTACK 0x80000000
35 
36 namespace BIAS {
37 
38  /** @enum EGradType
39  @brief different gradients to be used by hiogher level classes
40  - GT_Sobel3x3 gradient using 3x3 sobelx and sobely filters
41  - GT_Gauss gradient using derivatives of gauss with square kernel
42  - GT_GaussAsymmetric gradient using derivatives of gauss */
44 
45  /** @enum LowPassType
46  @brief determines which lowpass filter is used before subsampling
47  - LPT_Mean use non-weighted mean across a window
48  - LPT_Gauss weight (in a window) with gaussian function
49  - LPT_GaussThreshold same as Gauss but does not concerne values
50  under a specified threshold */
53 
54  /** @class FilterBase
55  * @test TestFilterBase.hh
56  @ingroup g_filter
57  @brief virtual parent class for API definition of all (future) filters
58 
59  We would like to have a general (abstract) class FilterBase,
60  which should be located in BIAS/Filter and which has the main function
61  Filter(inputimage, outputimage).
62  This enforces all our filters to have a common interface.
63  Derived from that, we have Convolution, Gauss, Median, ...
64  To keep the interface clean and exchangable, all Filters should be
65  derived from FilterBase and be usable with the standard interface.
66  The standard function checks the desired properties of the Kernel and
67  behaves accordingly,
68  i.e. may call the optimized subroutines, e.g. FastSobel3x3.
69  These subroutines may also be directly called if the user knows
70  exactly which implementation he wants.
71  FilterBase also holds an enum for the output size,
72  such as "full", "same" or "valid".
73 
74  @author skoglund, koeser, woelk 11/2004 */
75 
76  template <class InputStorageType, class OutputStorageType>
77  class BIASFilter_EXPORT FilterBase : public Debug
78  {
79 
80  public:
81  /** enum for border calculation, same meanings as in matlab:
82  - TBH_valid: returns only the pixels whose values can be computed
83  without using zero padding of the input image. The
84  resulting output image is smaller than the input image.
85  The ROI of the output image is set accordingly.
86  - TBH_same: returns the set of pixels that can be computed by applying
87  the filter to all pixels that are actually part of the
88  input image. Border pixels are computed using zero
89  padding, but the center pixel of the computational kernel
90  is applied only to pixels in the image. This results in an
91  output image that is the same size as the input image.
92  - TBH_full: returns the full convolution. This means conv2 returns all
93  pixels for which any of the pixels in the computational
94  molecule overlap pixels in the image, even when the center
95  pixel is outside the input image. The resulting output
96  image is larger than the input image. This is not
97  implemented at the moment. */
98  enum TBorderHandling { TBH_full, TBH_same, TBH_valid };
99 
100  FilterBase();
102  virtual ~FilterBase();
103 
104  /// prototyp for filter computation function
105  virtual int Filter(const Image<InputStorageType>& src,
106  Image<OutputStorageType>& dst) = 0;
107 
108  void GetBorders(int& border_x, int& border_y) const;
109 
110 
111  /** @brief run over all pixel which do not belong to the roi and set them
112  to some value (typically black)
113  @author koeser 12/2008 */
114  void SetNonROIToValue(Image<OutputStorageType>& dst,
115  const std::vector<OutputStorageType>& t) const;
116 
117  /** @brief run over all pixel which do not belong to the roi and set them
118  to the value in the source image regardless of the roi of the source.
119  Both images must have same size.
120  @author koeser 12/2008 */
121  void CopyNonROIFromSource(const Image<InputStorageType>& src,
122  Image<OutputStorageType>& dst) const;
123 
124 
125  /////////////////////////////////////////////////////////////////////////
126 
127  inline void SetBorderHandling(const int bh) { _FilterBorderHandling=bh; }
128 
129  inline int GetBorderHandling() const { return _FilterBorderHandling; }
130 
131  protected:
132  int _FilterBorderHandling; // defaults to valid
133 
134  virtual void GetBordersValid_(int& border_x, int& border_y) const = 0;
135 
136  }; // class
137 
138 
139 
140 
141 } // namespace
142 
143 
144 
145 #endif // __FilterBase_hh__
LowPassType
determines which lowpass filter is used before subsampling
Definition: FilterBase.hh:51
virtual parent class for API definition of all (future) filters
Definition: FilterBase.hh:77
EGradType
different gradients to be used by hiogher level classes
Definition: FilterBase.hh:43
int GetBorderHandling() const
Definition: FilterBase.hh:129
TBorderHandling
enum for border calculation, same meanings as in matlab:
Definition: FilterBase.hh:98
void SetBorderHandling(const int bh)
Definition: FilterBase.hh:127