latest version v1.9 - last update 10 Apr 2010 |
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 .......: ltiMultiGeometricFeaturesFromMask.h 00027 * authors ....: Claudia Goenner 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 31.8.2003 00030 * revisions ..: $Id: ltiMultiGeometricFeaturesFromMask.h,v 1.9 2006/02/07 19:20:46 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_MULTI_GEOMETRIC_FEATURES_FROM_MASK_H_ 00034 #define _LTI_MULTI_GEOMETRIC_FEATURES_FROM_MASK_H_ 00035 00036 #include "ltiGeometricFeaturesFromMask.h" 00037 #include "ltiGenericVector.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 reassigns 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 and stored in the vector corresponding to the 00048 * object's kind. Thereby it is assumed that each object kind is 00049 * assigned the same grey value in the input channel. All objects of the same 00050 * kind are stored in a single vector. These vectors again are returned in a 00051 * vector and ordered in the same way as in the parameter mask Values, which 00052 * specifies the grey values for which the geometric features are computed. 00053 * Any other grey values are still labeled as described in fastRelabeling, 00054 * but excluded from the further processing performed by this class. 00055 * 00056 * Close objects are merged if requested. To ensure fast merging two objects 00057 * are close if their surrounding rectangles are close. 00058 * 00059 * CAVEAT: 00060 * 1) Sorting of the merged objects by their size does not work if the 00061 * circumscribing rectangles are returned only. 00062 */ 00063 class multiGeometricFeaturesFromMask : public geometricFeaturesFromMask { 00064 public: 00065 /** 00066 * the parameters for the class multiGeometricFeaturesFromMask 00067 */ 00068 class parameters : public geometricFeaturesFromMask::parameters { 00069 public: 00070 /** 00071 * default constructor 00072 */ 00073 parameters(); 00074 00075 /** 00076 * copy constructor 00077 * @param other the parameters object to be copied 00078 */ 00079 parameters(const parameters& other); 00080 00081 /** 00082 * destructor 00083 */ 00084 ~parameters(); 00085 00086 /** 00087 * returns name of this type 00088 */ 00089 const char* getTypeName() const; 00090 00091 /** 00092 * copy the contents of a parameters object 00093 * @param other the parameters object to be copied 00094 * @return a reference to this parameters object 00095 */ 00096 parameters& copy(const parameters& other); 00097 00098 /** 00099 * copy the contents of a parameters object 00100 * @param other the parameters object to be copied 00101 * @return a reference to this parameters object 00102 */ 00103 parameters& operator=(const parameters& other); 00104 00105 00106 /** 00107 * returns a pointer to a clone of the parameters 00108 */ 00109 virtual functor::parameters* clone() const; 00110 00111 /** 00112 * write the parameters in the given ioHandler 00113 * @param handler the ioHandler to be used 00114 * @param complete if true (the default) the enclosing begin/end will 00115 * be also written, otherwise only the data block will be written. 00116 * @return true if write was successful 00117 */ 00118 virtual bool write(ioHandler& handler,const bool complete=true) const; 00119 00120 /** 00121 * read the parameters from the given ioHandler 00122 * @param handler the ioHandler to be used 00123 * @param complete if true (the default) the enclosing begin/end will 00124 * be also written, otherwise only the data block will be written. 00125 * @return true if write was successful 00126 */ 00127 virtual bool read(ioHandler& handler,const bool complete=true); 00128 00129 # ifdef _LTI_MSC_6 00130 /** 00131 * this function is required by MSVC only, as a workaround for a 00132 * very awful bug, which exists since MSVC V.4.0, and still by 00133 * V.6.0 with all bugfixes (so called "service packs") remains 00134 * there... This method is also public due to another bug, so please 00135 * NEVER EVER call this method directly: use read() instead 00136 */ 00137 bool readMS(ioHandler& handler,const bool complete=true); 00138 00139 /** 00140 * this function is required by MSVC only, as a workaround for a 00141 * very awful bug, which exists since MSVC V.4.0, and still by 00142 * V.6.0 with all bugfixes (so called "service packs") remains 00143 * there... This method is also public due to another bug, so please 00144 * NEVER EVER call this method directly: use write() instead 00145 */ 00146 bool writeMS(ioHandler& handler,const bool complete=true) const; 00147 # endif 00148 00149 // ------------------------------------------------ 00150 // the parameters 00151 // ------------------------------------------------ 00152 00153 /** 00154 * Each object kind may be merged (true) or not (false). The inherited 00155 * parameter merge is ignored. The vectors mergeEntries and maskValues 00156 * must be of the same size. 00157 * 00158 * Default: empty 00159 */ 00160 genericVector<bool> mergeEntries; 00161 00162 /** 00163 * Specifies which mask values will be processed by this class. 00164 * The vectors mergeEntries and maskValues must be of the same size. 00165 * 00166 * Default: empty 00167 */ 00168 ivector maskValues; 00169 00170 /** 00171 * Sometimes it is advantageous to perform the merge operation separately 00172 * from the apply, i.e. when labeling several roi's one after the other. 00173 * If manualPostProcess is true the apply won't compute the complete 00174 * result, but only perform the labeling and initialization of the 00175 * geometric feature vectors. Thus some geometric features are not 00176 * consistent after the apply in the manual case, 00177 * e.g. the center of gravity is not divided by the area yet. 00178 * 00179 * Default: false 00180 */ 00181 bool manualPostProcess; 00182 00183 }; 00184 00185 /** 00186 * default constructor 00187 */ 00188 multiGeometricFeaturesFromMask(); 00189 00190 /** 00191 * Construct a functor using the given parameters 00192 */ 00193 multiGeometricFeaturesFromMask(const parameters& par); 00194 00195 /** 00196 * copy constructor 00197 * @param other the object to be copied 00198 */ 00199 multiGeometricFeaturesFromMask(const multiGeometricFeaturesFromMask& other); 00200 00201 /** 00202 * destructor 00203 */ 00204 virtual ~multiGeometricFeaturesFromMask(); 00205 00206 /** 00207 * returns the name of this type ("multiGeometricFeaturesFromMask") 00208 */ 00209 virtual const char* getTypeName() const; 00210 00211 /** 00212 * Update the parameters content. 00213 * return true on success and false otherwise 00214 */ 00215 bool updateParameters(); 00216 00217 /** 00218 * apply-method to get the bounding boxes of the objects inside the image. 00219 * operates on the given %parameter. 00220 * @param src channel8 with the source data 00221 * @param objects a vector with the smallest rectangles containing each 00222 * labeled object 00223 * @return true if apply successful or false otherwise. 00224 */ 00225 bool apply(const channel8& src, 00226 std::vector<std::vector<rectangle> >& objects) const; 00227 00228 /** 00229 * apply-method to get simple geometric features (bounding box, area, 00230 * center of gravity) of the objects inside the image. Additionally 00231 * to the bounding boxes a matrix with all the labels is returned, where 00232 * the label subtracted by one corresponds to the index into the vector 00233 * with the geometric features. 00234 * operates on the given %parameter. 00235 * @param src channel8 with the source data 00236 * @param dest a matrix with the labeled data 00237 * @param objects a vector with the geometric features of each labeled 00238 * object 00239 * @return true if apply successful or false otherwise. 00240 */ 00241 bool apply(const channel8 &src, imatrix& dest, 00242 std::vector<std::vector<rectangle> >& objects) const; 00243 00244 /** 00245 * apply-method to get simple geometric features (bounding box, area, 00246 * center of gravity) of the objects inside the image. 00247 * operates on the given %parameter. 00248 * @param src channel8 with the source data 00249 * @param objects a vector with the geometric features of each labeled object 00250 * @return true if apply successful or false otherwise. 00251 */ 00252 bool apply(const channel8 &src, 00253 std::vector<std::vector<geometricFeatureGroup0> >& objects) const; 00254 00255 /** 00256 * apply-method to get simple geometric features (bounding box, area, 00257 * center of gravity) of the objects inside the image. Additionally 00258 * to the bounding boxes a matrix with all the labels is returned, where 00259 * the label subtracted by one corresponds to the index into the vector 00260 * with the geometric features. 00261 * operates on the given %parameter. 00262 * @param src channel8 with the source data 00263 * @param dest matrix with the labeled data 00264 * @param objects a vector with the geometric features of each labeled 00265 * object 00266 * @return true if apply successful or false otherwise. 00267 */ 00268 bool apply 00269 (const channel8 &src, imatrix& dest, 00270 std::vector<std::vector<geometricFeatureGroup0> >& objects) const; 00271 00272 /** 00273 * Merge if requested and compute the center of gravity. This method need 00274 * only be called in the manual post processing mode. 00275 * @param objects the geometric features to be processed 00276 * @return true on success and false otherwise 00277 */ 00278 bool postProcess 00279 (std::vector< std::vector<geometricFeatureGroup0> >& objects) const; 00280 00281 /** 00282 * Merge if requested. This method need only be 00283 * called in the manual post processing mode. 00284 * @param objects the rectangles to be processed 00285 * @return true on success and false otherwise 00286 */ 00287 bool postProcess(std::vector< std::vector<rectangle> >& objects) const; 00288 00289 /** 00290 * copy data of "other" functor. 00291 * @param other the functor to be copied 00292 * @return a reference to this functor object 00293 */ 00294 multiGeometricFeaturesFromMask& copy 00295 (const multiGeometricFeaturesFromMask& other); 00296 00297 /** 00298 * alias for copy member 00299 * @param other the functor to be copied 00300 * @return a reference to this functor object 00301 */ 00302 multiGeometricFeaturesFromMask& operator= 00303 (const multiGeometricFeaturesFromMask& other); 00304 00305 /** 00306 * returns a pointer to a clone of this functor. 00307 */ 00308 virtual functor* clone() const; 00309 00310 /** 00311 * returns used parameters 00312 */ 00313 const parameters& getParameters() const; 00314 00315 }; 00316 } 00317 00318 #endif