latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 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 .......: ltiLocalMoments.h 00027 * authors ....: Arnd Hannemann 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 28.4.2004 00030 * revisions ..: $Id: ltiLocalMoments.h,v 1.5 2006/02/08 11:25:00 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_LOCAL_MOMENTS_H_ 00034 #define _LTI_LOCAL_MOMENTS_H_ 00035 00036 //TODO: include only those files which are needed in this header!! 00037 00038 #include <list> 00039 #include "ltiImage.h" 00040 #include "ltiArray.h" 00041 #include "ltiLocalFeatureExtractor.h" 00042 00043 namespace lti { 00044 /** 00045 * This local feature extractor can be used to estimate the 00046 * standardized moments (Mean, Variance, Skew and Kurtosis) 00047 * of a certain circular area around the given location. 00048 * 00049 * For Variance, Skew and Kurtosis unbiased estimators are used. 00050 * 00051 * \code 00052 * #include "ltiLocalMoments.h" 00053 * 00054 * lti::channel src; 00055 * lti::point p(200,200); 00056 * lti::location(p,0,5); 00057 * lti::dvector dest; 00058 * 00059 * lti::localMoments lM; 00060 * lM.apply(src,loc,dest); 00061 * 00062 * // per default all those moments are calculated: 00063 * std::cout << "Mean ="<<dest[0]<<"\n"; 00064 * std::cout << "Variance = "<<dest[1]<<"\n"; 00065 * std::cout << "Skew = "<<dest[2]<<"\n"; 00066 * std::cout << "Kurtosis = "<<dest[3]<<"\n"; 00067 * \endcode 00068 * 00069 * @ingroup gFeatureExtr 00070 */ 00071 class localMoments : public localFeatureExtractor { 00072 public: 00073 /** 00074 * The parameters for the class localMoments 00075 */ 00076 class parameters : public localFeatureExtractor::parameters { 00077 public: 00078 00079 /** 00080 * Default constructor 00081 */ 00082 parameters(); 00083 00084 /** 00085 * Copy constructor 00086 * @param other the parameters object to be copied 00087 */ 00088 parameters(const parameters& other); 00089 00090 /** 00091 * Destructor 00092 */ 00093 ~parameters(); 00094 00095 /** 00096 * Returns name of this type 00097 */ 00098 const char* getTypeName() const; 00099 00100 /** 00101 * Copy the contents of a parameters object 00102 * @param other the parameters object to be copied 00103 * @return a reference to this parameters object 00104 */ 00105 parameters& copy(const parameters& other); 00106 00107 /** 00108 * Copy the contents of a parameters object 00109 * @param other the parameters object to be copied 00110 * @return a reference to this parameters object 00111 */ 00112 parameters& operator=(const parameters& other); 00113 00114 00115 /** 00116 * Returns a pointer to a clone of the parameters 00117 */ 00118 virtual functor::parameters* clone() const; 00119 00120 /** 00121 * Write the parameters in 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 write(ioHandler& handler,const bool complete=true) const; 00128 00129 /** 00130 * Read the parameters from the given ioHandler 00131 * @param handler the ioHandler to be used 00132 * @param complete if true (the default) the enclosing begin/end will 00133 * be also written, otherwise only the data block will be written. 00134 * @return true if write was successful 00135 */ 00136 virtual bool read(ioHandler& handler,const bool complete=true); 00137 00138 # ifdef _LTI_MSC_6 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 read() instead 00145 */ 00146 bool readMS(ioHandler& handler,const bool complete=true); 00147 00148 /** 00149 * This function is required by MSVC only, as a workaround for a 00150 * very awful bug, which exists since MSVC V.4.0, and still by 00151 * V.6.0 with all bugfixes (so called "service packs") remains 00152 * there... This method is also public due to another bug, so please 00153 * NEVER EVER call this method directly: use write() instead 00154 */ 00155 bool writeMS(ioHandler& handler,const bool complete=true) const; 00156 # endif 00157 00158 // ------------------------------------------------ 00159 // the parameters 00160 // ------------------------------------------------ 00161 00162 /** 00163 * Which method is used to extract pixels of the original image. 00164 * 00165 * Default: FixedRaySampling 00166 */ 00167 eSamplingMethod samplingMethod; 00168 00169 /** 00170 * If this is true, the mean of the location pixels is 00171 * calculated and stored in the result vector. 00172 * 00173 * The values in each result vector are ordered by ascending complexity. 00174 * (Mean,Variance,Skew,Kurtosis) 00175 * 00176 * Default: true 00177 */ 00178 bool calculateMean; 00179 /** 00180 * If this is true, the variance of the location pixels is 00181 * calculated and stored in the result vector. 00182 * 00183 * The values in each result vector are ordered by ascending complexity. 00184 * (Mean,Variance,Skew,Kurtosis) 00185 * 00186 * Default: true 00187 */ 00188 bool calculateVariance; 00189 /** 00190 * If this is true, the skew of the location pixels is 00191 * calculated and stored in the result vector. 00192 * 00193 * The values in each result vector are ordered by ascending complexity. 00194 * (Mean,Variance,Skew,Kurtosis) 00195 * 00196 * Default: true 00197 */ 00198 bool calculateSkew; 00199 /** 00200 * If this is true, the kurtosis of the location pixels is 00201 * calculated and stored in the result vector. 00202 * 00203 * The values in each result vector are ordered by ascending complexity. 00204 * (Mean,Variance,Skew,Kurtosis) 00205 * 00206 * Default: true 00207 */ 00208 bool calculateKurtosis; 00209 00210 /** 00211 * Factor used to scale the radius of the given locations. 00212 * 00213 * Default: 1.0f 00214 */ 00215 float scale; 00216 00217 /** 00218 * Radius of the fixed grid used for fixedGridSampling(). 00219 * This parameter has no effect if FixedRaySampling is used. 00220 * 00221 * Default: 3 00222 */ 00223 int gridRadius; 00224 00225 /** 00226 * Number of Circles used for fixedRaySampling(). 00227 * This parameter has no effect if FixedGridSampling is used. 00228 * 00229 * Default: 3 00230 */ 00231 int numCircles; 00232 00233 /** 00234 * Number of Rays used for fixedRaySampling(). 00235 * This parameter has no effect if FixedGridSampling is used. 00236 * 00237 * Default: 24 00238 */ 00239 int numRays; 00240 00241 00242 }; 00243 00244 /** 00245 * Default constructor 00246 */ 00247 localMoments(); 00248 00249 /** 00250 * Construct a functor using the given parameters 00251 */ 00252 localMoments(const parameters& par); 00253 00254 /** 00255 * Copy constructor 00256 * @param other the object to be copied 00257 */ 00258 localMoments(const localMoments& other); 00259 00260 /** 00261 * Destructor 00262 */ 00263 virtual ~localMoments(); 00264 00265 /** 00266 * Returns the name of this type ("localMoments") 00267 */ 00268 virtual const char* getTypeName() const; 00269 00270 //TODO: comment your apply methods! 00271 00272 virtual bool setParameters(const parameters& theParam); 00273 00274 /** 00275 * Compute the local feature for the given location. 00276 * 00277 * @param src original channel to be analyzed. 00278 * @param loc location that need to be analyzed. 00279 * @param dest feature vector. 00280 * @return true if successful, or false otherwise. 00281 */ 00282 virtual bool apply(const lti::channel& src, 00283 const location& loc, 00284 dvector& dest) const; 00285 00286 /** 00287 * Compute the local feature for the given location for each color channel 00288 * of the given image. 00289 * The resulting vectors are concatinated in this order: red,green,blue. 00290 * 00291 * @param src original image to be analyzed. 00292 * @param loc location that need to be analyzed. 00293 * @param dest feature vector. 00294 * @return true if successful, or false otherwise. 00295 */ 00296 virtual bool apply(const lti::image& src, 00297 const location& loc, 00298 dvector& dest) const; 00299 00300 /** 00301 * Compute the local features for the given locations for each 00302 * color channel of the given image. 00303 * The resulting vectors are concatinated in this order: red,green,blue. 00304 * 00305 * @param src original channel to be analyzed. 00306 * @param locs list of locations that need to be analyzed. 00307 * @param dests list of feature vectors. 00308 * @return true if successful, or false otherwise. 00309 */ 00310 virtual bool apply(const lti::image& src, 00311 const std::list<location>& locs, 00312 std::list<dvector>& dests) const; 00313 00314 /** 00315 * Compute the local features for the given locations. 00316 * 00317 * @param src original channel to be analyzed. 00318 * @param locs locations that need to be analyzed. 00319 * @param dests feature vectors. 00320 * @return true if successful, or false otherwise. 00321 */ 00322 virtual bool apply(const lti::channel& src, 00323 const std::list<location>& locs, 00324 std::list<dvector>& dests) const; 00325 00326 00327 /** 00328 * Returns whether the onPlace version of apply is faster or 00329 * the onCopy version. 00330 */ 00331 // virtual functor::eFasterApply theFaster() const; 00332 00333 /** 00334 * Copy data of "other" functor. 00335 * @param other the functor to be copied 00336 * @return a reference to this functor object 00337 */ 00338 localMoments& copy(const localMoments& other); 00339 00340 /** 00341 * Alias for copy member 00342 * @param other the functor to be copied 00343 * @return a reference to this functor object 00344 */ 00345 localMoments& operator=(const localMoments& other); 00346 00347 /** 00348 * Returns a pointer to a clone of this functor. 00349 */ 00350 virtual functor* clone() const; 00351 00352 /** 00353 * Returns used parameters 00354 */ 00355 const parameters& getParameters() const; 00356 00357 //TODO: comment the attributes of your functor 00358 // If you add more attributes manually, do not forget to do following: 00359 // 1. indicate in the default constructor the default values 00360 // 2. make sure that the copy member also copy your new attributes, or 00361 // to ensure there, that these attributes are properly initialized. 00362 00363 protected: 00364 /** 00365 * Internal array for circular mask of fixedGridSampling 00366 */ 00367 array<int> circPoints; 00368 00369 }; 00370 } 00371 00372 #endif