latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2002, 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 .......: ltiLocalColorFeature.h 00027 * authors ....: Axel Berner, Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 17.1.2002 00030 * revisions ..: $Id: ltiLocalColorFeature.h,v 1.12 2006/02/08 11:23:55 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_LOCAL_COLOR_FEATURE_H_ 00034 #define _LTI_LOCAL_COLOR_FEATURE_H_ 00035 00036 #include "ltiObject.h" 00037 00038 #include <list> 00039 00040 #include "ltiImage.h" 00041 #include "ltiArray.h" 00042 #include "ltiLocation.h" 00043 #include "ltiLocalFeatureExtractor.h" 00044 #include "ltiLinearKernels.h" 00045 #include "ltiBilinearInterpolator.h" 00046 00047 namespace lti { 00048 /** 00049 * This functor calculates for each location in a given list color-features. 00050 * 00051 * Each location will be considered as a circular region, that will 00052 * be divided in a specified number of slices. The color feature will 00053 * compute for each slice the average color. 00054 * 00055 * It is also possible to compute overlapping slices, to make the feature 00056 * more robust against noise. 00057 * 00058 * You can compute the locations with the functor lti::axLocationSearch or 00059 * with lti::pyramidLocationSearch. 00060 * 00061 * @ingroup gColor 00062 * @ingroup gFeatureExt 00063 */ 00064 class localColorFeature : public localFeatureExtractor { 00065 public: 00066 /** 00067 * The parameters for the class localColorFeature 00068 */ 00069 class parameters : public localFeatureExtractor::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 // the parameters 00152 // ------------------------------------------------ 00153 00154 /** 00155 * Number of slices. 00156 * 00157 * A given location will be interpreted as a circle, that will 00158 * be divided in this number of slices. The minimal allowed 00159 * value of slices is one, and the maximal allowed slices value 00160 * is 120. 00161 * 00162 * The number of dimensions of the output feature vector will be 00163 * "slices" or "2*slices" depending on the "overlap" parameter. 00164 * 00165 * Default value: 6 00166 */ 00167 unsigned int slices; 00168 00169 /** 00170 * Overlapping slices. 00171 * 00172 * If true, twice the number of slices will be computed and the feature 00173 * vector will have 2*slices elements. If false, single slices will be 00174 * computed and the number of elements of the feature vector will be 00175 * just 1*slices. 00176 * 00177 * Default value: true 00178 */ 00179 bool overlap; 00180 00181 /** 00182 * Normalize. 00183 * 00184 * If true, the final feature vector will be normalized so that the 00185 * sum of all elements equals one. 00186 * 00187 * Default value: false 00188 */ 00189 bool normalize; 00190 00191 /** 00192 * Mask radius. 00193 * 00194 * The feature computation will be made using a template mask of a fixed 00195 * size that is computed only once, when you set the parameters. The 00196 * values in this fixed mask will be taken from the image using bilinear 00197 * interpolation. 00198 * 00199 * The greater the radius, the more pixels will be considered to compute 00200 * the mean values of each slice, but the more the time it will take 00201 * to compute each location. 00202 * 00203 * This value should be greater than 2 and smaller than 255 00204 * 00205 * Default value: 7 00206 */ 00207 int maskRadius; 00208 00209 }; 00210 00211 /** 00212 * Default constructor 00213 */ 00214 localColorFeature(); 00215 00216 /** 00217 * Constructor with default parameters 00218 */ 00219 localColorFeature(const parameters& param); 00220 00221 /** 00222 * Copy constructor 00223 * @param other the object to be copied 00224 */ 00225 localColorFeature(const localColorFeature& other); 00226 00227 /** 00228 * Destructor 00229 */ 00230 virtual ~localColorFeature(); 00231 00232 /** 00233 * Returns the name of this type ("localColorFeature") 00234 */ 00235 virtual const char* getTypeName() const; 00236 00237 00238 /** 00239 * Compute the color feature for each location. 00240 * 00241 * @param src original image to be analyzed. 00242 * @param locs locations that need to be analyzed. 00243 * @param dest list of feature vectors. This list will have the 00244 * same size as locs and contains the average color of the 00245 * location and of the slices. The structure of an element 00246 * of the vector list for slices=2 and overlapping would be: 00247 * rrrrggggbbbb. 00248 * @return true if successful, or false otherwise. */ 00249 bool apply(const lti::image& src, 00250 const std::list<location>& locs, 00251 std::list<dvector>& dest); 00252 00253 /** 00254 * Compute the color feature for the given location. 00255 * 00256 * @param src original image to be analyzed. 00257 * @param locs location that need to be analyzed. 00258 * @param dest feature vector. This vector contains the average color of 00259 * the the slices. The structure of the vector for slices=2 00260 * and overlapping set to true would be: 00261 * rrrrggggbbbb. 00262 * @return true if successful, or false otherwise. */ 00263 bool apply(const lti::image& src, 00264 const location& locs, 00265 dvector& dest); 00266 00267 /** 00268 * Slices mask 00269 * 00270 * This method returns a read-only reference to the main mask. 00271 * It is intended for debug purposes only. 00272 */ 00273 const kernel2D<ubyte>& getMask() const; 00274 00275 /** 00276 * Copy data of "other" functor. 00277 * 00278 * @param other the functor to be copied 00279 * @return a reference to this functor object 00280 */ 00281 localColorFeature& copy(const localColorFeature& other); 00282 00283 /** 00284 * Alias for copy member 00285 * 00286 * @param other the functor to be copied 00287 * @return a reference to this functor object 00288 */ 00289 localColorFeature& operator=(const localColorFeature& other); 00290 00291 /** 00292 * Returns a pointer to a clone of this functor. 00293 */ 00294 virtual functor* clone() const; 00295 00296 /** 00297 * Get a read-only reference to the current parameter set. 00298 * 00299 * @return used parameters 00300 */ 00301 const parameters& getParameters() const; 00302 00303 /** 00304 * Update parameters 00305 */ 00306 virtual bool updateParameters(); 00307 00308 protected: 00309 00310 /** 00311 * Simple structure used to hold a mask and the correspoinding io-points 00312 * of the circle. 00313 */ 00314 class sliceMask { 00315 public: 00316 /** 00317 * Default constructor 00318 */ 00319 sliceMask(); 00320 00321 /** 00322 * Constructor to generate directly the mask 00323 * 00324 * @param radius radius of the mask 00325 * @param angle anglewhich will be usually zero or 2*Pi/slices/2, to 00326 * shift the mask one half slice from the "normal" one. 00327 * @param slices number of slices 00328 */ 00329 sliceMask(const int radius, 00330 const double angle, 00331 const int slices); 00332 00333 /** 00334 * Copy constructor 00335 */ 00336 sliceMask(const sliceMask& other); 00337 00338 /** 00339 * Generate this mask for the given %parameters 00340 */ 00341 void generate(const int radius, 00342 const double angle, 00343 const int slices); 00344 00345 /** 00346 * Copy member 00347 */ 00348 sliceMask& copy(const sliceMask& other); 00349 00350 /** 00351 * Alias for copy member 00352 */ 00353 sliceMask& operator=(const sliceMask& other); 00354 00355 /** 00356 * Get the mean values from the image at the given location considering 00357 * this mask. 00358 * 00359 * The vector contains first the means for all red components of the 00360 * slices, followed by the green components and then by the blue ones, 00361 */ 00362 bool getMeans(const image& img, 00363 const location& loc, 00364 vector< trgbPixel<float> >& means) const; 00365 00366 /** 00367 * Get mask 00368 */ 00369 const kernel2D<ubyte>& getMask() const; 00370 00371 protected: 00372 /** 00373 * Bilinear interpolation functor 00374 */ 00375 bilinearInterpolator<rgbPixel> bilin; 00376 00377 /** 00378 * Mask contains the index of the slice for a pixel 00379 */ 00380 kernel2D<ubyte> mask; 00381 00382 /** 00383 * Input/output points. 00384 * 00385 * The size of this "matrix" will always be the 2 x number of rows of the 00386 * mask, but indexed also with negative values 00387 */ 00388 array<int> ioPts; 00389 00390 /** 00391 * Number of slices used 00392 */ 00393 int slices; 00394 00395 /** 00396 * Radius of the mask 00397 */ 00398 int radius; 00399 00400 }; 00401 00402 /** 00403 * Slice mask used to compute the normal feature. 00404 */ 00405 sliceMask normalMask; 00406 00407 /** 00408 * Slice mask used to compute the overlapped feature 00409 */ 00410 sliceMask overlapMask; 00411 }; 00412 } 00413 00414 #endif