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

ltiGeometricFeaturesFromMask.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 .......: ltiGeometricFeaturesFromMask.h
00027  * authors ....: Dorothee Finck
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 11.6.2003
00030  * revisions ..: $Id: ltiGeometricFeaturesFromMask.h,v 1.13 2006/02/08 11:11:50 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_GEOMETRIC_FEATURES_FROM_MASK_H_
00034 #define _LTI_GEOMETRIC_FEATURES_FROM_MASK_H_
00035 
00036 #include "ltiFastRelabeling.h"
00037 #include "ltiGeometricFeatureGroup.h"
00038 
00039 namespace lti {
00040 
00041   /**
00042    * This functor takes a mask (labeled or not), where it is assumed that
00043    * a region must be connected or not and reassigned labels to them in
00044    * a way that each connected region gets its own label.
00045    *
00046    * Additionally the minimum bounding rectangle or geometric features of the
00047    * labeled objects are computed. Close objects are merged if requested. To
00048    * ensure fast merging two objects are close if their surrounding rectangles
00049    * are close.
00050    * CAVEAT: 
00051    * 1) Sorting of the merged objects by their size does not work if the circumscribing 
00052    *    rectangles are returned only.
00053    */
00054   class geometricFeaturesFromMask : public fastRelabeling {
00055   public:
00056 
00057     /**
00058      * the parameters for the class geometricFeaturesFromMask
00059      */
00060     class parameters : public fastRelabeling::parameters {
00061     public:
00062       /**
00063        * default constructor
00064        */
00065       parameters();
00066 
00067       /**
00068        * copy constructor
00069        * @param other the parameters object to be copied
00070        */
00071       parameters(const parameters& other);
00072 
00073       /**
00074        * destructor
00075        */
00076       ~parameters();
00077 
00078       /**
00079        * returns name of this type
00080        */
00081       const char* getTypeName() const;
00082 
00083       /**
00084        * copy the contents of a parameters object
00085        * @param other the parameters object to be copied
00086        * @return a reference to this parameters object
00087        */
00088       parameters& copy(const parameters& other);
00089 
00090       /**
00091        * copy the contents of a parameters object
00092        * @param other the parameters object to be copied
00093        * @return a reference to this parameters object
00094        */
00095       parameters& operator=(const parameters& other);
00096 
00097 
00098       /**
00099        * returns a pointer to a clone of the parameters
00100        */
00101       virtual functor::parameters* clone() const;
00102 
00103       /**
00104        * write the parameters in the given ioHandler
00105        * @param handler the ioHandler to be used
00106        * @param complete if true (the default) the enclosing begin/end will
00107        *        be also written, otherwise only the data block will be written.
00108        * @return true if write was successful
00109        */
00110       virtual bool write(ioHandler& handler,const bool complete=true) const;
00111 
00112       /**
00113        * read the parameters from 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 read(ioHandler& handler,const bool complete=true);
00120 
00121 #     ifdef _LTI_MSC_6
00122       /**
00123        * this function is required by MSVC only, as a workaround for a
00124        * very awful bug, which exists since MSVC V.4.0, and still by
00125        * V.6.0 with all bugfixes (so called "service packs") remains
00126        * there...  This method is also public due to another bug, so please
00127        * NEVER EVER call this method directly: use read() instead
00128        */
00129       bool readMS(ioHandler& handler,const bool complete=true);
00130 
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 write() instead
00137        */
00138       bool writeMS(ioHandler& handler,const bool complete=true) const;
00139 #     endif
00140 
00141       // ------------------------------------------------
00142       // the parameters
00143       // ------------------------------------------------
00144 
00145       /**
00146        * If this value is greater than 0 and sortSize is true, only the n biggest
00147        * objects will be processed and all other objects are suppressed.
00148        *
00149        * Default: 0
00150        */
00151       int nBest;
00152 
00153       /**
00154        * If the number of pixels of an object after merging
00155        * is less than the minimumMergedObjectSize, it will be
00156        * assigned to the background label (0). 
00157        * The inherited parameter minimumObjectSize applies to objects
00158        * before merging.
00159        *
00160        * Default value: 1 (i.e. consider all objects)
00161        */
00162       int minimumMergedObjectSize;
00163 
00164       /**
00165        * The minimum distance in x and y direction between labeled regions
00166        * that belong to the same object. The labeled regions are approximated
00167        * by rectangles and thus the distances are computed between those
00168        * rectangles along the x and y axis.
00169        *
00170        * Default: (0,0) (i.e. rectangles must overlap)
00171        */
00172       point minimumDistance;
00173 
00174       /**
00175        * The objects may be merged if close (true) or not (false).
00176        *
00177        * Default: false
00178        */
00179       bool merge;
00180     };
00181 
00182     /**
00183      * default constructor
00184      */
00185     geometricFeaturesFromMask();
00186 
00187     /**
00188      * Construct a functor using the given parameters
00189      */
00190     geometricFeaturesFromMask(const parameters& par);
00191 
00192     /**
00193      * copy constructor
00194      * @param other the object to be copied
00195      */
00196     geometricFeaturesFromMask(const geometricFeaturesFromMask& other);
00197 
00198     /**
00199      * destructor
00200      */
00201     virtual ~geometricFeaturesFromMask();
00202 
00203     /**
00204      * returns the name of this type ("geometricFeaturesFromMask")
00205      */
00206     virtual const char* getTypeName() const;
00207 
00208     /**
00209      * copy data of "other" functor.
00210      * @param other the functor to be copied
00211      * @return a reference to this functor object
00212      */
00213     geometricFeaturesFromMask& copy(const geometricFeaturesFromMask& other);
00214 
00215     /**
00216      * alias for copy member
00217      * @param other the functor to be copied
00218      * @return a reference to this functor object
00219      */
00220     geometricFeaturesFromMask& operator=(const geometricFeaturesFromMask& other);
00221 
00222     /**
00223      * returns a pointer to a clone of this functor.
00224      */
00225     virtual functor* clone() const;
00226 
00227     /**
00228      * returns used parameters
00229      */
00230     const parameters& getParameters() const;
00231 
00232     /**
00233      * apply-method to get the bounding boxes of the objects inside the image.
00234      * operates on the given %parameter.
00235      * @param src channel8 with the source data.
00236      * @param objects a vector with the smallest rectangles containing
00237      *                each labeled object
00238      * @return true if apply successful or false otherwise.
00239      */    
00240     bool apply(const channel8& src, std::vector<rectangle>& objects) const;
00241  
00242 
00243     /**
00244      * apply-method to get the bounding boxes of the objects inside
00245      * the image. Additionally to the bounding boxes a matrix with all
00246      * the labels is returned, where the label subtracted by one
00247      * corresponds to the index into the vector with the bounding
00248      * boxes.
00249      *
00250      * operates on the given %parameter.
00251      * @param src channel8 with the source data.
00252      * @param dest imatrix with the labeled objects.
00253      * @param objects a vector with the smallest rectangles containing
00254      *                each labeled object
00255      * @return true if apply successful or false otherwise.
00256      */    
00257     bool apply(const channel8& src, imatrix& dest,
00258                std::vector<rectangle>& objects) const;
00259     
00260     /**
00261      * apply-method to get simple geometric features (bounding box, area,
00262      * center of gravity) of the objects inside the image.
00263      * operates on the given %parameter.
00264      * @param src channel8 with the source data.
00265      * @param objects a vector with the geometric features of each
00266      *                labeled object
00267      * @return true if apply successful or false otherwise.
00268      */  
00269     bool apply(const channel8 &src, 
00270                std::vector<geometricFeatureGroup0>& objects) const;
00271     
00272     /**
00273      * apply-method to get simple geometric features (bounding box,
00274      * area, center of gravity) of the objects inside the
00275      * image. Additionally to the bounding boxes a matrix with all the
00276      * labels is returned, where the label subtracted by one
00277      * corresponds to the index of vector with the geometric features.
00278      * @param src channel8 with the source data.
00279      * @param dest imatrix with the labeled objects.
00280      * @param objects a vector with the geometric features of each
00281      *                labeled object
00282      * @return true if apply successful or false otherwise.
00283      */  
00284     bool apply(const channel8 &src, imatrix& dest,
00285          std::vector<geometricFeatureGroup0>& objects) const;
00286 
00287   protected:
00288     /**
00289      * computes the vector of equivalent labels, i.e. suppresses
00290      * objects smaller than the minimum size and those which are not
00291      * among the n-best. Furthermore this suppression is more
00292      * efficient than using the parent class' methods because the
00293      * labeled mask is not updated yet.
00294      * @param src channel8 with the source data
00295      * @param dest matrix with the labels
00296      * @param objSize vector with the object sizes
00297      * @param equivLabels vector with equivalent labels
00298      * @param numObjects contains the number of detected objects
00299      * @return true on success or false otherwise.
00300      */
00301 
00302     bool computeEquivLabels(const channel8& src, imatrix& dest,
00303           ivector& objSize, ivector& equivLabels,
00304           int& numObjects) const;
00305 
00306     /**
00307      * initializes the vector of bounding rectangles with the
00308      * rectangle containing the entire image.
00309      * @param numLab the number of labels
00310      * @param size the size of the input channel
00311      * @param objects the vector to be initializes
00312      * @return true on success or false otherwise.
00313      */
00314     virtual bool initRectangleVector(const int numLab, const point& size,
00315              std::vector<rectangle>& objects) const;
00316 
00317     /**
00318      * initializes the vector of geometric features from group 0
00319      * @param numLab the number of labels
00320      * @param size the size of the input channel
00321      * @param objects the vector to be initializes
00322      * @return true on success or false otherwise.
00323      */
00324     virtual bool 
00325       initGeomFeature0Vector(const int numLab, const point& size,
00326            std::vector<geometricFeatureGroup0>& objects)
00327       const;
00328     
00329     /**
00330      * merge neighboring objects
00331      * @param src the vector with the rectangles to be merged
00332      * @return true on success or false otherwise.
00333      */
00334     bool merge(std::vector<rectangle>& src) const;
00335     
00336     /**
00337      * merge neighboring objects
00338      * @param src the vector with the geometric features to be merged
00339      * @return true on success or false otherwise.
00340      */
00341     bool merge(std::vector<geometricFeatureGroup0>& src) const;
00342 
00343     /** 
00344      * sort the merged objects
00345      * @param objects the vector with the geometric features to be sorted
00346      * @return true on success or false otherwise.
00347      */
00348     bool sortMerged(std::vector<geometricFeatureGroup0>& objects) const;
00349   };
00350 
00351 }
00352 
00353 
00354 #endif

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