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 Digital Image/Signal Processing Library 00026 * file .......: ltiKMeansSegmentation.h 00027 * authors ....: Axel Berner 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 3.2.2002 00030 * revisions ..: $Id: ltiKMeansSegmentation.h,v 1.10 2006/02/08 11:19:59 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_K_MEANS_SEGMENTATION_H_ 00034 #define _LTI_K_MEANS_SEGMENTATION_H_ 00035 00036 #include "ltiKMColorQuantization.h" 00037 #include "ltiSegmentation.h" 00038 00039 namespace lti { 00040 /** 00041 * A segmentation algorithm which is based on a color-quantization 00042 * algorithm followed by a smoothing filter. The quantization of 00043 * the colors is done with the k-Means algorithm, which creates an 00044 * optimal color-palette, to which all original image colors are 00045 * mapped to. The smoothing filter (None, Median, K-Nearest, ...) 00046 * can be choosen with the parameters objects. 00047 */ 00048 class kMeansSegmentation : public segmentation { 00049 public: 00050 /** 00051 * the parameters for the class kMeansSegmentation 00052 */ 00053 class parameters : public segmentation::parameters { 00054 public: 00055 /** 00056 * default constructor 00057 */ 00058 parameters(); 00059 00060 /** 00061 * construct a parameters object with the given number of 00062 * quantization colors. 00063 * 00064 * @param numCols number of colors 00065 */ 00066 parameters(const int numCols); 00067 00068 /** 00069 * copy constructor 00070 * @param other the parameters object to be copied 00071 */ 00072 parameters(const parameters& other); 00073 00074 /** 00075 * destructor 00076 */ 00077 ~parameters(); 00078 00079 /** 00080 * returns name of this type 00081 */ 00082 const char* getTypeName() const; 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& copy(const parameters& other); 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& operator=(const parameters& other); 00097 00098 00099 /** 00100 * returns a pointer to a clone of the parameters 00101 */ 00102 virtual functor::parameters* clone() const; 00103 00104 /** 00105 * write the parameters in the given ioHandler 00106 * @param handler the ioHandler to be used 00107 * @param complete if true (the default) the enclosing begin/end will 00108 * be also written, otherwise only the data block will be written. 00109 * @return true if write was successful 00110 */ 00111 virtual bool write(ioHandler& handler,const bool complete=true) const; 00112 00113 /** 00114 * read the parameters from the given ioHandler 00115 * @param handler the ioHandler to be used 00116 * @param complete if true (the default) the enclosing begin/end will 00117 * be also written, otherwise only the data block will be written. 00118 * @return true if write was successful 00119 */ 00120 virtual bool read(ioHandler& handler,const bool complete=true); 00121 00122 # ifdef _LTI_MSC_6 00123 /** 00124 * this function is required by MSVC only, as a workaround for a 00125 * very awful bug, which exists since MSVC V.4.0, and still by 00126 * V.6.0 with all bugfixes (so called "service packs") remains 00127 * there... This method is also public due to another bug, so please 00128 * NEVER EVER call this method directly: use read() instead 00129 */ 00130 bool readMS(ioHandler& handler,const bool complete=true); 00131 00132 /** 00133 * this function is required by MSVC only, as a workaround for a 00134 * very awful bug, which exists since MSVC V.4.0, and still by 00135 * V.6.0 with all bugfixes (so called "service packs") remains 00136 * there... This method is also public due to another bug, so please 00137 * NEVER EVER call this method directly: use write() instead 00138 */ 00139 bool writeMS(ioHandler& handler,const bool complete=true) const; 00140 # endif 00141 00142 // ------------------------------------------------ 00143 // the parameters 00144 // ------------------------------------------------ 00145 00146 /** 00147 * number of colors for the image quantization and other 00148 * quantization parameters 00149 * 00150 * Default: numberOfColors: 16 00151 * thresholdDeltaPalette: 1 00152 */ 00153 kMColorQuantization::parameters quantParameters; 00154 00155 /** 00156 * Smooth filter type 00157 */ 00158 enum eSmoothFilterType { 00159 Nothing = 0, /**< Do not smooth the color quantized image */ 00160 Median = 1, /**< Use Median Filter (lti::medianFilter) */ 00161 KNearest = 2 /**< Use K-Nearest Neighbor filter 00162 * (lti::kNearestNeighFilter) 00163 */ 00164 }; 00165 00166 /** 00167 * kind of smoothing-filter. Use the constants defined in the parameters 00168 * to specify the filter type: Nothing, Median or KNearest 00169 * 00170 * Default: KNearest 00171 */ 00172 eSmoothFilterType smoothFilter; 00173 00174 /** 00175 * kerner size of the smoothing-filter 00176 * 00177 * Default: 5 00178 */ 00179 int kernelSize; 00180 }; 00181 00182 /** 00183 * default constructor 00184 */ 00185 kMeansSegmentation(); 00186 00187 /** 00188 * default constructor with parameters object 00189 */ 00190 kMeansSegmentation(const parameters& par); 00191 00192 /** 00193 * construct a segmentation functor with the given numbers of colors 00194 * in the quantization stage. 00195 */ 00196 kMeansSegmentation(const int numCols); 00197 00198 /** 00199 * copy constructor 00200 * @param other the object to be copied 00201 */ 00202 kMeansSegmentation(const kMeansSegmentation& other); 00203 00204 /** 00205 * destructor 00206 */ 00207 virtual ~kMeansSegmentation(); 00208 00209 /** 00210 * returns the name of this type ("kMeansSegmentation") 00211 */ 00212 virtual const char* getTypeName() const; 00213 00214 //------------------------------------------------------------------------- 00215 00216 /** 00217 * operates on the given %parameter. 00218 * @param src image with the source data. 00219 * @param dest resulting labeled mask 00220 * @return true if apply successful or false otherwise. 00221 */ 00222 bool apply(const image& src,matrix<int>& dest) const; 00223 00224 /** 00225 * operates on the given %parameter. 00226 * @param src image with the source data. 00227 * @param dest resulting labeled mask 00228 * @return true if apply successful or false otherwise. 00229 */ 00230 bool apply(const image& src,channel8& dest) const; 00231 00232 /** 00233 * operates on the given %parameter. 00234 * @param src image with the source data. 00235 * @param dest resulting labeled mask 00236 * @param pal the color palette found by the k-Means algorithm 00237 * @return true if apply successful or false otherwise. 00238 */ 00239 bool apply(const image& src,matrix<int>& dest,palette& pal) const; 00240 00241 /** 00242 * operates on the given %parameter. 00243 * @param src image with the source data. 00244 * @param dest resulting labeled mask 00245 * @param pal the color palette found by the k-Means algorithm 00246 * @return true if apply successful or false otherwise. 00247 */ 00248 bool apply(const image& src,channel8& dest,palette& pal) const; 00249 00250 /** 00251 * copy data of "other" functor. 00252 * @param other the functor to be copied 00253 * @return a reference to this functor object 00254 */ 00255 kMeansSegmentation& copy(const kMeansSegmentation& other); 00256 00257 /** 00258 * alias for copy member 00259 * @param other the functor to be copied 00260 * @return a reference to this functor object 00261 */ 00262 kMeansSegmentation& operator=(const kMeansSegmentation& other); 00263 00264 /** 00265 * returns a pointer to a clone of this functor. 00266 */ 00267 virtual functor* clone() const; 00268 00269 /** 00270 * returns used parameters 00271 */ 00272 const parameters& getParameters() const; 00273 }; 00274 } 00275 00276 #endif