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 .......: ltiLabelAdjacencyMap.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 18.11.2002 00030 * revisions ..: $Id: ltiLabelAdjacencyMap.h,v 1.8 2006/02/08 11:21:36 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_LABEL_ADJACENCY_MAP_H_ 00034 #define _LTI_LABEL_ADJACENCY_MAP_H_ 00035 00036 #include "ltiFunctor.h" 00037 #include "ltiImage.h" 00038 #include "ltiVector.h" 00039 #include "ltiSparseMatrix.h" 00040 00041 namespace lti { 00042 /** 00043 * Visualize a label mask in a color image 00044 * 00045 * This class draws a color image using as input a labeled mask. The 00046 * colors used for each label are chosen based on the adjacency, so that 00047 * two neighbor labels never get the same color. 00048 * 00049 * You can choose the kind of neighborhood used (4 or 8 neighborhood) and 00050 * the number of colors you want to use. 00051 * 00052 * @ingroup gVisualization 00053 */ 00054 class labelAdjacencyMap : public functor { 00055 public: 00056 /** 00057 * the parameters for the class labelAdjacencyMap 00058 */ 00059 class parameters : public functor::parameters { 00060 public: 00061 /** 00062 * default constructor 00063 */ 00064 parameters(); 00065 00066 /** 00067 * copy constructor 00068 * @param other the parameters object to be copied 00069 */ 00070 parameters(const parameters& other); 00071 00072 /** 00073 * destructor 00074 */ 00075 ~parameters(); 00076 00077 /** 00078 * returns name of this type 00079 */ 00080 const char* getTypeName() const; 00081 00082 /** 00083 * copy the contents of a parameters object 00084 * @param other the parameters object to be copied 00085 * @return a reference to this parameters object 00086 */ 00087 parameters& copy(const parameters& other); 00088 00089 /** 00090 * copy the contents of a parameters object 00091 * @param other the parameters object to be copied 00092 * @return a reference to this parameters object 00093 */ 00094 parameters& operator=(const parameters& other); 00095 00096 00097 /** 00098 * returns a pointer to a clone of the parameters 00099 */ 00100 virtual functor::parameters* clone() const; 00101 00102 /** 00103 * write the parameters in the given ioHandler 00104 * @param handler the ioHandler to be used 00105 * @param complete if true (the default) the enclosing begin/end will 00106 * be also written, otherwise only the data block will be written. 00107 * @return true if write was successful 00108 */ 00109 virtual bool write(ioHandler& handler,const bool complete=true) const; 00110 00111 /** 00112 * read the parameters from the given ioHandler 00113 * @param handler the ioHandler to be used 00114 * @param complete if true (the default) the enclosing begin/end will 00115 * be also written, otherwise only the data block will be written. 00116 * @return true if write was successful 00117 */ 00118 virtual bool read(ioHandler& handler,const bool complete=true); 00119 00120 # ifdef _LTI_MSC_6 00121 /** 00122 * this function is required by MSVC only, as a workaround for a 00123 * very awful bug, which exists since MSVC V.4.0, and still by 00124 * V.6.0 with all bugfixes (so called "service packs") remains 00125 * there... This method is also public due to another bug, so please 00126 * NEVER EVER call this method directly: use read() instead 00127 */ 00128 bool readMS(ioHandler& handler,const bool complete=true); 00129 00130 /** 00131 * this function is required by MSVC only, as a workaround for a 00132 * very awful bug, which exists since MSVC V.4.0, and still by 00133 * V.6.0 with all bugfixes (so called "service packs") remains 00134 * there... This method is also public due to another bug, so please 00135 * NEVER EVER call this method directly: use write() instead 00136 */ 00137 bool writeMS(ioHandler& handler,const bool complete=true) const; 00138 # endif 00139 00140 // ------------------------------------------------ 00141 // the parameters 00142 // ------------------------------------------------ 00143 00144 /** 00145 * If true, the mininum number of colors will be used, which will depend 00146 * on the neighborhood used. (a max of 4 colors is required for a 00147 * 4 neighborhood, and a max of 8 color for a 8 neighborhood). 00148 * 00149 * If false, all colors in the palette might be used. 00150 * 00151 * Default: false 00152 */ 00153 bool minColors; 00154 00155 /** 00156 * The colors used to denote the labels. Note that the assigment is not 00157 * 1 to 1, but will be done depending on the adjacency of the labels. 00158 * 00159 * Default: {lti::Black,lti::Red,lti::Green,lti::Blue,lti::Yellow, 00160 * lti::Cyan,lti::Magenta,lti::DarkOrange,lti::Lemon, 00161 * lti::Violet} 00162 * 00163 * This default palette can be access anytime as 00164 * lti::labelAdjacencyMap::parameters::defaultPalette 00165 */ 00166 palette thePalette; 00167 00168 /** 00169 * Neighborhood used. 00170 * 00171 * Valid values are 4 and 8. Other values will be considered as 00172 * 8-neighborhood. 00173 * 00174 * Default value: 8 00175 */ 00176 int neighborhood; 00177 00178 /** 00179 * Default color palette 00180 * 00181 * {lti::Black, lti::Red, lti::Green, lti::Blue, 00182 * lti::Yellow, lti::Cyan, lti::Magenta, lti::DarkOrange, 00183 * lti::Lemon, lti::Violet} 00184 */ 00185 static const palette defaultPalette; 00186 00187 }; 00188 00189 /** 00190 * default constructor 00191 */ 00192 labelAdjacencyMap(); 00193 00194 /** 00195 * Construct a functor using the given parameters 00196 */ 00197 labelAdjacencyMap(const parameters& par); 00198 00199 /** 00200 * copy constructor 00201 * @param other the object to be copied 00202 */ 00203 labelAdjacencyMap(const labelAdjacencyMap& other); 00204 00205 /** 00206 * destructor 00207 */ 00208 virtual ~labelAdjacencyMap(); 00209 00210 /** 00211 * returns the name of this type ("labelAdjacencyMap") 00212 */ 00213 virtual const char* getTypeName() const; 00214 00215 /** 00216 * operates on a copy of the given %parameters. 00217 * @param src channel8 with the source data. 00218 * @param dest image where the result will be left. 00219 * @return true if apply successful or false otherwise. 00220 */ 00221 bool apply(const matrix<ubyte>& src,image& dest) const; 00222 00223 /** 00224 * operates on a copy of the given %parameters. 00225 * @param src matrix<int> with the source data. 00226 * @param dest image where the result will be left. 00227 * @return true if apply successful or false otherwise. 00228 */ 00229 bool apply(const matrix<int>& src,image& dest) const; 00230 00231 /** 00232 * copy data of "other" functor. 00233 * @param other the functor to be copied 00234 * @return a reference to this functor object 00235 */ 00236 labelAdjacencyMap& copy(const labelAdjacencyMap& other); 00237 00238 /** 00239 * alias for copy member 00240 * @param other the functor to be copied 00241 * @return a reference to this functor object 00242 */ 00243 labelAdjacencyMap& operator=(const labelAdjacencyMap& other); 00244 00245 /** 00246 * returns a pointer to a clone of this functor. 00247 */ 00248 virtual functor* clone() const; 00249 00250 /** 00251 * returns used parameters 00252 */ 00253 const parameters& getParameters() const; 00254 00255 // protected: 00256 00257 /** 00258 * compute the adjacency of the labels of a given label mask 00259 */ 00260 bool adjacency(const matrix<ubyte>& mask,sparseMatrix<int>& dest) const; 00261 00262 /** 00263 * compute the adjacency of the labels of a given label mask 00264 */ 00265 bool adjacency(const matrix<int>& mask,sparseMatrix<int>& dest) const; 00266 00267 /** 00268 * compute the minimum palette required 00269 */ 00270 bool computeMinPalette(const sparseMatrix<int>& adj, 00271 palette& pal) const; 00272 00273 00274 /** 00275 * compute the palette required, using all colors in the parameters if 00276 * possible 00277 */ 00278 bool computeMaxPalette(const sparseMatrix<int>& adj, 00279 palette& pal) const; 00280 00281 }; 00282 } 00283 00284 #endif