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 .......: ltiComputePalette.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 11.3.2002 00030 * revisions ..: $Id: ltiComputePalette.h,v 1.12 2006/02/07 18:39:58 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_COMPUTE_PALETTE_H_ 00034 #define _LTI_COMPUTE_PALETTE_H_ 00035 00036 #include "ltiImage.h" 00037 #include "ltiFunctor.h" 00038 00039 namespace lti { 00040 /** 00041 * This class is used to compute a palette given a color image and an 00042 * index mask. Both objects must have the same size. 00043 * The size of the resulting palette will be the maximal value 00044 * in the index mask plus one. The colors in the palette will be the average 00045 * colors in the mask. 00046 * 00047 * @see usePalette 00048 */ 00049 class computePalette : public functor { 00050 public: 00051 /** 00052 * the parameters for the class computePalette 00053 */ 00054 class parameters : public functor::parameters { 00055 public: 00056 /** 00057 * default constructor 00058 */ 00059 parameters(); 00060 00061 /** 00062 * copy constructor 00063 * @param other the parameters object to be copied 00064 */ 00065 parameters(const parameters& other); 00066 00067 /** 00068 * destructor 00069 */ 00070 ~parameters(); 00071 00072 /** 00073 * returns name of this type 00074 */ 00075 const char* getTypeName() const; 00076 00077 /** 00078 * copy the contents of a parameters object 00079 * @param other the parameters object to be copied 00080 * @return a reference to this parameters object 00081 */ 00082 parameters& copy(const parameters& other); 00083 00084 /** 00085 * copy the contents of a parameters object 00086 * @param other the parameters object to be copied 00087 * @return a reference to this parameters object 00088 */ 00089 parameters& operator=(const parameters& other); 00090 00091 00092 /** 00093 * returns a pointer to a clone of the parameters 00094 */ 00095 virtual functor::parameters* clone() const; 00096 00097 /** 00098 * write the parameters in the given ioHandler 00099 * @param handler the ioHandler to be used 00100 * @param complete if true (the default) the enclosing begin/end will 00101 * be also written, otherwise only the data block will be written. 00102 * @return true if write was successful 00103 */ 00104 virtual bool write(ioHandler& handler,const bool complete=true) const; 00105 00106 /** 00107 * read the parameters from the given ioHandler 00108 * @param handler the ioHandler to be used 00109 * @param complete if true (the default) the enclosing begin/end will 00110 * be also written, otherwise only the data block will be written. 00111 * @return true if write was successful 00112 */ 00113 virtual bool read(ioHandler& handler,const bool complete=true); 00114 00115 # ifdef _LTI_MSC_6 00116 /** 00117 * this function is required by MSVC only, as a workaround for a 00118 * very awful bug, which exists since MSVC V.4.0, and still by 00119 * V.6.0 with all bugfixes (so called "service packs") remains 00120 * there... This method is also public due to another bug, so please 00121 * NEVER EVER call this method directly: use read() instead 00122 */ 00123 bool readMS(ioHandler& handler,const bool complete=true); 00124 00125 /** 00126 * this function is required by MSVC only, as a workaround for a 00127 * very awful bug, which exists since MSVC V.4.0, and still by 00128 * V.6.0 with all bugfixes (so called "service packs") remains 00129 * there... This method is also public due to another bug, so please 00130 * NEVER EVER call this method directly: use write() instead 00131 */ 00132 bool writeMS(ioHandler& handler,const bool complete=true) const; 00133 # endif 00134 00135 // ------------------------------------------------ 00136 // the parameters 00137 // ------------------------------------------------ 00138 00139 }; 00140 00141 /** 00142 * default constructor 00143 */ 00144 computePalette(); 00145 00146 /** 00147 * copy constructor 00148 * @param other the object to be copied 00149 */ 00150 computePalette(const computePalette& other); 00151 00152 /** 00153 * destructor 00154 */ 00155 virtual ~computePalette(); 00156 00157 /** 00158 * returns the name of this type ("computePalette") 00159 */ 00160 virtual const char* getTypeName() const; 00161 00162 /** 00163 * operates on a copy of the given %parameters. 00164 * @param src image with the source data. 00165 * @param mask mask with palette entry indices. 00166 * @param dest computed palette. 00167 * @return true if apply successful or false otherwise. 00168 */ 00169 bool apply(const image& src,const channel8& mask, palette& dest) const; 00170 00171 /** 00172 * operates on a copy of the given %parameters. 00173 * @param src image with the source data. 00174 * @param mask mask with palette entry indices. 00175 * @param dest computed palette. 00176 * @return true if apply successful or false otherwise. 00177 */ 00178 bool apply(const image& src,const matrix<int>& mask, palette& dest) const; 00179 00180 /** 00181 * operates on a copy of the given %parameters. 00182 * @param src image with the source data. 00183 * @param mask mask with palette entry indices. 00184 * @param dest computed palette (mean value of all elements with the 00185 * same index). 00186 * @param palStdDev standard deviation for each palette entry. 00187 * @return true if apply successful or false otherwise. 00188 */ 00189 bool apply(const image& src, 00190 const channel8& mask, 00191 palette& dest, 00192 vector<trgbPixel<float> >& palStdDev) const; 00193 00194 /** 00195 * operates on a copy of the given %parameters. 00196 * @param src image with the source data. 00197 * @param mask mask with palette entry indices. 00198 * @param dest computed palette (mean value of all elements with the 00199 * same index). 00200 * @param palStdDev standard deviation for each palette entry. 00201 * @return true if apply successful or false otherwise. 00202 */ 00203 bool apply(const image& src, 00204 const matrix<int>& mask, 00205 palette& dest, 00206 vector<trgbPixel<float> >& palStdDev) const; 00207 00208 /** 00209 * computes the mean values for each label present in the image 00210 * @param src image with the source data. 00211 * @param mask mask with palette entry indices. 00212 * @param means mean value of all elements with the same label. 00213 * @param n number of elements for each label. 00214 * @param numLabels this optional parameter can be used to save some time 00215 * if you give the number of labels in the mask, or to 00216 * be more specific the greatest label in mask + 1. If 00217 * ommited, the mask.maximum() will be called to find out 00218 * how many elements the vectors n and means must have, 00219 * which costs one iteration on the whole mask. 00220 * @return true if apply successful or false otherwise. 00221 */ 00222 bool apply(const image& src, 00223 const matrix<int>& mask, 00224 vector<trgbPixel<float> >& means, 00225 ivector& n, 00226 const int numLabels = -1) const; 00227 00228 00229 /** 00230 * operates on a copy of the given %parameters. 00231 * @param src image with the source data. 00232 * @param mask mask with palette entry indices. 00233 * @param dest computed palette (mean value of all elements with the 00234 * same index). 00235 * @param palStdDev standard deviation for each palette entry. 00236 * @param n number of pixels found for each entry 00237 * @return true if apply successful or false otherwise. 00238 */ 00239 bool apply(const image& src, 00240 const channel8& mask, 00241 palette& dest, 00242 vector<trgbPixel<float> >& palStdDev, 00243 vector<int>& n) const; 00244 00245 /** 00246 * operates on a copy of the given %parameters. 00247 * @param src image with the source data. 00248 * @param mask mask with palette entry indices. 00249 * @param dest computed palette (mean value of all elements with the 00250 * same index). 00251 * @param palStdDev standard deviation for each palette entry. 00252 * @param n number of pixels found for each entry 00253 * @return true if apply successful or false otherwise. 00254 */ 00255 bool apply(const image& src, 00256 const matrix<int>& mask, 00257 palette& dest, 00258 vector<trgbPixel<float> >& palStdDev, 00259 vector<int>& n) const; 00260 00261 /** 00262 * this apply will generate multivariate statistics for each 00263 * entry in the palette, at it takes more time than the other 00264 * ones. 00265 * @param src image with the source data. 00266 * @param mask mask with palette entry indices. 00267 * @param dest computed palette (mean value of all elements with the 00268 * same index). Note that this apply 00269 * will compute with floats) 00270 * @param palCovar covariance matrices for each palette entry. 00271 * @param n number of pixels found for each entry 00272 * @return true if apply successful or false otherwise. 00273 */ 00274 bool apply(const image& src, 00275 const matrix<int>& mask, 00276 vector<trgbPixel<float> >& dest, 00277 std::vector<matrix<float> >& palCovar, 00278 vector<int>& n) const; 00279 00280 /** 00281 * this apply will generate multivariate statistics for each 00282 * entry in the palette. It takes more time than the other 00283 * ones. The image will be assumed to be composed by the given three 00284 * channels. 00285 * @param ch1 first channel of the image 00286 * @param ch2 second channel of the image 00287 * @param ch3 third channel of the image 00288 * @param mask mask with palette entry indices. 00289 * @param dest computed palette (mean value of all elements with the 00290 * same index). Note that this apply 00291 * will compute with floats) 00292 * @param palCovar covariance matrices for each palette entry. 00293 * @param n number of pixels found for each entry 00294 * @return true if apply successful or false otherwise. 00295 */ 00296 bool apply(const channel& ch1, 00297 const channel& ch2, 00298 const channel& ch3, 00299 const matrix<int>& mask, 00300 vector<trgbPixel<float> >& dest, 00301 std::vector<matrix<float> >& palCovar, 00302 vector<int>& n) const; 00303 00304 /** 00305 * this apply will generate multivariate statistics for each 00306 * entry in the palette. It takes more time than the other 00307 * ones. The image will be assumed to be composed by the given three 00308 * channels. 00309 * @param ch1 first channel of the image 00310 * @param ch2 second channel of the image 00311 * @param ch3 third channel of the image 00312 * @param mask mask with palette entry indices. 00313 * @param dest computed palette (mean value of all elements with the 00314 * same index). Note that this apply 00315 * will compute with floats) 00316 * @param n number of pixels found for each entry 00317 * @return true if apply successful or false otherwise. 00318 */ 00319 bool apply(const channel& ch1, 00320 const channel& ch2, 00321 const channel& ch3, 00322 const matrix<int>& mask, 00323 vector<trgbPixel<float> >& dest, 00324 vector<int>& n) const; 00325 00326 /** 00327 * This apply method computes the mean values and variances of the 00328 * regions indicated by the mask for the given channel. 00329 * 00330 * @param ch channel for which the region statistics will be computed 00331 * @param mask labeled mask indicating the regions 00332 * @param means mean values for each region 00333 * @param vars variances for each region 00334 * @param n number of pixels per region 00335 * @return true if successful, false otherwise. 00336 */ 00337 bool apply(const channel& ch, 00338 const matrix<int>& mask, 00339 vector<float>& means, 00340 vector<float>& vars, 00341 vector<int>& n) const; 00342 00343 00344 /** 00345 * compute the mean value and covariance matrix for just one 00346 * label in the mask. 00347 * 00348 * @param src image with the source data. 00349 * @param mask mask with palette entry indices. 00350 * @param label label to be analyzed. 00351 * @param mean mean color of the given label. 00352 * @param covar covariance matrix for the given label. 00353 * @param n number of pixels found with the given label. 00354 * @return true if apply successful or false otherwise. 00355 */ 00356 bool apply(const image& src, 00357 const matrix<int>& mask, 00358 const int label, 00359 trgbPixel<float>& mean, 00360 matrix<float>& covar, 00361 int& n) const; 00362 00363 /** 00364 * copy data of "other" functor. 00365 * @param other the functor to be copied 00366 * @return a reference to this functor object 00367 */ 00368 computePalette& copy(const computePalette& other); 00369 00370 /** 00371 * alias for copy member 00372 * @param other the functor to be copied 00373 * @return a reference to this functor object 00374 */ 00375 computePalette& operator=(const computePalette& other); 00376 00377 /** 00378 * returns a pointer to a clone of this functor. 00379 */ 00380 virtual functor* clone() const; 00381 00382 /** 00383 * returns used parameters 00384 */ 00385 const parameters& getParameters() const; 00386 00387 private: 00388 /** 00389 * outer product of two colors 00390 */ 00391 void outer(const trgbPixel<float>& a, 00392 const trgbPixel<float>& b, 00393 matrix<double>& mat) const; 00394 }; 00395 } 00396 00397 #endif