Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StructureTensor.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 __StructureTensor_hh__
26 #define __StructureTensor_hh__
27 
28 #include "FilterBase.hh"
29 #include "GradientSobel3x3.hh"
30 #include "GradientGauss.hh"
31 #include "GradientGaussAsymmetric.hh"
32 #include "FilterNTo3N.hh"
33 
34 #define D_ST_WRITE_DEBUG_IM 0x00000001
35 #define D_ST_INIT 0x00000002
36 #define D_ST_FEATURES 0x00000004
37 
38 namespace BIAS {
39 
40  /** @class StructureTensor
41  @ingroup g_filter
42  @brief basic class for structure tensor calculation
43 
44  @author woelk 09/2004 */
45  template <class InputStorageType, class OutputStorageType>
46  class BIASFilter_EXPORT StructureTensor : public FilterNTo3N<InputStorageType,
47  OutputStorageType>
48  {
51  ::_FilterBorderHandling;
52  public:
55  ~StructureTensor();
56 
57  /** calls the apropriate non virtual member function
58  returns an 3 channel image where
59  - channel 0 contains gxx
60  - channel 1 contains gxy
61  - channel 2 contains gyy
62  @todo implement StructureTensor
63  @author woelk 09/2004 */
64  virtual int Filter(const Image<InputStorageType>& src,
66  virtual int FilterInt(const Image<InputStorageType>& src,
68  virtual int FilterFloat(const Image<InputStorageType>& src,
70 
71  virtual int Filter(const Image<InputStorageType>& src,
75 
76  virtual int FilterInt(const Image<InputStorageType>& src,
80 
81  virtual int FilterFloat(const Image<InputStorageType>& src,
85 
88 
89 
90  /** Calculates the gradients uses internal gradient class and calls
91  CalcStructureTensor with these gradients
92  @author woelk 09/2004 */
93  int CalcStructureTensor(const Image<InputStorageType>& src,
97 
98  /** For any _HalfWinSize. For any border handling.
99  @todo implement CalcStructureTensor for other border handling than
100  valid
101  @author woelk 09/2004 */
102  int CalcStructureTensor(const Image<OutputStorageType>& gx,
103  const Image<OutputStorageType>& gy,
107 
108  /** For any _HalfWinSize. Uses valid border handling.
109  Destination images must be initialized.
110  @todo implement separated summation.
111  @author woelk 09/2004 */
112  int CalcStructureTensorValid(const Image<OutputStorageType>& gx,
113  const Image<OutputStorageType>& gy,
117 
118  /** Uses _HalfWinSize=1
119  Destination images must be initialized.
120  @author woelk 09/2004 */
121  int CalcStructureTensor3x3(const Image<OutputStorageType>& gx,
122  const Image<OutputStorageType>& gy,
126 
127  /** Uses _HalfWinSize=2
128  Destination images must be initialized.
129  @author woelk 09/2004 */
130  int CalcStructureTensor5x5(const Image<OutputStorageType>& gx,
131  const Image<OutputStorageType>& gy,
135 
136  /** Uses _HalfWinSize=3
137  Destination images must be initialized.
138  @todo make it really fast
139  @author woelk 09/2004 */
140  int CalcStructureTensor7x7(const Image<OutputStorageType>& gx,
141  const Image<OutputStorageType>& gy,
145 
146  ///////////////////////////////////////////////////////////////////////
147 
148  inline void SetHalfWinSize(const int hws) { _HalfWinSize=hws; }
149 
150  inline int GetHalfWinSize() const { return _HalfWinSize; }
151 
153  { if (_grad) delete _grad; _grad = grad.Clone(); }
154 
155  inline const Image<OutputStorageType>& GetGradientX() const {
156  return _gx;
157  }
158 
159  inline const Image<OutputStorageType>& GetGradientY() const {
160  return _gy;
161  }
162 
163  protected:
164  /// pointer to gradient filter actually used:
166 
167  // the window size for the structure tensor computation
169 
170  // internal variables
171  // gradient images
173  // _gxx = gx*gx, gxy = gx*gy, gyy = gy*gy
175  // temporary space for separated summation
177  // size of the internal images
178  int _InternalMemWidth, _InternalMemHeight;
179 
180  /// for debugging only
181  void _WriteDebugImage(Image<OutputStorageType>& im, std::string name);
182 
183  /** fills up _gxx, _gxy, _gyy from gx and gy
184  @author woelk 09/2004 */
185  void _GradientProducts(const Image<OutputStorageType>& gx,
186  const Image<OutputStorageType>& gy);
187 
188 
189  /// allocates _gxx, _gyy, _gxy, _tsgxx, _tsgxy, _tsgyy
190  /// and sets InternalMemWidth and _InternalMemHeight
191  void _AllocInternalMem(const int width, const int height);
192 
193  virtual void GetBordersValid_(int &border_x, int &border_y) const;
194 
195  }; // class
196 
197 } // namespace
198 
199 #endif //__StructureTensor_hh__
void SetGradientFilter(const FilterNTo2N< InputStorageType, OutputStorageType > &grad)
const Image< OutputStorageType > & GetGradientY() const
base class for simple n-&gt;2n filter implementations
Definition: FilterNTo2N.hh:44
virtual parent class for API definition of all (future) filters
Definition: FilterBase.hh:77
virtual FilterNTo3N< InputStorageType, OutputStorageType > * Clone() const
basic class for structure tensor calculation
FilterNTo2N< InputStorageType, OutputStorageType > * _grad
pointer to gradient filter actually used:
const Image< OutputStorageType > & GetGradientX() const
virtual FilterNTo2N< InputStorageType, OutputStorageType > * Clone() const =0
void SetHalfWinSize(const int hws)
Image< OutputStorageType > _gyy
Image< OutputStorageType > _gy
base class for simple n-&gt;3n filter implementations
Definition: FilterNTo3N.hh:43
Image< OutputStorageType > _tsgyy