vigra - vigra/gradient_energy_tensor.hxx Source File

[ 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 #include "multi_shape.hxx"
49
50 namespace vigra {
51
52 /** \addtogroup TensorImaging Tensor Image Processing
53 */
54 //@{
55
56 /********************************************************/
57 /* */
58 /* gradientEnergyTensor */
59 /* */
60 /********************************************************/
61
62 /** \brief Calculate the gradient energy tensor for a scalar valued image.
63
64 These function calculates the gradient energy tensor (GET operator) as described in
65
66 M. Felsberg, U. K&ouml;the:
67 <i>"GET: The Connection Between Monogenic Scale-Space and Gaussian Derivatives"</i>,
68 in: R. Kimmel, N. Sochen, J. Weickert (Eds.): Scale Space and PDE Methods in Computer Vision,
69 Proc. of Scale-Space 2005, Lecture Notes in Computer Science 3459, pp. 192-203, Heidelberg: Springer, 2005.
70
71 U. K&ouml;the, M. Felsberg:
72 <i>"Riesz-Transforms Versus Derivatives: On the Relationship Between the Boundary Tensor and the Energy Tensor"</i>,
73 in: ditto, pp. 179-191.
74
75 with the given filters: The derivative filter \a derivKernel is applied to the appropriate image dimensions
76 in turn (see the papers above for details), and the other dimension is smoothed with \a smoothKernel.
77 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.
78 The output image must have 3 bands which will hold the
79 tensor components in the order t11, t12 (== t21), t22. The signs of the output are adjusted for a right-handed
80 coordinate system. Thus, orientations derived from the tensor will be in counter-clockwise (mathematically positive)
81 order, with the x-axis at zero degrees (this is the standard in all VIGRA functions that deal with orientation).
82
83 <b> Declarations:</b>
84
85 pass 2D array views:
86 \code
87 namespace vigra {
88 template <class T1, class S1,
89 class T2, class S2>
90 void
91 gradientEnergyTensor(MultiArrayView<2, T1, S1> const & src,
92 MultiArrayView<2, T2, S2> dest,
93 Kernel1D<double> const & derivKernel, Kernel1D<double> const & smoothKernel);
94 }
95 \endcode
96
97 \deprecatedAPI{gradientEnergyTensor}
98 pass \ref ImageIterators and \ref DataAccessors :
99 \code
100 namespace vigra {
101 template <class SrcIterator, class SrcAccessor,
102 class DestIterator, class DestAccessor>
103 void gradientEnergyTensor(SrcIterator supperleft, SrcIterator slowerright, SrcAccessor src,
104 DestIterator dupperleft, DestAccessor dest,
105 Kernel1D<double> const & derivKernel, Kernel1D<double> const & smoothKernel);
106 }
107 \endcode
108 use argument objects in conjunction with \ref ArgumentObjectFactories :
109 \code
110 namespace vigra {
111 template <class SrcIterator, class SrcAccessor,
112 class DestIterator, class DestAccessor>
113 void gradientEnergyTensor(triple<SrcIterator, SrcIterator, SrcAccessor> src,
114 pair<DestIterator, DestAccessor> dest,
115 Kernel1D<double> const & derivKernel, Kernel1D<double> const & smoothKernel);
116 }
117 \endcode
118 \deprecatedEnd
119
120 <b> Usage:</b>
121
122 <b>\#include</b> <vigra/gradient_energy_tensor.hxx><br/>
123 Namespace: vigra
124
125 \code
126 MultiArray<2, float> img(w,h);
127 MultiArray<2, TinyVector<float, 3> > get(w,h);
128 Kernel1D<double> grad, smooth;
129 grad.initGaussianDerivative(0.7, 1);
130 smooth.initGaussian(0.7);
131 ...
132 gradientEnergyTensor(img, get, grad, smooth);
133 \endcode
134
135 \deprecatedUsage{gradientEnergyTensor}
136 \code
137 FImage img(w,h);
138 FVector3Image get(w,h);
139 Kernel1D<double> grad, smooth;
140 grad.initGaussianDerivative(0.7, 1);
141 smooth.initGaussian(0.7);
142 ...
143 gradientEnergyTensor(srcImageRange(img), destImage(get), grad, smooth);
144 \endcode
145 \deprecatedEnd
146 */
147 doxygen_overloaded_function(template <...> void gradientEnergyTensor)
148
149 template <class SrcIterator, class SrcAccessor,
150 class DestIterator, class DestAccessor>
151 void gradientEnergyTensor(SrcIterator supperleft, SrcIterator slowerright, SrcAccessor src,
152 DestIterator dupperleft, DestAccessor dest,
153 Kernel1D<double> const & derivKernel, Kernel1D<double> const & smoothKernel)
154 {
155 vigra_precondition(dest.size(dupperleft) == 3,
156 "gradientEnergyTensor(): output image must have 3 bands.");
157
158 int w = slowerright.x - supperleft.x;
159 int h = slowerright.y - supperleft.y;
160
161 typedef typename
162 NumericTraits<typename SrcAccessor::value_type>::RealPromote TmpType;
163 typedef BasicImage<TmpType> TmpImage;
164 TmpImage gx(w, h), gy(w, h),
165 gxx(w, h), gxy(w, h), gyy(w, h),
166 laplace(w, h), gx3(w, h), gy3(w, h);
167
168 convolveImage(srcIterRange(supperleft, slowerright, src), destImage(gx),
169 derivKernel, smoothKernel);
170 convolveImage(srcIterRange(supperleft, slowerright, src), destImage(gy),
171 smoothKernel, derivKernel);
172 convolveImage(srcImageRange(gx), destImage(gxx),
173 derivKernel, smoothKernel);
174 convolveImage(srcImageRange(gx), destImage(gxy),
175 smoothKernel, derivKernel);
176 convolveImage(srcImageRange(gy), destImage(gyy),
177 smoothKernel, derivKernel);
178 combineTwoImages(srcImageRange(gxx), srcImage(gyy), destImage(laplace),
179 std::plus<TmpType>());
180 convolveImage(srcImageRange(laplace), destImage(gx3),
181 derivKernel, smoothKernel);
182 convolveImage(srcImageRange(laplace), destImage(gy3),
183 smoothKernel, derivKernel);
184 typename TmpImage::iterator gxi = gx.begin(),
185 gyi = gy.begin(),
186 gxxi = gxx.begin(),
187 gxyi = gxy.begin(),
188 gyyi = gyy.begin(),
189 gx3i = gx3.begin(),
190 gy3i = gy3.begin();
191 for(int y = 0; y < h; ++y, ++dupperleft.y)
192 {
193 typename DestIterator::row_iterator d = dupperleft.rowIterator();
194 for(int x = 0; x < w; ++x, ++d, ++gxi, ++gyi, ++gxxi, ++gxyi, ++gyyi, ++gx3i, ++gy3i)
195 {
196 dest.setComponent(sq(*gxxi) + sq(*gxyi) - *gxi * *gx3i, d, 0);
197 dest.setComponent(- *gxyi * (*gxxi + *gyyi) + 0.5 * (*gxi * *gy3i + *gyi * *gx3i), d, 1);
198 dest.setComponent(sq(*gxyi) + sq(*gyyi) - *gyi * *gy3i, d, 2);
199 }
200 }
201 }
202
203 template <class SrcIterator, class SrcAccessor,
204 class DestIterator, class DestAccessor>
205 inline void
206 gradientEnergyTensor(triple<SrcIterator, SrcIterator, SrcAccessor> src,
207 pair<DestIterator, DestAccessor> dest,
208 Kernel1D<double> const & derivKernel, Kernel1D<double> const & smoothKernel)
209 {
210 gradientEnergyTensor(src.first, src.second, src.third,
211 dest.first, dest.second, derivKernel, smoothKernel);
212 }
213
214 template <class T1, class S1,
215 class T2, class S2>
216 inline void
217 gradientEnergyTensor(MultiArrayView<2, T1, S1> const & src,
218 MultiArrayView<2, T2, S2> dest,
219 Kernel1D<double> const & derivKernel, Kernel1D<double> const & smoothKernel)
220 {
221 vigra_precondition(src.shape() == dest.shape(),
222 "gradientEnergyTensor(): shape mismatch between input and output.");
223 gradientEnergyTensor(srcImageRange(src),
224 destImage(dest), derivKernel, smoothKernel);
225 }
226
227 //@}
228
229 } // namespace vigra
230
231 #endif // VIGRA_GRADIENT_ENERGY_TENSOR_HXX
vigra::convolveImage
void convolveImage(...)
Convolve an image with the given kernel(s).
vigra::gradientEnergyTensor
void gradientEnergyTensor(...)
Calculate the gradient energy tensor for a scalar valued image.
vigra::sq
NumericTraits< T >::Promote sq(T t)
The square function.
Definition: mathutil.hxx:382
vigra::combineTwoImages
void combineTwoImages(...)
Combine two source images into destination image.
vigra::doxygen_overloaded_function
doxygen_overloaded_function(template<...> void separableConvolveBlockwise) template< unsigned int N
Separated convolution on ChunkedArrays.
utilities.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.11.1 (Fri May 19 2017)