latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 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 .......: ltiQuadTreeSegmentation.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 15.12.2003 00030 * revisions ..: $Id: ltiQuadTreeSegmentation.h,v 1.5 2006/02/08 11:43:16 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_QUAD_TREE_SEGMENTATION_H_ 00034 #define _LTI_QUAD_TREE_SEGMENTATION_H_ 00035 00036 #include "ltiMacroSymbols.h" 00037 00038 // only for compilers different than VC++ 6.0 available 00039 #ifdef _LTI_MSC_6 00040 00041 #pragma message("Insufficient C++ Template Support for lti::regionGraphMeans.") 00042 #pragma message("You need a newer compiler") 00043 00044 #else 00045 00046 #include "ltiVector.h" 00047 #include "ltiSegmentation.h" 00048 #include "ltiTree.h" 00049 #include "ltiImage.h" 00050 00051 namespace lti { 00052 /** 00053 * Quad-Tree based color image segmentation method. 00054 * 00055 * This is a very simple but inefficient method to segment color 00056 * images. It is provided because it is one of the classical 00057 * methods of split-and-merge segmentation techniques. 00058 * 00059 * A quad-tree based partition of the image if first done, and after that 00060 * neighbor regions are merged if they are similar enough. 00061 */ 00062 class quadTreeSegmentation : public segmentation { 00063 public: 00064 /** 00065 * The parameters for the class quadTreeSegmentation 00066 */ 00067 class parameters : public segmentation::parameters { 00068 public: 00069 /** 00070 * Default constructor 00071 */ 00072 parameters(); 00073 00074 /** 00075 * Copy constructor 00076 * @param other the parameters object to be copied 00077 */ 00078 parameters(const parameters& other); 00079 00080 /** 00081 * Destructor 00082 */ 00083 ~parameters(); 00084 00085 /** 00086 * Returns name of this type 00087 */ 00088 const char* getTypeName() const; 00089 00090 /** 00091 * Copy the contents of a parameters object 00092 * @param other the parameters object to be copied 00093 * @return a reference to this parameters object 00094 */ 00095 parameters& copy(const parameters& other); 00096 00097 /** 00098 * Copy the contents of a parameters object 00099 * @param other the parameters object to be copied 00100 * @return a reference to this parameters object 00101 */ 00102 parameters& operator=(const parameters& other); 00103 00104 00105 /** 00106 * Returns a pointer to a clone of the parameters 00107 */ 00108 virtual functor::parameters* clone() const; 00109 00110 /** 00111 * Write the parameters in the given ioHandler 00112 * @param handler the ioHandler to be used 00113 * @param complete if true (the default) the enclosing begin/end will 00114 * be also written, otherwise only the data block will be written. 00115 * @return true if write was successful 00116 */ 00117 virtual bool write(ioHandler& handler,const bool complete=true) const; 00118 00119 /** 00120 * Read the parameters from the given ioHandler 00121 * @param handler the ioHandler to be used 00122 * @param complete if true (the default) the enclosing begin/end will 00123 * be also written, otherwise only the data block will be written. 00124 * @return true if write was successful 00125 */ 00126 virtual bool read(ioHandler& handler,const bool complete=true); 00127 00128 # ifdef _LTI_MSC_6 00129 /** 00130 * This function is required by MSVC only, as a workaround for a 00131 * very awful bug, which exists since MSVC V.4.0, and still by 00132 * V.6.0 with all bugfixes (so called "service packs") remains 00133 * there... This method is also public due to another bug, so please 00134 * NEVER EVER call this method directly: use read() instead 00135 */ 00136 bool readMS(ioHandler& handler,const bool complete=true); 00137 00138 /** 00139 * This function is required by MSVC only, as a workaround for a 00140 * very awful bug, which exists since MSVC V.4.0, and still by 00141 * V.6.0 with all bugfixes (so called "service packs") remains 00142 * there... This method is also public due to another bug, so please 00143 * NEVER EVER call this method directly: use write() instead 00144 */ 00145 bool writeMS(ioHandler& handler,const bool complete=true) const; 00146 # endif 00147 00148 // ------------------------------------------------ 00149 // the parameters 00150 // ------------------------------------------------ 00151 00152 /** 00153 * If any of the std. deviation of the R,G or B components of the colors 00154 * in a region exceeds one of the given threshold, the region will be 00155 * split. 00156 * 00157 * The value range of the given components is assumed to be between 00158 * 0 and 255. 00159 * 00160 * Default value: 5 00161 */ 00162 float splitThreshold; 00163 00164 /** 00165 * If two neighbor regions have in all three color components a 00166 * mean distance under the given threshold, they will be merged. 00167 * 00168 * Default value: 3 00169 */ 00170 float mergeThreshold; 00171 00172 /** 00173 * Minimum region size in the split stage. 00174 * 00175 * This value must always be greater or equal (1,1) 00176 * 00177 * Default value: (3,3) 00178 */ 00179 point minRegionSize; 00180 }; 00181 00182 /** 00183 * Default constructor 00184 */ 00185 quadTreeSegmentation(); 00186 00187 /** 00188 * Construct a functor using the given parameters 00189 */ 00190 quadTreeSegmentation(const parameters& par); 00191 00192 /** 00193 * Copy constructor 00194 * @param other the object to be copied 00195 */ 00196 quadTreeSegmentation(const quadTreeSegmentation& other); 00197 00198 /** 00199 * Destructor 00200 */ 00201 virtual ~quadTreeSegmentation(); 00202 00203 /** 00204 * Returns the name of this type ("quadTreeSegmentation") 00205 */ 00206 virtual const char* getTypeName() const; 00207 00208 /** 00209 * Generate a second color image, where each found region gets the mean 00210 * color obtain from the original image. 00211 * 00212 * This is not the real segmentation, but for visualization purposes some 00213 * times this is the desired functionality. 00214 * 00215 * @param src image with the source data. 00216 * @param dest image where the result will be left. 00217 * @return true if apply successful or false otherwise. 00218 */ 00219 bool apply(const image& src,image& dest) const; 00220 00221 /** 00222 * Generate a second color image, where each found region gets the mean 00223 * color obtain from the original image. 00224 * 00225 * This is not the real segmentation, but for visualization purposes some 00226 * times this is the desired functionality. 00227 * 00228 * @param src image with the source data. 00229 * @param mask labeled mask with the segmented regions. 00230 * @param pal color palette for each region (the mean value) 00231 * @return true if apply successful or false otherwise. 00232 */ 00233 bool apply(const image& src, 00234 imatrix& mask, 00235 palette& pal) const; 00236 00237 00238 /** 00239 * Split the given image using a quad-tree strategy. 00240 * 00241 * Each detected region will have its own label in the resulting mask. 00242 * 00243 * @param img input color image 00244 * @param mask labeled mask with one integer ID per detected region. 00245 * @return true if successful or false otherwise. 00246 */ 00247 bool split(const image& img, 00248 imatrix& mask) 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 quadTreeSegmentation& copy(const quadTreeSegmentation& 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 quadTreeSegmentation& operator=(const quadTreeSegmentation& 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 protected: 00275 00276 /** 00277 * Compute the std. deviations in the given region of the image 00278 */ 00279 bool stats(const image& img, 00280 const point& from, 00281 const point& to, 00282 trgbPixel<float>& stats) const; 00283 /** 00284 * Recursively compute the quad-tree for the image 00285 */ 00286 bool split(const image& img, 00287 const float& threshold, 00288 const point& minSize, 00289 tree<rectangle>::node& qtree) const; 00290 }; 00291 } 00292 00293 #endif 00294 #endif