LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiSelective2DConvolution.h

00001 /*
00002  * Copyright (C) 2003, 2004, 2005, 2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  * This file is part of the LTI-Computer Vision Library (LTI-Lib)
00006  *
00007  * The LTI-Lib is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License (LGPL)
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * The LTI-Lib is distributed in the hope that it will be
00013  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00014  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with the LTI-Lib; see the file LICENSE.  If
00019  * not, write to the Free Software Foundation, Inc., 59 Temple Place -
00020  * Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 
00024 /*--------------------------------------------------------------------
00025  * project ....: LTI-Lib: Image Processing and Computer Vision Library
00026  * file .......: ltiSelective2DConvolution.h
00027  * authors ....: Henning Luepschen
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 10.9.2003
00030  * revisions ..: $Id: ltiSelective2DConvolution.h,v 1.8 2008/08/17 22:20:12 alvarado Exp $
00031  */
00032 
00033 #ifndef _LTI_SELECTIVE2_D_CONVOLUTION_H_
00034 #define _LTI_SELECTIVE2_D_CONVOLUTION_H_
00035 
00036 
00037 #include "ltiLinearKernels.h" 
00038 #include "ltiFilter.h"
00039 #include "ltiPointList.h"
00040 
00041 namespace lti {
00042   
00043   /**
00044    *  This modifier is used to convolve individual points of
00045    *  a given channel with a arbitrary kernel2D<float> (e.g. a
00046    *  gaussian kernel like the one in "ltiGaussKernels.h").
00047    *  
00048    *  The points to be convolved may be given in a mask channel,
00049    *  as pointList, or as individual points.
00050    *
00051    *  TODO: The boundaryType is not checked yet!!! Border points 
00052    *  cannot and will not be convolved.
00053    *
00054    *  Example of determinating the GradX and GradY values
00055    *  for a given channel src using a mask channel:
00056    *  \code
00057    *
00058    *  #include "ltiGradientKernels.h"
00059    *  #include "ltiSelective2DConvolution.h"
00060    *  #include "ltiImage.h"
00061    *  
00062    *  lti::channel src, mask;
00063    *  .
00064    *  .
00065    *  .
00066    *  //Fill mask and src channel as necessary
00067    *  .
00068    *  .
00069    *  .
00070    *
00071    *  lti::gradientKernelX<float> myKernelX(5);   // Optimal Gradient 5x5 kernels
00072    *  lti::gradientKernelY<float> myKernelY(5);   // They both are separable.
00073    *  lti::kernel2D<float> myKernel2D;            // We need genuine 2D kernels, not separable ones.
00074    *
00075    *  myKernel2D.castFrom(myKernelX);             // So, we create one :-)
00076    *  lti::selective2DConvolution mySelConvX(myKernel2D);
00077    *
00078    *  myKernel2D.castFrom(myKernelY);
00079    *  lti::selective2DConvolution mySelConvY;
00080    *  mySelConvY.setKernel(myKernel2D);           // Another way of setting an arbitrary kernel.
00081    *
00082    *  lti::channel GradX,GradY;                   // Where to put the results
00083    *  
00084    *  mySelConvX.apply(src,GradX,mask);           // All points in the mask channel having a value
00085    *  mySelConvY.apply(src,GradY,mask);           // !=0.0f are being convolved.
00086    *  \endcode
00087    *  
00088    *  Now, we have the results in the GradX and GradY channel.
00089    *
00090    */
00091   class selective2DConvolution : public filter {
00092   public:
00093     /**
00094      * the parameters for the class selective2DConvolution
00095      */
00096     class parameters : public filter::parameters {
00097     public:
00098       /**
00099        * default constructor
00100        */
00101       parameters();
00102 
00103       /**
00104        * copy constructor
00105        * @param other the parameters object to be copied
00106        */
00107       parameters(const parameters& other);
00108 
00109       /**
00110        * destructor
00111        */
00112       ~parameters();
00113 
00114       /**
00115        * returns name of this type
00116        */
00117       const char* getTypeName() const;
00118 
00119       /**
00120        * copy the contents of a parameters object
00121        * @param other the parameters object to be copied
00122        * @return a reference to this parameters object
00123        */
00124       parameters& copy(const parameters& other);
00125 
00126       /**
00127        * copy the contents of a parameters object
00128        * @param other the parameters object to be copied
00129        * @return a reference to this parameters object
00130        */
00131       parameters& operator=(const parameters& other);
00132 
00133 
00134       /**
00135        * returns a pointer to a clone of the parameters
00136        */
00137       virtual functor::parameters* clone() const;
00138 
00139       /**
00140        * returns the kernel2D<float> in use.  If it is not set yet, an
00141        * lti::invalidParameters exception will be thrown
00142        * @return a const reference to the filter kernel.
00143        */
00144       const kernel2D<float>& getKernel2D() const;
00145 
00146       /**
00147        * sets the filter kernel2D<float> to be used.
00148        * A copy of the given %parameter will be made!
00149        * @param aKernel the filter kernel to be used
00150        */
00151       void setKernel2D(const kernel2D<float>& aKernel);
00152 
00153 
00154 
00155       /**
00156        * write the parameters in the given ioHandler
00157        * @param handler the ioHandler to be used
00158        * @param complete if true (the default) the enclosing begin/end will
00159        *        be also written, otherwise only the data block will be written.
00160        * @return true if write was successful
00161        */
00162       virtual bool write(ioHandler& handler,const bool complete=true) const;
00163 
00164       /**
00165        * read the parameters from the given ioHandler
00166        * @param handler the ioHandler to be used
00167        * @param complete if true (the default) the enclosing begin/end will
00168        *        be also written, otherwise only the data block will be written.
00169        * @return true if write was successful
00170        */
00171       virtual bool read(ioHandler& handler,const bool complete=true);
00172 
00173 #     ifdef _LTI_MSC_6
00174       /**
00175        * this function is required by MSVC only, as a workaround for a
00176        * very awful bug, which exists since MSVC V.4.0, and still by
00177        * V.6.0 with all bugfixes (so called "service packs") remains
00178        * there...  This method is also public due to another bug, so please
00179        * NEVER EVER call this method directly: use read() instead
00180        */
00181       bool readMS(ioHandler& handler,const bool complete=true);
00182 
00183       /**
00184        * this function is required by MSVC only, as a workaround for a
00185        * very awful bug, which exists since MSVC V.4.0, and still by
00186        * V.6.0 with all bugfixes (so called "service packs") remains
00187        * there...  This method is also public due to another bug, so please
00188        * NEVER EVER call this method directly: use write() instead
00189        */
00190       bool writeMS(ioHandler& handler,const bool complete=true) const;
00191 #     endif
00192 
00193       // ------------------------------------------------
00194       // the parameters
00195       // ------------------------------------------------
00196 
00197       //TODO: comment the parameters of your functor
00198       // If you add more parameters manually, do not forget to do following:
00199       // 1. indicate in the default constructor the default values
00200       // 2. make sure that the copy member also copy your new parameters
00201       // 3. make sure that the read and write members also read and
00202       //    write your parameters
00203       
00204     protected:
00205       /**
00206        * pointer to the filter kernel2D copy
00207        */
00208       kernel2D<float>* kernel2D_;
00209 
00210     };
00211 
00212     /**
00213      * default constructor
00214      */
00215     selective2DConvolution();
00216 
00217     /**
00218      * Construct a functor using the given parameters
00219      */
00220     selective2DConvolution(const parameters& par);
00221 
00222     /**
00223      * Construct a selective2DConvolution functor with a parameters set
00224      * which includes the given filter kernel.
00225      */
00226     selective2DConvolution(const kernel2D<float>& aKernel);
00227 
00228     /**
00229      * copy constructor
00230      * @param other the object to be copied
00231      */
00232     selective2DConvolution(const selective2DConvolution& other);
00233 
00234     /**
00235      * destructor
00236      */
00237     virtual ~selective2DConvolution();
00238 
00239     /**
00240      * returns the name of this type ("selective2DConvolution")
00241      */
00242     virtual const char* getTypeName() const;
00243     
00244 
00245     /**
00246      * operates on a copy of the given %parameters.
00247      * @param src channel with the source data.
00248      * @param mask channel with the mask data. All points in the src channel
00249      * having a corresponding point in the mask channel
00250      * with values different from 0 are convolved with the given kernel.
00251      * @param dest channel where the result will be left.
00252      * @return true if apply successful or false otherwise.
00253      */ 
00254     bool apply(const channel& src, channel& dest, const channel& mask) const;
00255  
00256     /**
00257      * operates on a copy of the given %parameters. Convolves only
00258      * one specific point in the source channel with a given kernel. The
00259      * result can be found in the result variable.
00260      * @param src channel with the source data.
00261      * @param result The result of the convolution can be found here.
00262      * @param column Column of the convolved point.
00263      * @param row Row of the convolved point
00264      * @return true if apply successful or false otherwise.
00265      */
00266     bool apply(const channel& src, float& result, const int row, const int column) const;
00267 
00268     /**
00269      * operates on a copy of the given %parameters. Convolves only
00270      * one specific point in the source channel with a given kernel. The
00271      * result will be written into a destination channel.
00272      * @param src channel with the source data.
00273      * @param column Column of the convolved point.
00274      * @param row Row of the convolved point
00275      * @param dest channel where the result will be left.
00276      * @return true if apply successful or false otherwise.
00277      */
00278     bool apply(const channel& src, channel& dest, const int row, const int column) const;
00279 
00280     /**
00281      * operates on a copy of the given %parameters. Convolves only
00282      * one specific point in the source channel with a given kernel.
00283      * @param src channel with the source data.
00284      * @param result The result of the convolution can be found here.
00285      * @param thePoint Convolved point.
00286      * @return true if apply successful or false otherwise.
00287      */ 
00288     bool apply(const channel& src, float& result, const point& thePoint) const;
00289 
00290     /**
00291      * operates on a copy of the given %parameters. Convolves only
00292      * one specific point in the source channel with a given kernel. The
00293      * result will be written into a destination channel.
00294      * @param src channel with the source data.
00295      * @param thePoint Convolved point.
00296      * @param dest channel where the result will be left.
00297      * @return true if apply successful or false otherwise.
00298      */ 
00299     bool apply(const channel& src, channel& dest, const point& thePoint) const;
00300     
00301     /**
00302      * operates on a copy of the given %parameters. Convolves all points
00303      * of a pointlist in the source channel with a given kernel. The result
00304      * will be written into a destination channel.
00305      * @param src channel with the source data.
00306      * @param dest channel where the result will be left.
00307      * @param thePointList Given pointlist. All points of the list are 
00308      *        convolved.
00309      * @return true if apply successful or false otherwise.
00310      */
00311     bool apply(const channel& src, channel& dest, 
00312                const pointList& thePointList) const;
00313 
00314     /**
00315      * copy data of "other" functor.
00316      * @param other the functor to be copied
00317      * @return a reference to this functor object
00318      */
00319     selective2DConvolution& copy(const selective2DConvolution& other);
00320 
00321     /**
00322      * alias for copy member
00323      * @param other the functor to be copied
00324      * @return a reference to this functor object
00325      */
00326     selective2DConvolution& operator=(const selective2DConvolution& other);
00327 
00328     /**
00329      * returns a pointer to a clone of this functor.
00330      */
00331     virtual functor* clone() const;
00332 
00333     /**
00334      * returns used parameters
00335      */
00336     const parameters& getParameters() const;
00337 
00338     /**
00339      * shortcut to set the filter kernel2D in the functor parameters.
00340      * The other parameters remain unchanged.
00341      */
00342     void setKernel2D(const kernel2D<float>& aKernel);
00343 
00344 
00345     //TODO: comment the attributes of your functor
00346     // If you add more attributes manually, do not forget to do following:
00347     // 1. indicate in the default constructor the default values
00348     // 2. make sure that the copy member also copy your new attributes, or
00349     //    to ensure there, that these attributes are properly initialized.
00350 
00351   };
00352 }
00353 
00354 #endif

Generated on Sat Apr 10 15:26:08 2010 for LTI-Lib by Doxygen 1.6.1