Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Convolution.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  Johan Skoglund
10  skoglund@isy.liu.se
11  CVL/isy
12  university of Linkoeping
13  sweden
14 
15 BIAS is free software; you can redistribute it and/or modify
16 it under the terms of the GNU Lesser General Public License as published by
17 the Free Software Foundation; either version 2.1 of the License, or
18 (at your option) any later version.
19 
20 BIAS is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU Lesser General Public License for more details.
24 
25 You should have received a copy of the GNU Lesser General Public License
26 along with BIAS; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 */
29 
30 
31 #ifndef __Convolution_hh__
32 #define __Convolution_hh__
33 
34 #include <typeinfo>
35 
36 #include "FilterNToN.hh"
37 #include "FilterMask.hh"
38 
39 #define D_GRADGAUSS_KERNEL 0x00000001
40 #define D_CONV_KERNEL 0x00000002
41 #define D_GRAD_DEB 0x00000004
42 #define D_WRITE_IMAGES 0x00000008
43 #define D_CONV_TYPES 0x00000010
44 #define D_HESSGAUSS_KERNEL 0x00000012
45 
46 // data types, in which intermediate values are computed
47 #define CONV_FLOAT float
48 #define CONV_INT int
49 
50 namespace BIAS {
51 
52  /** @class Convolution
53  @ingroup g_filter
54  @brief generic convolution class.
55 
56  Use as follows:
57  - SetKernel(FilterMask)
58  - Filter(source, destination)
59 
60  Center pixel is determined by (size-1)>>1.
61 
62  @author woelk/koeser/skoglund
63  @date 11/2004 */
64 
65  template <class InputStorageType, class OutputStorageType>
66  class BIASFilter_EXPORT Convolution
67  : public FilterNToN<InputStorageType, OutputStorageType>
68  {
69  public:
70  Convolution();
72  virtual ~Convolution();
73 
74  /** @brief decides on the image types which
75  FilterFunction should be called */
76  virtual int Filter(const Image<InputStorageType>& src,
78 
79 
80  /** @brief do the convolution using integer arithmetics and shifts */
81  virtual int FilterInt(const Image<InputStorageType>& src,
83 
84  /** @brief do the convolution using floating point calculations */
85  virtual int FilterFloat(const Image<InputStorageType>& src,
87 
90 
91  /** @brief get the current filter mask */
92  inline void GetKernel(FilterMask& fm) const
93  { fm = _fm; }
94 
95  /** @brief set a new filter mask */
96  inline void SetKernel(FilterMask& fm)
97  { _fm = fm;}
98 
99  /** @brief prints the used filter mask, for debugging */
100  void PrintKernel() const;
101 
102  /** @brief decides if calculation is done in integer or floating point */
103  inline bool CalculationInFloat() const
104  { return ((typeid(OutputStorageType)==typeid(float)) ||
105  (typeid(OutputStorageType)==typeid(double))||
106  (typeid(InputStorageType)==typeid(float)) ||
107  (typeid(InputStorageType)==typeid(double))); };
108 
109  protected:
110  /// the kernel data used for convolution
111  FilterMask _fm;
112 
113  /// temporary memory, needed for separable filters when float filtering
115 
116  /// temporary memory, needed for separable filters when integer filtering
118 
119  /// @brief worker function for int matrix convolution
120  int ConvIntMat_(const Image<InputStorageType> &src,
122 
123  /// @brief worker function for int separated (horizontal) convolution
124  int ConvIntHori_(const Image<InputStorageType> &src,
125  Image<CONV_INT> &dst);
126 
127  /// @brief worker function for int separated (vertical) convolution
128  int ConvIntVert_(const Image<CONV_INT> &src,
130 
131  /// @brief worker function for float matrix convolution
132  int ConvFloatMat_(const Image<InputStorageType> &src,
134 
135  /// @brief worker function for float separated (horizontal) convolution
136  int ConvFloatHori_(const Image<InputStorageType> &src,
137  Image<CONV_FLOAT> &dst);
138 
139  /// @brief worker function for float separated (vertical) convolution
140  int ConvFloatVert_(const Image<CONV_FLOAT> &src,
142 
143  inline void GetBordersValid_(int &border_x, int &border_y) const
144  { _fm.GetSize(border_x, border_y); }
145 
146  }; // class
147 
148 
149 } // namespace
150 
151 #endif // __Convolution_hh__
virtual FilterNToN< InputStorageType, OutputStorageType > * Clone() const
Definition: Convolution.hh:88
generic convolution class.
Definition: Convolution.hh:66
Image< CONV_FLOAT > _tmpFloat
temporary memory, needed for separable filters when float filtering
Definition: Convolution.hh:114
Image< CONV_INT > _tmpInt
temporary memory, needed for separable filters when integer filtering
Definition: Convolution.hh:117
void SetKernel(FilterMask &fm)
set a new filter mask
Definition: Convolution.hh:96
base class for simple n-&gt;n filter implementations
Definition: FilterNToN.hh:43
void GetKernel(FilterMask &fm) const
get the current filter mask
Definition: Convolution.hh:92
void GetBordersValid_(int &border_x, int &border_y) const
Definition: Convolution.hh:143
A filter mask (or a kernel) used for convolution.
Definition: FilterMask.hh:61
bool CalculationInFloat() const
decides if calculation is done in integer or floating point
Definition: Convolution.hh:103