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

ltiColorEdgesGS.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 .......: ltiColorEdgesGS.h
00027  * authors ....: Pablo Alvarado
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 17.10.2003
00030  * revisions ..: $Id: ltiColorEdgesGS.h,v 1.8 2006/02/07 18:38:04 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_COLOR_EDGES_G_S_H_
00034 #define _LTI_COLOR_EDGES_G_S_H_
00035 
00036 #include "ltiImage.h"
00037 #include "ltiEdgeDetector.h"
00038 #include "ltiGradientFunctor.h"
00039 #include "ltiLinearKernels.h"
00040 #include <limits>
00041 
00042 namespace lti {
00043   /**
00044    * Gevers and Stokman color edges.
00045    *
00046    * This functor implements the color edges detector described in:
00047    *
00048    * Theo Gevers and Harro Stokman, "Classifying Color Edges in Video into
00049    *   Shadow-Geometry, Highlight or Material Transitions", IEEE Trans. on
00050    *   Multimedia, Vol. 5 No. 2, June 2003
00051    *
00052    * Note that it is intended for color images only.  If you use in on
00053    * gray-valued image the results won't be good.
00054    *
00055    * The edgeDetector::parameters::edgeValue attribute will be used to mark
00056    * the material edges, which are usually the ones you really want to have.
00057    *
00058    * This detector is in general slow, since it has to compute many color
00059    * channels and gradients to classify the edges into material, highlight
00060    * or shadow edges.  If you are looking for a faster detector use the
00061    * lti::cannyEdges functor, which uses the lti::colorContrastGradient to
00062    * compute also edges of color images.
00063    */
00064   class colorEdgesGS : public edgeDetector {
00065   public:
00066     /**
00067      * the parameters for the class colorEdgesGS
00068      */
00069     class parameters : public edgeDetector::parameters {
00070     public:
00071       /**
00072        * default constructor
00073        */
00074       parameters();
00075 
00076       /**
00077        * copy constructor
00078        * @param other the parameters object to be copied
00079        */
00080       parameters(const parameters& other);
00081 
00082       /**
00083        * destructor
00084        */
00085       ~parameters();
00086 
00087       /**
00088        * returns name of this type
00089        */
00090       const char* getTypeName() const;
00091 
00092       /**
00093        * copy the contents of a parameters object
00094        * @param other the parameters object to be copied
00095        * @return a reference to this parameters object
00096        */
00097       parameters& copy(const parameters& other);
00098 
00099       /**
00100        * copy the contents of a parameters object
00101        * @param other the parameters object to be copied
00102        * @return a reference to this parameters object
00103        */
00104       parameters& operator=(const parameters& other);
00105 
00106 
00107       /**
00108        * returns a pointer to a clone of the parameters
00109        */
00110       virtual functor::parameters* clone() const;
00111 
00112       /**
00113        * write the parameters in the given ioHandler
00114        * @param handler the ioHandler to be used
00115        * @param complete if true (the default) the enclosing begin/end will
00116        *        be also written, otherwise only the data block will be written.
00117        * @return true if write was successful
00118        */
00119       virtual bool write(ioHandler& handler,const bool complete=true) const;
00120 
00121       /**
00122        * read the parameters from the given ioHandler
00123        * @param handler the ioHandler to be used
00124        * @param complete if true (the default) the enclosing begin/end will
00125        *        be also written, otherwise only the data block will be written.
00126        * @return true if write was successful
00127        */
00128       virtual bool read(ioHandler& handler,const bool complete=true);
00129 
00130 #     ifdef _LTI_MSC_6
00131       /**
00132        * this function is required by MSVC only, as a workaround for a
00133        * very awful bug, which exists since MSVC V.4.0, and still by
00134        * V.6.0 with all bugfixes (so called "service packs") remains
00135        * there...  This method is also public due to another bug, so please
00136        * NEVER EVER call this method directly: use read() instead
00137        */
00138       bool readMS(ioHandler& handler,const bool complete=true);
00139 
00140       /**
00141        * this function is required by MSVC only, as a workaround for a
00142        * very awful bug, which exists since MSVC V.4.0, and still by
00143        * V.6.0 with all bugfixes (so called "service packs") remains
00144        * there...  This method is also public due to another bug, so please
00145        * NEVER EVER call this method directly: use write() instead
00146        */
00147       bool writeMS(ioHandler& handler,const bool complete=true) const;
00148 #     endif
00149 
00150       /**
00151        * Assuming the given image corresponds to a homogeneous color patch,
00152        * the noise standard deviation will be computed as the standard 
00153        * deviation for each channel.
00154        *
00155        * The result will be left in the attribute noiseStdDeviation.
00156        * 
00157        * @param img image containing a homogeneous color patch.
00158        * @param window region of the image to be considered.
00159        * @return true if successful, false otherwise.
00160        */
00161       bool measureNoise(const image& img,
00162                         const rectangle& window =
00163                         rectangle(0,0,
00164                                   std::numeric_limits<int>::max(),
00165                                   std::numeric_limits<int>::max()));
00166 
00167 
00168       // ------------------------------------------------
00169       // the parameters
00170       // ------------------------------------------------
00171 
00172       /**
00173        * Value used to mark the shadow edges. 
00174        *
00175        * Default value 128
00176        */
00177       ubyte shadowEdgeValue;
00178 
00179       /**
00180        * Value used to mark the highlight edges.
00181        * Default value 192
00182        */
00183       ubyte highlightEdgeValue;
00184 
00185       /**
00186        * The algorithm of Gevers and Stokman requires the standard deviation
00187        * for the noise at each channel.
00188        *
00189        * You can compute this standard deviation with the methods
00190        * of this parameter class measureNoise().
00191        *
00192        * The noise standard deviation is computed for the range [0,255].
00193        * 
00194        * Default value: trgbPixel<float>(1.5f,1.5f,1.5f)
00195        */
00196       trgbPixel<float> noiseStdDeviation;
00197 
00198       /**
00199        * Parameters for the gradient functor used to compute single channel
00200        * gradients.
00201        *
00202        * The parameters used are mostly the default ones, but the
00203        * mode is always set to cartesian, since that is the mode
00204        * required by this functor, and the default kernel is the Sobel.
00205        */
00206       gradientFunctor::parameters gradient;
00207 
00208       /**
00209        * Multiplicative factor for the uncertainty.
00210        *
00211        * The gradient value must surpass this factor times the uncertainty in
00212        * order to be considered as edge.
00213        *
00214        * Default value: 3.0
00215        */
00216       float uncertaintyFactor;
00217 
00218     };
00219 
00220     /**
00221      * default constructor
00222      */
00223     colorEdgesGS();
00224 
00225     /**
00226      * Construct a functor using the given parameters
00227      */
00228     colorEdgesGS(const parameters& par);
00229 
00230     /**
00231      * copy constructor
00232      * @param other the object to be copied
00233      */
00234     colorEdgesGS(const colorEdgesGS& other);
00235 
00236     /**
00237      * destructor
00238      */
00239     virtual ~colorEdgesGS();
00240 
00241     /**
00242      * returns the name of this type ("colorEdgesGS")
00243      */
00244     virtual const char* getTypeName() const;
00245 
00246 
00247     /**
00248      * @name Gray valued images.
00249      *
00250      * This methods are supplied for completeness, but since the algorithms
00251      * are designed to work with color images, the results won't be good.
00252      * Use the lti::cannyEdges functor instead.
00253      */
00254     //@{
00255     virtual bool apply(channel8 &srcdest) const;
00256     virtual bool apply(channel &srcdest) const;
00257     virtual bool apply(const channel8 &src, channel8 &dest) const;
00258     virtual bool apply(const channel &src, channel &dest) const; 
00259     virtual bool apply(const channel &src, channel8 &dest) const; 
00260     //@}
00261 
00262 
00263     /**
00264      * @name Color Images
00265      */
00266     //@{
00267     /**
00268      * Compute the edges for the given image and leave the result there too.
00269      * See apply(const image&, image&) for more details.
00270      * @param srcdest input and output image.
00271      * @return true if apply successful or false otherwise.
00272      */
00273     virtual bool apply(image &srcdest) const;
00274 
00275     /**
00276      * Compute the edges for the given image.
00277      * - The material edges will be marked with a gray tone with the value
00278      *   edgeValue given in the parameters object.
00279      * - The shadow edges will be red (with the shadow value given in the 
00280      *   parameters)
00281      * - The highlight edges will be green (with the highlight value given in
00282      *   the parameters.
00283      * The background will be gray, with the value given as noEdgeValue in
00284      * the parameters.
00285      *
00286      * @param src input image
00287      * @param dest colored edges
00288      * @return true if apply successful or false otherwise.
00289      */
00290     virtual bool apply(const image &src, image &dest) const;
00291 
00292 
00293     /**
00294      * Detect the edges in the given color image.
00295      * The edges will belong to one of three classes: material edge, highlight
00296      * edge or shadow edge.  Each one of them will be mark with the 
00297      * corresponding parameter value.
00298      * @see edgeDetector::parameters , parameters
00299      *
00300      * @param src input color image
00301      * @param dest detected edges
00302      * @return true if apply successful or false otherwise.
00303      */
00304     virtual bool apply (const image &src, channel8 &dest) const;
00305     //@}
00306   
00307     /**
00308      * copy data of "other" functor.
00309      * @param other the functor to be copied
00310      * @return a reference to this functor object
00311      */
00312     colorEdgesGS& copy(const colorEdgesGS& other);
00313 
00314     /**
00315      * alias for copy member
00316      * @param other the functor to be copied
00317      * @return a reference to this functor object
00318      */
00319     colorEdgesGS& operator=(const colorEdgesGS& other);
00320 
00321     /**
00322      * returns a pointer to a clone of this functor.
00323      */
00324     virtual functor* clone() const;
00325 
00326     /**
00327      * returns used parameters
00328      */
00329     const parameters& getParameters() const;
00330 
00331   protected:
00332     /**
00333      * Get gradient modula and uncertainty values for each one of them
00334      */
00335     bool getGradients(const channel& red,
00336                       const channel& green,
00337                       const channel& blue,
00338                       const channel& o1,
00339                       const channel& o2,
00340                       const channel& c1,
00341                       const channel& c2,
00342                       const float& stdDevR,
00343                       const float& stdDevG,
00344                       const float& stdDevB,
00345                       const float& stdDevO1,
00346                       const float& stdDevO2,
00347                       const channel& stdDevC1,
00348                       const channel& stdDevC2,
00349                             channel& gradRGB,
00350                             channel& stdDevRGB,
00351                             channel& gradO1O2,
00352                             channel& stdDevO1O2,
00353                             channel& gradC1C2,
00354                             channel& stdDevC1C2) const;
00355 
00356     /**
00357      * Compute the kernels necessary to compute the uncertainty of the
00358      * gradient.
00359      */
00360     bool constructUncertaintyKernels(sepKernel<float>& filterX,
00361                                     sepKernel<float>& filterY) const;
00362     
00363   };
00364 }
00365 
00366 #endif

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