latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2000, 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 .......: ltiChromaticityHistogram.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 12.10.2000 00030 * revisions ..: $Id: ltiChromaticityHistogram.h,v 1.8 2006/02/07 18:35:37 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_CHROMATICITY_HISTOGRAM_H_ 00034 #define _LTI_CHROMATICITY_HISTOGRAM_H_ 00035 00036 #include "ltiContour.h" 00037 #include "ltiObject.h" 00038 #include "ltiMatrix.h" 00039 #include "ltiHistogram.h" 00040 #include "ltiGlobalFeatureExtractor.h" 00041 00042 namespace lti { 00043 00044 00045 /** 00046 * Create a chromaticity histrogram feature vector. 00047 * Due to the fact that chromaticity has no information contents on 00048 * intensity, this feature is highly illumination invariant. 00049 * The 2D chromaticity-histogram is a triangular matrix and will be 00050 * coded in the 1D feature vector to save memory space. 00051 * @see chromaticityHistogram::parameters 00052 */ 00053 class chromaticityHistogram : public globalFeatureExtractor { 00054 public: 00055 /** 00056 * the parameters for the class chromaticityHistogram 00057 */ 00058 class parameters : public globalFeatureExtractor::parameters { 00059 public: 00060 /** 00061 * default constructor 00062 */ 00063 parameters(); 00064 00065 /** 00066 * copy constructor 00067 * @param other the parameters object to be copied 00068 */ 00069 parameters(const parameters& other); 00070 00071 /** 00072 * destructor 00073 */ 00074 ~parameters(); 00075 00076 /** 00077 * returns name of this type 00078 */ 00079 const char* getTypeName() const; 00080 00081 /** 00082 * copy the contents of a parameters object 00083 * @param other the parameters object to be copied 00084 * @return a reference to this parameters object 00085 */ 00086 parameters& copy(const parameters& other); 00087 00088 /** 00089 * returns a pointer to a clone of the parameters 00090 */ 00091 virtual functor::parameters* clone() const; 00092 00093 /** 00094 * write the parameters in the given ioHandler 00095 * @param handler the ioHandler to be used 00096 * @param complete if true (the default) the enclosing begin/end will 00097 * be also written, otherwise only the data block will be written. 00098 * @return true if write was successful 00099 */ 00100 virtual bool write(ioHandler& handler,const bool complete=true) 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 read(ioHandler& handler,const bool complete=true); 00110 00111 # ifdef _LTI_MSC_6 00112 /** 00113 * this function is required by MSVC only, as a workaround for a 00114 * very awful bug, which exists since MSVC V.4.0, and still by 00115 * V.6.0 with all bugfixes (so called "service packs") remains 00116 * there... This method is public due to another bug, so please 00117 * NEVER EVER call this method directly: use read() instead! 00118 */ 00119 bool readMS(ioHandler& handler,const bool complete=true); 00120 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 public due to another bug, so please 00126 * NEVER EVER call this method directly: use write() instead! 00127 */ 00128 bool writeMS(ioHandler& handler,const bool complete=true) const; 00129 # endif 00130 00131 // ------------------------------------------------ 00132 // the parameters 00133 // ------------------------------------------------ 00134 00135 /** 00136 * To compensate illumination variations, the norm of a 00137 * pixel-neighbourhood centered on the analyzed pixel will be 00138 * calculated. The following factor will be multiplied by the 00139 * number of rows of the analyzed image to get the height of the 00140 * neighbourhood. */ 00141 float verticalNeighbourhood; 00142 00143 /** 00144 * To compensate illumination variations, the norm of a 00145 * pixel-neighbourhood centered on the analyzed pixel will be 00146 * calculated. The following factor will be multiplied by the 00147 * number of columns of the analyzed image to get the size of the 00148 * neighbourhood. */ 00149 float horizontalNeighbourhood; 00150 00151 /** 00152 * type used in the norm specification 00153 */ 00154 enum eNormType { 00155 NoNorm, /*! Do not normalize */ 00156 L1, /*!< L1 norm */ 00157 L2 /*!< L2 norm */ 00158 }; 00159 00160 /** 00161 * Which kind of normalization should be used? (Default L2 Norm) 00162 */ 00163 eNormType norm; 00164 00165 /** 00166 * Dimension of the 1D gaussian kernel which is used to smooth the 00167 * resulting 1D histogram 00168 */ 00169 int smoothingKernelSize; 00170 00171 /** 00172 * The number of cells in the histogram to store the 00173 * green-chromaticity values 00174 */ 00175 int greenCells; 00176 00177 /** 00178 * The number of cells in the histogram to store the 00179 * red-chromaticity values 00180 */ 00181 int redCells; 00182 00183 /** 00184 * The value of the background will be ignored in the histogram 00185 */ 00186 rgbPixel backgroundColor; 00187 }; 00188 00189 /** 00190 * accumulator class of the squares of the values 00191 */ 00192 template<class T> 00193 class l2accumulator { 00194 public: 00195 /** 00196 * default constructor 00197 */ 00198 l2accumulator() : acc(T()) {}; 00199 00200 /** 00201 * accumulation operator 00202 */ 00203 inline const T& operator+=(const T& x) { 00204 acc+=(x*x); return acc; 00205 }; 00206 00207 /** 00208 * deaccumulation operator 00209 */ 00210 inline const T& operator-=(const T& x) { 00211 acc-=(x*x); return acc; 00212 }; 00213 00214 /** 00215 * division operator 00216 */ 00217 inline T operator/(const T& y) { 00218 return ((acc>0) ? sqrt(acc)/y : 0); 00219 }; 00220 00221 /** 00222 * cast operator to type T 00223 */ 00224 operator T() const {return ((acc>0) ? sqrt(acc) :0) ;}; 00225 00226 /** 00227 * assignment operator 00228 */ 00229 const T& operator=(const T& x) {acc=x*x; return (x);}; 00230 00231 protected: 00232 T acc; 00233 }; 00234 00235 /** 00236 * default constructor 00237 */ 00238 chromaticityHistogram(); 00239 00240 /** 00241 * copy constructor 00242 * @param other the object to be copied 00243 */ 00244 chromaticityHistogram(const chromaticityHistogram& other); 00245 00246 /** 00247 * destructor 00248 */ 00249 virtual ~chromaticityHistogram(); 00250 00251 /** 00252 * returns the name of this type ("chromaticityHistogram") 00253 */ 00254 virtual const char* getTypeName() const; 00255 00256 /** 00257 * operates on the given %parameter. 00258 * @param src image with the source data. 00259 * @param chrHist the feature vector will be left here 00260 * @result a reference to the <code>chrHist</code>. 00261 */ 00262 bool apply(const image& src,dvector& chrHist) const; 00263 00264 /** 00265 * copy data of "other" functor. 00266 * @param other the functor to be copied 00267 * @return a reference to this functor object 00268 */ 00269 chromaticityHistogram& copy(const chromaticityHistogram& other); 00270 00271 /** 00272 * returns a pointer to a clone of this functor. 00273 */ 00274 virtual functor* clone() const; 00275 00276 /** 00277 * returns used parameters 00278 */ 00279 const parameters& getParameters() const; 00280 }; 00281 } 00282 00283 #endif