latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2001, 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 Digital Image/Signal Processing Library 00026 * file .......: ltiLkmColorQuantization.h 00027 * authors ....: Axel Berner 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 15.5.2001 00030 * revisions ..: $Id: ltiLkmColorQuantization.h,v 1.8 2006/02/08 11:23:38 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_LKM_COLOR_QUANTIZATION_H_ 00034 #define _LTI_LKM_COLOR_QUANTIZATION_H_ 00035 00036 #include "ltiColorQuantization.h" 00037 00038 namespace lti { 00039 /** 00040 * Color quantization functor based on the local k-Means algorithm 00041 * of O. Verevka and J. W. Buchanan (see original paper 00042 * <a href="http://www.cs.ualberta.ca/~oleg/quantization.html">here</a>). 00043 * 00044 * The modifications are basically in the use of a LUT for the 00045 * computation of the L2 norm, which makes the algorithm as 00046 * efficient as using the originally proposed L(1/2) norm and the 00047 * consideration of a direct neighbourhood to avoid some problems 00048 * with simple quantization problems. 00049 */ 00050 class lkmColorQuantization : public colorQuantization { 00051 public: 00052 /** 00053 * the parameters for the class lkmColorQuantization 00054 */ 00055 class parameters : public colorQuantization::parameters { 00056 public: 00057 /** 00058 * default constructor 00059 */ 00060 parameters(); 00061 00062 /** 00063 * copy constructor 00064 * @param other the parameters object to be copied 00065 */ 00066 parameters(const parameters& other); 00067 00068 /** 00069 * destructor 00070 */ 00071 ~parameters(); 00072 00073 /** 00074 * returns name of this type 00075 */ 00076 const char* getTypeName() const; 00077 00078 /** 00079 * copy the contents of a parameters object 00080 * @param other the parameters object to be copied 00081 * @return a reference to this parameters object 00082 */ 00083 parameters& copy(const parameters& other); 00084 00085 /** 00086 * copy the contents of a parameters object 00087 * @param other the parameters object to be copied 00088 * @return a reference to this parameters object 00089 */ 00090 parameters& operator=(const parameters& other); 00091 00092 00093 /** 00094 * returns a pointer to a clone of the parameters 00095 */ 00096 virtual functor::parameters* clone() const; 00097 00098 /** 00099 * write the parameters in the given ioHandler 00100 * @param handler the ioHandler to be used 00101 * @param complete if true (the default) the enclosing begin/end will 00102 * be also written, otherwise only the data block will be written. 00103 * @return true if write was successful 00104 */ 00105 virtual bool write(ioHandler& handler,const bool complete=true) const; 00106 00107 /** 00108 * write the parameters in the given ioHandler 00109 * @param handler the ioHandler to be used 00110 * @param complete if true (the default) the enclosing begin/end will 00111 * be also written, otherwise only the data block will be written. 00112 * @return true if write was successful 00113 */ 00114 virtual bool read(ioHandler& handler,const bool complete=true); 00115 00116 # ifdef _LTI_MSC_6 00117 /** 00118 * this function is required by MSVC only, as a workaround for a 00119 * very awful bug, which exists since MSVC V.4.0, and still by 00120 * V.6.0 with all bugfixes (so called "service packs") remains 00121 * there... This method is also public due to another bug, so please 00122 * NEVER EVER call this method directly: use read() instead 00123 */ 00124 bool readMS(ioHandler& handler,const bool complete=true); 00125 00126 /** 00127 * this function is required by MSVC only, as a workaround for a 00128 * very awful bug, which exists since MSVC V.4.0, and still by 00129 * V.6.0 with all bugfixes (so called "service packs") remains 00130 * there... This method is also public due to another bug, so please 00131 * NEVER EVER call this method directly: use write() instead 00132 */ 00133 bool writeMS(ioHandler& handler,const bool complete=true) const; 00134 # endif 00135 00136 // ------------------------------------------------ 00137 // the parameters 00138 // ------------------------------------------------ 00139 00140 //TODO: comment the parameters of your functor 00141 // If you add more parameters manually, do not forget to do following: 00142 // 1. indicate in the default constructor the default values 00143 // 2. make sure that the copy member also copy your new parameters 00144 // 3. make sure that the read and write members also read and 00145 // write your parameters 00146 00147 00148 /** 00149 * This parameter defines how strong 00150 * is the influence of an changing paletteIndex 00151 * towards the neighbour paletteIndex is. 00152 * Default value: 0.1 00153 */ 00154 double neighbour; 00155 00156 /** 00157 * this parameter is the startvalue 00158 * for the weight of a new pixel. 00159 * Default value: 0.6 00160 */ 00161 double learnRate; 00162 00163 /** 00164 * This parameter is the factor, 00165 * the learnRate will be multiplicated with 00166 * in every iteration 00167 * It defines how fast the learnRate convergates to zero 00168 * Default value: 0.5 00169 */ 00170 double shrinkLearnRate; 00171 00172 /** 00173 * this parameter sets the upper limit for 00174 * the iterations, if the algorithm hasn't 00175 * convergated yet 00176 * Default value: 10 00177 */ 00178 int maxIterations; 00179 }; 00180 00181 /** 00182 * default constructor 00183 */ 00184 lkmColorQuantization(); 00185 00186 /** 00187 * copy constructor 00188 * @param other the object to be copied 00189 */ 00190 lkmColorQuantization(const lkmColorQuantization& other); 00191 00192 /** 00193 * destructor 00194 */ 00195 virtual ~lkmColorQuantization(); 00196 00197 /** 00198 * returns the name of this type ("lkmColorQuantization") 00199 */ 00200 virtual const char* getTypeName() const; 00201 00202 /** 00203 * operates on a copy of the given %parameters. 00204 * @param src image with the source data. 00205 * @param dest image where the result will be left. 00206 * @param lkmCPalette the color palette with the quantized colors 00207 * @return true if apply successful or false otherwise. 00208 */ 00209 bool apply(const image& src, 00210 channel8& dest, 00211 lti::palette& lkmCPalette) const; 00212 00213 /** 00214 * operates on the given %parameter. 00215 * @param srcdest image with the source data. The result 00216 * will be left here too. 00217 * @return true if apply successful or false otherwise. 00218 */ 00219 bool apply(image& srcdest) const; 00220 00221 /** 00222 * operates on the given %parameter. 00223 * @param src image with the source data. 00224 * @param dest image with only the number of colors specified in 00225 * the parameters 00226 * @return true if apply successful or false otherwise. 00227 */ 00228 bool apply(const image& src,image& dest) const; 00229 00230 /** 00231 * copy data of "other" functor. 00232 * @param other the functor to be copied 00233 * @return a reference to this functor object 00234 */ 00235 lkmColorQuantization& copy(const lkmColorQuantization& other); 00236 00237 /** 00238 * returns a pointer to a clone of this functor. 00239 */ 00240 virtual functor* clone() const; 00241 00242 /** 00243 * returns used parameters 00244 */ 00245 const parameters& getParameters() const; 00246 00247 private: 00248 // look up table for the square of a number between -255 and 255 00249 static const int* sqrLUT; 00250 }; 00251 } 00252 00253 #endif