Basic Image AlgorithmS Library 2.8.0

StructureTensor.hh

00001 /*
00002 This file is part of the BIAS library (Basic ImageAlgorithmS).
00003 
00004 Copyright (C) 2003-2009    (see file CONTACT for details)
00005   Multimediale Systeme der Informationsverarbeitung
00006   Institut fuer Informatik
00007   Christian-Albrechts-Universitaet Kiel
00008 
00009 
00010 BIAS is free software; you can redistribute it and/or modify
00011 it under the terms of the GNU Lesser General Public License as published by
00012 the Free Software Foundation; either version 2.1 of the License, or
00013 (at your option) any later version.
00014 
00015 BIAS is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU Lesser General Public License for more details.
00019 
00020 You should have received a copy of the GNU Lesser General Public License
00021 along with BIAS; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 */
00024 
00025 #ifndef __StructureTensor_hh__
00026 #define __StructureTensor_hh__
00027 
00028 #include "FilterBase.hh"
00029 #include "GradientSobel3x3.hh"
00030 #include "GradientGauss.hh"
00031 #include "GradientGaussAsymmetric.hh"
00032 #include "FilterNTo3N.hh"
00033 
00034 #define D_ST_WRITE_DEBUG_IM 0x00000001
00035 #define D_ST_INIT           0x00000002
00036 #define D_ST_FEATURES       0x00000004
00037 
00038 namespace BIAS {
00039 
00040   /** @class StructureTensor
00041       @ingroup g_filter
00042       @brief basic class for structure tensor calculation
00043 
00044       @author woelk 09/2004 */
00045   template <class InputStorageType, class OutputStorageType> 
00046   class BIASFilter_EXPORT StructureTensor : public FilterNTo3N<InputStorageType, 
00047                                              OutputStorageType>
00048   {
00049     using FilterBase<InputStorageType,OutputStorageType>::DebugLevelIsSet;
00050     using FilterBase<InputStorageType,OutputStorageType>
00051     ::_FilterBorderHandling;
00052   public:
00053     StructureTensor();
00054     StructureTensor(const StructureTensor<InputStorageType, OutputStorageType>& other);
00055     ~StructureTensor();
00056 
00057     /** calls the apropriate non virtual member function
00058         returns an 3 channel image where 
00059         - channel 0 contains gxx
00060         - channel 1 contains gxy
00061         - channel 2 contains gyy
00062         @todo implement StructureTensor
00063         @author woelk 09/2004 */
00064     virtual int Filter(const Image<InputStorageType>& src, 
00065                        Image<OutputStorageType>& dst);
00066     virtual int FilterInt(const Image<InputStorageType>& src, 
00067                           Image<OutputStorageType>& dst);
00068     virtual int FilterFloat(const Image<InputStorageType>& src, 
00069                             Image<OutputStorageType>& dst);
00070 
00071     virtual int Filter(const Image<InputStorageType>& src, 
00072                        Image<OutputStorageType>& gxx, 
00073                        Image<OutputStorageType>& gxy,
00074                        Image<OutputStorageType>& gyy);
00075 
00076     virtual int FilterInt(const Image<InputStorageType>& src, 
00077                           Image<OutputStorageType>& gxx, 
00078                           Image<OutputStorageType>& gxy,
00079                           Image<OutputStorageType>& gyy);
00080 
00081     virtual int FilterFloat(const Image<InputStorageType>& src, 
00082                             Image<OutputStorageType>& gxx, 
00083                             Image<OutputStorageType>& gxy,
00084                             Image<OutputStorageType>& gyy);
00085 
00086     virtual FilterNTo3N<InputStorageType, OutputStorageType>* Clone() const
00087     { return new StructureTensor<InputStorageType, OutputStorageType>(*this); }
00088     
00089 
00090     /** Calculates the gradients uses internal gradient class and calls
00091         CalcStructureTensor with these gradients
00092         @author woelk 09/2004 */
00093     int CalcStructureTensor(const Image<InputStorageType>& src, 
00094                            Image<OutputStorageType>& sgxx, 
00095                             Image<OutputStorageType>& sgxy,
00096                            Image<OutputStorageType>& sgyy);
00097 
00098     /** For any _HalfWinSize. For any border handling.
00099         @todo implement CalcStructureTensor for other border handling than 
00100         valid
00101         @author woelk 09/2004 */
00102     int CalcStructureTensor(const Image<OutputStorageType>& gx,
00103                             const Image<OutputStorageType>& gy, 
00104                             Image<OutputStorageType>& sgxx, 
00105                             Image<OutputStorageType>& sgxy,
00106                             Image<OutputStorageType>& sgyy);
00107 
00108     /** For any _HalfWinSize. Uses valid border handling.
00109         Destination images must be initialized.
00110         @todo implement separated summation.
00111         @author woelk 09/2004 */
00112     int CalcStructureTensorValid(const Image<OutputStorageType>& gx,
00113                                  const Image<OutputStorageType>& gy, 
00114                                  Image<OutputStorageType>& sgxx, 
00115                                  Image<OutputStorageType>& sgxy,
00116                                  Image<OutputStorageType>& sgyy);
00117 
00118     /** Uses _HalfWinSize=1
00119         Destination images must be initialized.
00120         @author woelk 09/2004 */
00121     int CalcStructureTensor3x3(const Image<OutputStorageType>& gx,
00122                                const Image<OutputStorageType>& gy, 
00123                                Image<OutputStorageType>& sgxx, 
00124                                Image<OutputStorageType>& sgxy,
00125                                Image<OutputStorageType>& sgyy);
00126 
00127     /** Uses _HalfWinSize=2
00128         Destination images must be initialized.
00129         @author woelk 09/2004 */
00130     int CalcStructureTensor5x5(const Image<OutputStorageType>& gx,
00131                                const Image<OutputStorageType>& gy, 
00132                                Image<OutputStorageType>& sgxx, 
00133                                Image<OutputStorageType>& sgxy,
00134                                Image<OutputStorageType>& sgyy);
00135 
00136     /** Uses _HalfWinSize=3
00137         Destination images must be initialized.
00138         @todo make it really fast
00139         @author woelk 09/2004 */
00140     int CalcStructureTensor7x7(const Image<OutputStorageType>& gx,
00141                                const Image<OutputStorageType>& gy, 
00142                                Image<OutputStorageType>& sgxx, 
00143                                Image<OutputStorageType>& sgxy,
00144                                Image<OutputStorageType>& sgyy);
00145 
00146     ///////////////////////////////////////////////////////////////////////
00147 
00148     inline void SetHalfWinSize(const int hws) { _HalfWinSize=hws; }
00149 
00150     inline int GetHalfWinSize() const { return _HalfWinSize; }
00151 
00152     inline void SetGradientFilter(const FilterNTo2N<InputStorageType, OutputStorageType>& grad) 
00153     { if (_grad) delete _grad; _grad = grad.Clone(); }
00154 
00155     inline const Image<OutputStorageType>& GetGradientX() const {
00156       return _gx;
00157     }
00158 
00159     inline const Image<OutputStorageType>& GetGradientY() const {
00160       return _gy;
00161     }
00162 
00163   protected:
00164     /// pointer to gradient filter actually used:
00165     FilterNTo2N<InputStorageType, OutputStorageType> *_grad;
00166 
00167     // the window size for the structure tensor computation
00168     int _HalfWinSize;
00169 
00170     // internal variables
00171     // gradient images
00172     Image<OutputStorageType> _gx, _gy;
00173     // _gxx = gx*gx, gxy = gx*gy, gyy = gy*gy
00174     Image<OutputStorageType> _gxx, _gxy, _gyy;
00175     // temporary space for separated summation
00176     Image<OutputStorageType> _tsgxx, _tsgxy, _tsgyy;
00177     // size of the internal images
00178     int _InternalMemWidth, _InternalMemHeight;
00179 
00180     /// for debugging only
00181     void _WriteDebugImage(Image<OutputStorageType>& im, std::string name);
00182 
00183     /** fills up _gxx, _gxy, _gyy from gx and gy 
00184         @author woelk 09/2004 */
00185     void _GradientProducts(const Image<OutputStorageType>& gx,
00186                            const Image<OutputStorageType>& gy);
00187     
00188     
00189     /// allocates _gxx, _gyy, _gxy, _tsgxx, _tsgxy, _tsgyy
00190     ///  and sets InternalMemWidth and _InternalMemHeight
00191     void _AllocInternalMem(const int width, const int height);
00192 
00193     virtual void GetBordersValid_(int &border_x, int &border_y) const;
00194 
00195   }; // class
00196 
00197 } // namespace
00198 
00199 #endif //__StructureTensor_hh__
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends