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

vigra/gradient_energy_tensor.hxx VIGRA

00001 /************************************************************************/
00002 /*                                                                      */
00003 /*               Copyright 2004-2005 by Ullrich Koethe                  */
00004 /*                                                                      */
00005 /*    This file is part of the VIGRA computer vision library.           */
00006 /*    The VIGRA Website is                                              */
00007 /*        http://hci.iwr.uni-heidelberg.de/vigra/                       */
00008 /*    Please direct questions, bug reports, and contributions to        */
00009 /*        ullrich.koethe@iwr.uni-heidelberg.de    or                    */
00010 /*        vigra@informatik.uni-hamburg.de                               */
00011 /*                                                                      */
00012 /*    Permission is hereby granted, free of charge, to any person       */
00013 /*    obtaining a copy of this software and associated documentation    */
00014 /*    files (the "Software"), to deal in the Software without           */
00015 /*    restriction, including without limitation the rights to use,      */
00016 /*    copy, modify, merge, publish, distribute, sublicense, and/or      */
00017 /*    sell copies of the Software, and to permit persons to whom the    */
00018 /*    Software is furnished to do so, subject to the following          */
00019 /*    conditions:                                                       */
00020 /*                                                                      */
00021 /*    The above copyright notice and this permission notice shall be    */
00022 /*    included in all copies or substantial portions of the             */
00023 /*    Software.                                                         */
00024 /*                                                                      */
00025 /*    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND    */
00026 /*    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES   */
00027 /*    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND          */
00028 /*    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT       */
00029 /*    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,      */
00030 /*    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      */
00031 /*    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR     */
00032 /*    OTHER DEALINGS IN THE SOFTWARE.                                   */                
00033 /*                                                                      */
00034 /************************************************************************/
00035 
00036 
00037 #ifndef VIGRA_GRADIENT_ENERGY_TENSOR_HXX
00038 #define VIGRA_GRADIENT_ENERGY_TENSOR_HXX
00039 
00040 #include <cmath>
00041 #include <functional>
00042 #include "utilities.hxx"
00043 #include "array_vector.hxx"
00044 #include "basicimage.hxx"
00045 #include "combineimages.hxx"
00046 #include "numerictraits.hxx"
00047 #include "convolution.hxx"
00048 
00049 namespace vigra {
00050 
00051 /** \addtogroup TensorImaging Tensor Image Processing
00052 */
00053 //@{
00054 
00055 /********************************************************/
00056 /*                                                      */
00057 /*                 gradientEnergyTensor                 */
00058 /*                                                      */
00059 /********************************************************/
00060 
00061 /** \brief Calculate the gradient energy tensor for a scalar valued image.
00062 
00063     These function calculates the gradient energy tensor (GET operator) as described in
00064     
00065     M. Felsberg, U. K&ouml;the: 
00066     <i>"GET: The Connection Between Monogenic Scale-Space and Gaussian Derivatives"</i>, 
00067     in: R. Kimmel, N. Sochen, J. Weickert (Eds.): Scale Space and PDE Methods in Computer Vision, 
00068     Proc. of Scale-Space 2005, Lecture Notes in Computer Science 3459, pp. 192-203, Heidelberg: Springer, 2005.
00069     
00070     U. K&ouml;the, M. Felsberg: 
00071     <i>"Riesz-Transforms Versus Derivatives: On the Relationship Between the Boundary Tensor and the Energy Tensor"</i>, 
00072     in: ditto, pp. 179-191.
00073 
00074     with the given filters: The derivative filter \a derivKernel is applied to the appropriate image dimensions 
00075     in turn (see the papers above for details), and the other dimension is smoothed with \a smoothKernel. 
00076     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.  
00077     The output image must have 3 bands which will hold the
00078     tensor components in the order t11, t12 (== t21), t22. The signs of the output are adjusted for a right-handed
00079     coordinate system. Thus, orientations derived from the tensor will be in counter-clockwise (mathematically positive)
00080     order, with the x-axis at zero degrees (this is the standard in all VIGRA functions that deal with orientation).
00081     
00082     <b> Declarations:</b>
00083 
00084     pass arguments explicitly:
00085     \code
00086     namespace vigra {
00087         template <class SrcIterator, class SrcAccessor,
00088                   class DestIterator, class DestAccessor>
00089         void gradientEnergyTensor(SrcIterator supperleft, SrcIterator slowerright, SrcAccessor src,
00090                                   DestIterator dupperleft, DestAccessor dest,
00091                                   Kernel1D<double> const & derivKernel, Kernel1D<double> const & smoothKernel);
00092     }
00093     \endcode
00094 
00095     use argument objects in conjunction with \ref ArgumentObjectFactories :
00096     \code
00097     namespace vigra {
00098         template <class SrcIterator, class SrcAccessor,
00099                   class DestIterator, class DestAccessor>
00100         void gradientEnergyTensor(triple<SrcIterator, SrcIterator, SrcAccessor> src,
00101                                   pair<DestIterator, DestAccessor> dest,
00102                                   Kernel1D<double> const & derivKernel, Kernel1D<double> const & smoothKernel);
00103     }
00104     \endcode
00105 
00106     <b> Usage:</b>
00107 
00108     <b>\#include</b> <vigra/gradient_energy_tensor.hxx>
00109 
00110     \code
00111     FImage img(w,h);
00112     FVector3Image get(w,h);
00113     Kernel1D<double> grad, smooth;
00114     grad.initGaussianDerivative(0.7, 1);
00115     smooth.initGaussian(0.7);
00116     ...
00117     gradientEnergyTensor(srcImageRange(img), destImage(get), grad, smooth);
00118     \endcode
00119 
00120 */
00121 doxygen_overloaded_function(template <...> void gradientEnergyTensor)
00122 
00123 template <class SrcIterator, class SrcAccessor,
00124           class DestIterator, class DestAccessor>
00125 void gradientEnergyTensor(SrcIterator supperleft, SrcIterator slowerright, SrcAccessor src,
00126                           DestIterator dupperleft, DestAccessor dest,
00127                           Kernel1D<double> const & derivKernel, Kernel1D<double> const & smoothKernel)
00128 {
00129     vigra_precondition(dest.size(dupperleft) == 3,
00130                        "gradientEnergyTensor(): output image must have 3 bands.");
00131 
00132     int w = slowerright.x - supperleft.x;
00133     int h = slowerright.y - supperleft.y;
00134     
00135     typedef typename 
00136        NumericTraits<typename SrcAccessor::value_type>::RealPromote TmpType;
00137     typedef BasicImage<TmpType> TmpImage;    
00138     TmpImage gx(w, h), gy(w, h), 
00139              gxx(w, h), gxy(w, h), gyy(w, h), 
00140              laplace(w, h), gx3(w, h), gy3(w, h);
00141     
00142     convolveImage(srcIterRange(supperleft, slowerright, src), destImage(gx), 
00143                   derivKernel, smoothKernel);
00144     convolveImage(srcIterRange(supperleft, slowerright, src), destImage(gy), 
00145                   smoothKernel, derivKernel);
00146     convolveImage(srcImageRange(gx), destImage(gxx), 
00147                   derivKernel, smoothKernel);
00148     convolveImage(srcImageRange(gx), destImage(gxy), 
00149                   smoothKernel, derivKernel);
00150     convolveImage(srcImageRange(gy), destImage(gyy), 
00151                   smoothKernel, derivKernel);
00152     combineTwoImages(srcImageRange(gxx), srcImage(gyy), destImage(laplace), 
00153                      std::plus<TmpType>());
00154     convolveImage(srcImageRange(laplace), destImage(gx3), 
00155                   derivKernel, smoothKernel);
00156     convolveImage(srcImageRange(laplace), destImage(gy3), 
00157                   smoothKernel, derivKernel);
00158     typename TmpImage::iterator gxi  = gx.begin(),
00159                                 gyi  = gy.begin(),
00160                                 gxxi = gxx.begin(),
00161                                 gxyi = gxy.begin(),
00162                                 gyyi = gyy.begin(),
00163                                 gx3i = gx3.begin(),
00164                                 gy3i = gy3.begin();
00165     for(int y = 0; y < h; ++y, ++dupperleft.y)
00166     {
00167         typename DestIterator::row_iterator d = dupperleft.rowIterator(); 
00168         for(int x = 0; x < w; ++x, ++d, ++gxi, ++gyi, ++gxxi, ++gxyi, ++gyyi, ++gx3i, ++gy3i)
00169         {
00170             dest.setComponent(sq(*gxxi) + sq(*gxyi) - *gxi * *gx3i, d, 0);
00171             dest.setComponent(- *gxyi * (*gxxi + *gyyi) + 0.5 * (*gxi * *gy3i + *gyi * *gx3i), d, 1);
00172             dest.setComponent(sq(*gxyi) + sq(*gyyi) - *gyi * *gy3i, d, 2);
00173         }
00174     }
00175 }
00176 
00177 template <class SrcIterator, class SrcAccessor,
00178           class DestIterator, class DestAccessor>
00179 inline
00180 void gradientEnergyTensor(triple<SrcIterator, SrcIterator, SrcAccessor> src,
00181                           pair<DestIterator, DestAccessor> dest,
00182                           Kernel1D<double> const & derivKernel, Kernel1D<double> const & smoothKernel)
00183 {
00184     gradientEnergyTensor(src.first, src.second, src.third,
00185                          dest.first, dest.second, derivKernel, smoothKernel);
00186 }
00187 
00188 //@}
00189 
00190 } // namespace vigra
00191 
00192 #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.8.0 (20 Sep 2011)