[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

gradient_energy_tensor.hxx
1 /************************************************************************/
2 /* */
3 /* Copyright 2004-2005 by Ullrich Koethe */
4 /* */
5 /* This file is part of the VIGRA computer vision library. */
6 /* The VIGRA Website is */
7 /* http://hci.iwr.uni-heidelberg.de/vigra/ */
8 /* Please direct questions, bug reports, and contributions to */
9 /* ullrich.koethe@iwr.uni-heidelberg.de or */
10 /* vigra@informatik.uni-hamburg.de */
11 /* */
12 /* Permission is hereby granted, free of charge, to any person */
13 /* obtaining a copy of this software and associated documentation */
14 /* files (the "Software"), to deal in the Software without */
15 /* restriction, including without limitation the rights to use, */
16 /* copy, modify, merge, publish, distribute, sublicense, and/or */
17 /* sell copies of the Software, and to permit persons to whom the */
18 /* Software is furnished to do so, subject to the following */
19 /* conditions: */
20 /* */
21 /* The above copyright notice and this permission notice shall be */
22 /* included in all copies or substantial portions of the */
23 /* Software. */
24 /* */
25 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
26 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
27 /* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
28 /* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
29 /* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
30 /* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
31 /* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
32 /* OTHER DEALINGS IN THE SOFTWARE. */
33 /* */
34 /************************************************************************/
35 
36 
37 #ifndef VIGRA_GRADIENT_ENERGY_TENSOR_HXX
38 #define VIGRA_GRADIENT_ENERGY_TENSOR_HXX
39 
40 #include <cmath>
41 #include <functional>
42 #include "utilities.hxx"
43 #include "array_vector.hxx"
44 #include "basicimage.hxx"
45 #include "combineimages.hxx"
46 #include "numerictraits.hxx"
47 #include "convolution.hxx"
48 
49 namespace vigra {
50 
51 /** \addtogroup TensorImaging Tensor Image Processing
52 */
53 //@{
54 
55 /********************************************************/
56 /* */
57 /* gradientEnergyTensor */
58 /* */
59 /********************************************************/
60 
61 /** \brief Calculate the gradient energy tensor for a scalar valued image.
62 
63  These function calculates the gradient energy tensor (GET operator) as described in
64 
65  M. Felsberg, U. K&ouml;the:
66  <i>"GET: The Connection Between Monogenic Scale-Space and Gaussian Derivatives"</i>,
67  in: R. Kimmel, N. Sochen, J. Weickert (Eds.): Scale Space and PDE Methods in Computer Vision,
68  Proc. of Scale-Space 2005, Lecture Notes in Computer Science 3459, pp. 192-203, Heidelberg: Springer, 2005.
69 
70  U. K&ouml;the, M. Felsberg:
71  <i>"Riesz-Transforms Versus Derivatives: On the Relationship Between the Boundary Tensor and the Energy Tensor"</i>,
72  in: ditto, pp. 179-191.
73 
74  with the given filters: The derivative filter \a derivKernel is applied to the appropriate image dimensions
75  in turn (see the papers above for details), and the other dimension is smoothed with \a smoothKernel.
76  The kernels can be as small as 3x1, e.g. [0.5, 0, -0.5] and [3.0/16.0, 10.0/16.0, 3.0/16.0] respectively.
77  The output image must have 3 bands which will hold the
78  tensor components in the order t11, t12 (== t21), t22. The signs of the output are adjusted for a right-handed
79  coordinate system. Thus, orientations derived from the tensor will be in counter-clockwise (mathematically positive)
80  order, with the x-axis at zero degrees (this is the standard in all VIGRA functions that deal with orientation).
81 
82  <b> Declarations:</b>
83 
84  pass arguments explicitly:
85  \code
86  namespace vigra {
87  template <class SrcIterator, class SrcAccessor,
88  class DestIterator, class DestAccessor>
89  void gradientEnergyTensor(SrcIterator supperleft, SrcIterator slowerright, SrcAccessor src,
90  DestIterator dupperleft, DestAccessor dest,
91  Kernel1D<double> const & derivKernel, Kernel1D<double> const & smoothKernel);
92  }
93  \endcode
94 
95  use argument objects in conjunction with \ref ArgumentObjectFactories :
96  \code
97  namespace vigra {
98  template <class SrcIterator, class SrcAccessor,
99  class DestIterator, class DestAccessor>
100  void gradientEnergyTensor(triple<SrcIterator, SrcIterator, SrcAccessor> src,
101  pair<DestIterator, DestAccessor> dest,
102  Kernel1D<double> const & derivKernel, Kernel1D<double> const & smoothKernel);
103  }
104  \endcode
105 
106  <b> Usage:</b>
107 
108  <b>\#include</b> <vigra/gradient_energy_tensor.hxx>
109 
110  \code
111  FImage img(w,h);
112  FVector3Image get(w,h);
113  Kernel1D<double> grad, smooth;
114  grad.initGaussianDerivative(0.7, 1);
115  smooth.initGaussian(0.7);
116  ...
117  gradientEnergyTensor(srcImageRange(img), destImage(get), grad, smooth);
118  \endcode
119 
120 */
121 doxygen_overloaded_function(template <...> void gradientEnergyTensor)
122 
123 template <class SrcIterator, class SrcAccessor,
124  class DestIterator, class DestAccessor>
125 void gradientEnergyTensor(SrcIterator supperleft, SrcIterator slowerright, SrcAccessor src,
126  DestIterator dupperleft, DestAccessor dest,
127  Kernel1D<double> const & derivKernel, Kernel1D<double> const & smoothKernel)
128 {
129  vigra_precondition(dest.size(dupperleft) == 3,
130  "gradientEnergyTensor(): output image must have 3 bands.");
131 
132  int w = slowerright.x - supperleft.x;
133  int h = slowerright.y - supperleft.y;
134 
135  typedef typename
136  NumericTraits<typename SrcAccessor::value_type>::RealPromote TmpType;
137  typedef BasicImage<TmpType> TmpImage;
138  TmpImage gx(w, h), gy(w, h),
139  gxx(w, h), gxy(w, h), gyy(w, h),
140  laplace(w, h), gx3(w, h), gy3(w, h);
141 
142  convolveImage(srcIterRange(supperleft, slowerright, src), destImage(gx),
143  derivKernel, smoothKernel);
144  convolveImage(srcIterRange(supperleft, slowerright, src), destImage(gy),
145  smoothKernel, derivKernel);
146  convolveImage(srcImageRange(gx), destImage(gxx),
147  derivKernel, smoothKernel);
148  convolveImage(srcImageRange(gx), destImage(gxy),
149  smoothKernel, derivKernel);
150  convolveImage(srcImageRange(gy), destImage(gyy),
151  smoothKernel, derivKernel);
152  combineTwoImages(srcImageRange(gxx), srcImage(gyy), destImage(laplace),
153  std::plus<TmpType>());
154  convolveImage(srcImageRange(laplace), destImage(gx3),
155  derivKernel, smoothKernel);
156  convolveImage(srcImageRange(laplace), destImage(gy3),
157  smoothKernel, derivKernel);
158  typename TmpImage::iterator gxi = gx.begin(),
159  gyi = gy.begin(),
160  gxxi = gxx.begin(),
161  gxyi = gxy.begin(),
162  gyyi = gyy.begin(),
163  gx3i = gx3.begin(),
164  gy3i = gy3.begin();
165  for(int y = 0; y < h; ++y, ++dupperleft.y)
166  {
167  typename DestIterator::row_iterator d = dupperleft.rowIterator();
168  for(int x = 0; x < w; ++x, ++d, ++gxi, ++gyi, ++gxxi, ++gxyi, ++gyyi, ++gx3i, ++gy3i)
169  {
170  dest.setComponent(sq(*gxxi) + sq(*gxyi) - *gxi * *gx3i, d, 0);
171  dest.setComponent(- *gxyi * (*gxxi + *gyyi) + 0.5 * (*gxi * *gy3i + *gyi * *gx3i), d, 1);
172  dest.setComponent(sq(*gxyi) + sq(*gyyi) - *gyi * *gy3i, d, 2);
173  }
174  }
175 }
176 
177 template <class SrcIterator, class SrcAccessor,
178  class DestIterator, class DestAccessor>
179 inline
180 void gradientEnergyTensor(triple<SrcIterator, SrcIterator, SrcAccessor> src,
181  pair<DestIterator, DestAccessor> dest,
182  Kernel1D<double> const & derivKernel, Kernel1D<double> const & smoothKernel)
183 {
184  gradientEnergyTensor(src.first, src.second, src.third,
185  dest.first, dest.second, derivKernel, smoothKernel);
186 }
187 
188 //@}
189 
190 } // namespace vigra
191 
192 #endif // VIGRA_GRADIENT_ENERGY_TENSOR_HXX

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de)
Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany

html generated using doxygen and Python
vigra 1.9.0 (Sat Oct 5 2013)