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

ltiClassicEdgeDetector.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  * project ....: LTI-Lib: Image Processing and Computer Vision Library
00025  * file .......: ltiClassicEdgeDetector.h
00026  * authors ....: Arnd Hannemann 
00027  * organization: LTI, RWTH Aachen
00028  * creation ...: 27.11.2003
00029  * revisions ..: $Id: ltiClassicEdgeDetector.h,v 1.6 2006/02/07 18:36:51 ltilib Exp $
00030  */
00031 
00032 // include only once
00033 #ifndef _LTI_SOBEL_EDGES_H_
00034 #define _LTI_SOBEL_EDGES_H_
00035 
00036 #include "ltiEdgeDetector.h"
00037 #include "ltiNonMaximaSuppression.h"
00038 #include "ltiThresholding.h"
00039 #include "ltiConvolution.h"
00040 #include "ltiGradientFunctor.h"
00041 
00042 
00043 namespace lti {
00044   /**
00045   * This class implements simple standard edgedectors like Sobel.
00046   * It uses a gradient functor to create a gradient magnitude.
00047   * Furthermore it uses nonMaximaSuppression or thresholding 
00048   * to extract the edges.
00049   *
00050   * \code
00051   * #include ltiClassicEdgeDetector.h
00052   *
00053   * channel src;
00054   * channel8 edges;
00055   *
00056   * classicEdgeDetector::parameters cedPar;
00057   * // using thresholding instead of standard nonMaximaSuppression
00058   * thresholding::parameters tPar;
00059   * tPar.highThreshold = 0.8;
00060   * thresholding t(tPar);
00061   *
00062   * cedPar.setMaximaSearchMethod(t);
00063   * cedPar.gradientParameters.kernelType = gradientFunctor::parameters::Prewitt;
00064   *
00065   * // This has NO effect, because setMaximaSearchMethod was used
00066   * // so the thresholding functor was copied
00067   * tPar.highTreshold = 0.5;
00068   * t.setParameters(tPar);
00069   *
00070   * classicEdgeDetector ced(cedPar);
00071   *
00072   * ced.apply(src,edges);
00073   *
00074   * \endcode
00075   *
00076   * @ingroup gEdgeCorner
00077   */
00078   class classicEdgeDetector : public edgeDetector {
00079   public:
00080 
00081     /** 
00082      * The parameters for the class classicEdgeDetector.
00083      */
00084     class parameters : public edgeDetector::parameters {
00085     // there are protected attributes which are used by classicEdgeDetector
00086       friend class classicEdgeDetector;
00087     public:
00088 
00089 
00090       /**
00091        * enum type for maxima search method
00092        */
00093       enum eMaximaSearchMethod {
00094         NonMaximaSuppression, /**< use an instance of nonMaximaSuprression to extract edges */
00095         Thresholding /**< use an instance of thresholding to extract edges */
00096       };
00097 
00098       /**
00099        * default constructor
00100        */
00101       parameters();
00102 
00103       /**
00104        * copy constructor
00105        * @param other the parametrs object to copied
00106        */
00107       parameters(const parameters& other);
00108 
00109       /**
00110        * destructor
00111        */
00112       ~parameters();
00113 
00114       /** 
00115        * returns name of this type 
00116        * @return string "ltiClassicEdgeDetector::parameters"
00117        */
00118       const char* getTypeName() const;
00119 
00120       /**
00121        * copy the contents of a parameters object
00122        * @param other the parameters object to be copied
00123        * @return a reference to this parameters object
00124        */
00125       parameters& copy(const parameters& other);
00126 
00127       /**
00128        * Copy the contents of a parameters object
00129        * @param other the parameters object to be copied
00130        * @return a reference to this parameters object
00131        */
00132       parameters& operator=(const parameters& other);
00133 
00134 
00135       /**
00136        * Returns a pointer to a clone of the parameters
00137        */
00138       virtual functor::parameters* clone() const;
00139 
00140       /**
00141        * Write the parameters in the given ioHandler.
00142        * \b Note: The parameters of the used maxima search method will 
00143        * \b NOT be saved!
00144        * @param handler the ioHandler to be used
00145        * @param complete if true (the default) the enclosing begin/end will
00146        *        be also written, otherwise only the data block will be written.
00147        * @return true if write was successful
00148        */
00149       virtual bool write(ioHandler& handler,const bool complete=true) const;
00150 
00151       /**
00152        * Read the parameters from the given ioHandler
00153        * \b Note: The parameters of the used maxima search method will 
00154        * \b NOT be read!
00155        * @param handler the ioHandler to be used
00156        * @param complete if true (the default) the enclosing begin/end will
00157        *        be also written, otherwise only the data block will be written.
00158        * @return true if write was successful
00159        */
00160       virtual bool read(ioHandler& handler,const bool complete=true);
00161 
00162 #     ifdef _LTI_MSC_6
00163       /**
00164        * This function is required by MSVC only, as a workaround for a
00165        * very awful bug, which exists since MSVC V.4.0, and still by
00166        * V.6.0 with all bugfixes (so called "service packs") remains
00167        * there...  This method is also public due to another bug, so please
00168        * NEVER EVER call this method directly: use read() instead
00169        */
00170       bool readMS(ioHandler& handler,const bool complete=true);
00171 
00172       /**
00173        * This function is required by MSVC only, as a workaround for a
00174        * very awful bug, which exists since MSVC V.4.0, and still by
00175        * V.6.0 with all bugfixes (so called "service packs") remains
00176        * there...  This method is also public due to another bug, so please
00177        * NEVER EVER call this method directly: use write() instead
00178        */
00179       bool writeMS(ioHandler& handler,const bool complete=true) const;
00180 #     endif
00181 
00182      
00183       // ------------------------------------------------
00184       // the parameters
00185       // ------------------------------------------------
00186 
00187 
00188 
00189       /**
00190        * Parameters of gradientFunctor which is used to compute the Gradients.
00191        *
00192        * Default value: parameters with KernelType = Sobel.
00193        */
00194       gradientFunctor::parameters gradientParameters;
00195 
00196       /** 
00197        * Sets a new maxima search method. A copy of the functor will be
00198        * done (so it is useless to change the parameters of the given
00199        * functor instance, because the internal functor will never notice
00200        * the changes done to its "parent").
00201        *
00202        * Attention:
00203        * some parameters of the functor will be overwritten 
00204        * in classicEdgeDetector::setParameters(const functor::parameters& theParam);
00205        */
00206       void setMaximaSearchMethod(const thresholding& thresholder);
00207 
00208       /** 
00209        * Sets a new maxima search method. A copy of the functor will be
00210        * done (so it is useless to change the parameters of the given 
00211        * functor instance, because the internal functor will never notice
00212        * the changes done to its "parent").
00213        *       
00214        * Attention:
00215        * some parameters of the functor will be overwritten 
00216        * in classicEdgeDetector::setParameters(const functor::parameters& theParam);
00217        */
00218       void setMaximaSearchMethod(const nonMaximaSuppression& suppressor);
00219 
00220       /**
00221        * Sets a new maxima search method. The functor which is passed here as
00222        * an argument must have been allocated with new; it must not be 
00223        * a local variable. On destruction of the parameters object, the
00224        * instance of the given functor will be deleted, i.e. this parameters
00225        * instance will be responsible for the memory managment of the object.
00226        *
00227        * \b Attention:
00228        * some parameters of the functor will be overwritten 
00229        * in classicEdgeDetector::setParameters();
00230        */
00231       void attachMaximaSearchMethod(thresholding* thresholder);
00232 
00233       /**
00234        * Sets a new maxima search method. The functor which is passed here as
00235        * an argument must have been allocated with new; it must not be 
00236        * a local variable. On destruction of the parameters object, the
00237        * instance of the given functor will be deleted, i.e. this parameters
00238        * instance will be responsible for the memory managment of the object.
00239        *
00240        * \b Attention:
00241        * some parameters of the functor will be overwritten 
00242        * in classicEdgeDetector::setParameters();
00243        */
00244       void attachMaximaSearchMethod(nonMaximaSuppression* suppressor);
00245 
00246 
00247       /**
00248        * Sets a new maxima search method. The functor which is passed here as
00249        * an argument is not deleted by the parameters object, the caller
00250        * must ensure that threre are no memory leaks.
00251        *   
00252        * \b Attention:
00253        * some parameters of the functor will be overwritten 
00254        * in classicEdgeDetector::setParameters();
00255        */
00256       void useExternalMaximaSearchMethod(thresholding* thresholder);
00257 
00258       /**
00259        * Sets a new maxima search method. The functor which is passed here as
00260        * an argument is not deleted by the parameters object, the caller
00261        * must ensure that threre are no memory leaks.
00262        *
00263        * \b Attention:
00264        * some parameters of the functor will be overwritten 
00265        * in classicEdgeDetector::setParameters();
00266        */
00267       void useExternalMaximaSearchMethod(nonMaximaSuppression* suppressor);
00268 
00269     protected:
00270 
00271       /** 
00272        * Method which is used to get the edges out of the gradient.
00273        * Default value: nonMaximaSuppression
00274        */
00275       eMaximaSearchMethod maximaSearchMethod;
00276 
00277       /**
00278        * non maxima suppression functor.
00279        * 
00280        * Default value: default nonMaximaSuppression
00281        */
00282       nonMaximaSuppression* suppressor;
00283 
00284       /**
00285        * thresholding functor
00286        *
00287        * Default value: 0
00288        */
00289       thresholding* thresholder;
00290 
00291       /**
00292        * Flag used to indicate if the local maxima search method functor
00293        * must be deleted by this object or not (just pointing to some
00294        * external instance...)
00295        */
00296       bool destroyFunctor;
00297 
00298 
00299 
00300     }; // parameters
00301 
00302     /** 
00303      * default constructor
00304      */
00305     classicEdgeDetector();
00306 
00307    /**
00308      * Construct a functor using the given parameters
00309      */
00310     classicEdgeDetector(const parameters& par);
00311 
00312     /**
00313      * Copy constructor
00314      * @param other the object to be copied
00315      */
00316     classicEdgeDetector(const classicEdgeDetector& other);
00317 
00318     /**
00319      * Destructor
00320      */
00321     virtual ~classicEdgeDetector();
00322 
00323 
00324     /** 
00325      * returns the name of this type ("classicEdgeDetector")
00326      */
00327     virtual const char* getTypeName() const;
00328 
00329     /**
00330      * Copy data of "other" functor.
00331      * @param other the functor to be copied
00332      * @return a reference to this functor object
00333      */
00334     classicEdgeDetector& copy(const classicEdgeDetector& other);
00335 
00336     /**
00337      * Alias for copy member
00338      * @param other the functor to be copied
00339      * @return a reference to this functor object
00340      */
00341     classicEdgeDetector& operator=(const classicEdgeDetector& other);
00342 
00343     /**
00344      * Returns a pointer to a clone of this functor.
00345      */
00346     virtual functor* clone() const;
00347 
00348     /**
00349      * returns used parameters
00350      */
00351     const parameters& getParameters() const;
00352 
00353     /** 
00354      * operates on the given %parameters
00355      * @param src channel with the Source data.
00356      * @param edges channel where the result will be left.
00357      * @return true if apply successful or false otherwise.   
00358      */
00359 
00360     virtual bool apply(const channel& src, channel8& edges) const;
00361 
00362 
00363     /**
00364      * operates on the given %parameters
00365      * @param srcdest channel with the source data. The result will be left 
00366      *                here too.
00367      * @return true if apply successful or false otherwise.   
00368      */
00369     virtual bool apply(channel8& srcdest) const;
00370 
00371 
00372     /**
00373      * update functor's parameters.
00374      * This member initializes some internal data depending on the 
00375      * parameter set.
00376      *
00377      * if using Thresholding as maxima search method:
00378      * - thresholding::parameters::inRegionValue will be overwritten
00379      *   by edgeDetector::parameters::edgeValue (divided by 255) 
00380      * - thresholding::parameters::outRegionValue will be overwritten
00381      *   by edgeDetector::parameters::noEdgeValue (divided by 255)
00382      * - thresholding::parameters::keepInRegion will always be set
00383      *   to false
00384      * - thresholding::parameters::keepOutRegion will always be set
00385      *   to false
00386      *
00387      * if using nonMaximaSuppression as maxima search method:
00388      * - nonMaximaSuppression::parameters.edgeValue will be
00389      *   overwritten by edgeDetector::parameters::edgeValue
00390      * - nonMaximaSuppression::parameters.background will be
00391      *   overwritten by edgeDetector::parameters::noEdgeValue
00392      * - nonMaximaSuppression::parameters.checkAngles will always 
00393      *   be set to false
00394      *
00395      * @param theParam the parameters which should be set
00396      * @return true if successful, false otherwise
00397      */
00398     virtual bool updateParameters(const parameters& theParam);
00399 
00400 
00401   protected:
00402     /** functor which is used to compute the gradient */
00403     gradientFunctor gradienter;
00404  
00405   };
00406 }
00407 
00408 #endif

Generated on Sat Apr 10 15:25:13 2010 for LTI-Lib by Doxygen 1.6.1