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

ltiRegionsPolygonizer.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 .......: ltiRegionsPolygonizer.h
00027  * authors ....: Pablo Alvarado
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 1.10.2003
00030  * revisions ..: $Id: ltiRegionsPolygonizer.h,v 1.7 2006/02/08 11:46:07 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_REGIONS_POLYGONIZER_H_
00034 #define _LTI_REGIONS_POLYGONIZER_H_
00035 
00036 #include "ltiImage.h"
00037 #include "ltiPolygonPoints.h"
00038 #include "ltiFastRelabeling.h"
00039 #include "ltiFunctor.h"
00040 
00041 namespace lti {
00042   /**
00043    * This functor takes a labeled mask and for each region therein it
00044    * computes a polygon approximation of its contour.  Additionally,
00045    * it ensures that those pixels in the contour with at least two
00046    * neighbors of different classes will be taken as polygon vertices.
00047    *
00048    * 
00049    */
00050   class regionsPolygonizer : public functor {
00051   public:
00052     /**
00053      * the parameters for the class regionsPolygonizer
00054      */
00055     class parameters : public functor::parameters {
00056     public:
00057       /**
00058        * default constructor
00059        */
00060       parameters();
00061 
00062       /**
00063        * copy constructor
00064        * @param other the parameters object to be copied
00065        */
00066       parameters(const parameters& other);
00067 
00068       /**
00069        * destructor
00070        */
00071       ~parameters();
00072 
00073       /**
00074        * returns name of this type
00075        */
00076       const char* getTypeName() const;
00077 
00078       /**
00079        * copy the contents of a parameters object
00080        * @param other the parameters object to be copied
00081        * @return a reference to this parameters object
00082        */
00083       parameters& copy(const parameters& other);
00084 
00085       /**
00086        * copy the contents of a parameters object
00087        * @param other the parameters object to be copied
00088        * @return a reference to this parameters object
00089        */
00090       parameters& operator=(const parameters& other);
00091 
00092 
00093       /**
00094        * returns a pointer to a clone of the parameters
00095        */
00096       virtual functor::parameters* clone() const;
00097 
00098       /**
00099        * write the parameters in the given ioHandler
00100        * @param handler the ioHandler to be used
00101        * @param complete if true (the default) the enclosing begin/end will
00102        *        be also written, otherwise only the data block will be written.
00103        * @return true if write was successful
00104        */
00105       virtual bool write(ioHandler& handler,const bool complete=true) const;
00106 
00107       /**
00108        * read the parameters from the given ioHandler
00109        * @param handler the ioHandler to be used
00110        * @param complete if true (the default) the enclosing begin/end will
00111        *        be also written, otherwise only the data block will be written.
00112        * @return true if write was successful
00113        */
00114       virtual bool read(ioHandler& handler,const bool complete=true);
00115 
00116 #     ifdef _LTI_MSC_6
00117       /**
00118        * this function is required by MSVC only, as a workaround for a
00119        * very awful bug, which exists since MSVC V.4.0, and still by
00120        * V.6.0 with all bugfixes (so called "service packs") remains
00121        * there...  This method is also public due to another bug, so please
00122        * NEVER EVER call this method directly: use read() instead
00123        */
00124       bool readMS(ioHandler& handler,const bool complete=true);
00125 
00126       /**
00127        * this function is required by MSVC only, as a workaround for a
00128        * very awful bug, which exists since MSVC V.4.0, and still by
00129        * V.6.0 with all bugfixes (so called "service packs") remains
00130        * there...  This method is also public due to another bug, so please
00131        * NEVER EVER call this method directly: use write() instead
00132        */
00133       bool writeMS(ioHandler& handler,const bool complete=true) const;
00134 #     endif
00135 
00136       // ------------------------------------------------
00137       // the parameters
00138       // ------------------------------------------------
00139 
00140       /**
00141        * When approximating a contour with a polygon, this is the maximum
00142        * deviation allowed between the polygon sides and the contour.
00143        *
00144        * Default value: 1
00145        */
00146       double maxPixelDistance;
00147 
00148       /**
00149        * Detect region changes.
00150        *
00151        * If true, this flag indicates that the polygon approximation must
00152        * contain as vertices those points where the neighbor region change,
00153        * independently if the polygon approximation without them would also
00154        * be good enough.  
00155        *
00156        * If false, only the border points of the region will
00157        * be considered, ignoring the background.
00158        *
00159        * Default value: true
00160        */
00161       bool detectNeighbors;
00162     };
00163 
00164     /**
00165      * default constructor
00166      */
00167     regionsPolygonizer();
00168 
00169     /**
00170      * Construct a functor using the given parameters
00171      */
00172     regionsPolygonizer(const parameters& par);
00173 
00174     /**
00175      * copy constructor
00176      * @param other the object to be copied
00177      */
00178     regionsPolygonizer(const regionsPolygonizer& other);
00179 
00180     /**
00181      * destructor
00182      */
00183     virtual ~regionsPolygonizer();
00184 
00185     /**
00186      * returns the name of this type ("regionsPolygonizer")
00187      */
00188     virtual const char* getTypeName() const;
00189 
00190     /**
00191      * This apply method computes for each region in src a polygon
00192      * representation of its border.
00193      *
00194      * @param src input labeled mask
00195      * @param maxLabel maximum label in the input mask, (if you don't know it,
00196      *                 give for example src.maximum())
00197      * @param polygons polygon representation of each region indexed by their
00198      *                id.
00199      *
00200      * @return true if apply successful or false otherwise.
00201      */
00202     bool apply(const matrix<int>& src,
00203                const int maxLabel,
00204                      std::vector<polygonPoints>& polygons) const;
00205 
00206 
00207     /**
00208      * Computes for each region in src:
00209      * - approximating polygon 
00210      * - border 
00211      * - at the border points the label of the neighbor region.
00212      *
00213      * The labeled mask given in \a src \b must contain only connected
00214      * regions, identified by an unique integer id, as given by functors like
00215      * lti::fastRelabeling.
00216      *
00217      * The maximum labeld in \a src must be given to save some time if
00218      * possible.
00219      *
00220      * @param src input labeled mask
00221      * @param maxLabel maximum label in the input mask, (if you don't know it,
00222      *                 give for example src.maximum())
00223      * @param polygons polygon representation of each region indexed by their
00224      *                id.
00225      * @param borders  border points for each region.
00226      * @param neighbors matrix containing for each border pixel the id of
00227      *                  a neighbor region and for all other pixels the
00228      *                  own region id.
00229      * @return true if apply successful or false otherwise.
00230      */
00231     bool apply(const matrix<int>& src,
00232                const int maxLabel,
00233                      std::vector<polygonPoints>& polygons,
00234                      std::vector<borderPoints>& borders,
00235                      matrix<int>& neighbors) const;
00236 
00237     /**
00238      * copy data of "other" functor.
00239      * @param other the functor to be copied
00240      * @return a reference to this functor object
00241      */
00242     regionsPolygonizer& copy(const regionsPolygonizer& other);
00243 
00244     /**
00245      * alias for copy member
00246      * @param other the functor to be copied
00247      * @return a reference to this functor object
00248      */
00249     regionsPolygonizer& operator=(const regionsPolygonizer& other);
00250 
00251     /**
00252      * returns a pointer to a clone of this functor.
00253      */
00254     virtual functor* clone() const;
00255 
00256     /**
00257      * returns used parameters
00258      */
00259     const parameters& getParameters() const;
00260 
00261   };
00262 }
00263 
00264 #endif

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