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 .......: ltiHuMoments.h 00027 * authors ....: Suat Akyol 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 23.10.2001 00030 * revisions ..: $Id: ltiHuMoments.h,v 1.10 2006/02/08 11:18:25 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_HU_MOMENTS_H_ 00034 #define _LTI_HU_MOMENTS_H_ 00035 00036 #include "ltiMath.h" 00037 #include "ltiGlobalFeatureExtractor.h" 00038 00039 namespace lti { 00040 /** 00041 * Extracts the 7 moment invariants as described in "Visual Pattern Recognition 00042 * by Moment Invariants" by Ming-Kuei Hu (IRE Transactions on Information Theory, 00043 * 1962). 00044 */ 00045 class huMoments : public globalFeatureExtractor { 00046 public: 00047 // constant indices for accessing the result vectors 00048 static const int hu1; 00049 static const int hu2; 00050 static const int hu3; 00051 static const int hu4; 00052 static const int hu5; 00053 static const int hu6; 00054 static const int hu7; 00055 static const int xcog; 00056 static const int ycog; 00057 static const int eigen1; 00058 static const int eigen2; 00059 static const int orientation; 00060 static const int m00; 00061 00062 /** 00063 * the parameters for the class huMoments 00064 */ 00065 class parameters : public globalFeatureExtractor::parameters { 00066 public: 00067 /** 00068 * default constructor 00069 */ 00070 parameters(); 00071 00072 /** 00073 * copy constructor 00074 * @param other the parameters object to be copied 00075 */ 00076 parameters(const parameters& other); 00077 00078 /** 00079 * destructor 00080 */ 00081 ~parameters(); 00082 00083 /** 00084 * returns name of this type 00085 */ 00086 const char* getTypeName() const; 00087 00088 /** 00089 * copy the contents of a parameters object 00090 * @param other the parameters object to be copied 00091 * @return a reference to this parameters object 00092 */ 00093 parameters& copy(const parameters& other); 00094 00095 /** 00096 * copy the contents of a parameters object 00097 * @param other the parameters object to be copied 00098 * @return a reference to this parameters object 00099 */ 00100 parameters& operator=(const parameters& other); 00101 00102 00103 /** 00104 * returns a pointer to a clone of the parameters 00105 */ 00106 virtual functor::parameters* clone() const; 00107 00108 /** 00109 * write the parameters in the given ioHandler 00110 * @param handler the ioHandler to be used 00111 * @param complete if true (the default) the enclosing begin/end will 00112 * be also written, otherwise only the data block will be written. 00113 * @return true if write was successful 00114 */ 00115 virtual bool write(ioHandler& handler,const bool complete=true) const; 00116 00117 /** 00118 * read the parameters from the given ioHandler 00119 * @param handler the ioHandler to be used 00120 * @param complete if true (the default) the enclosing begin/end will 00121 * be also written, otherwise only the data block will be written. 00122 * @return true if write was successful 00123 */ 00124 virtual bool read(ioHandler& handler,const bool complete=true); 00125 00126 # ifdef _LTI_MSC_6 00127 /** 00128 * this function is required by MSVC only, as a workaround for a 00129 * very awful bug, which exists since MSVC V.4.0, and still by 00130 * V.6.0 with all bugfixes (so called "service packs") remains 00131 * there... This method is also public due to another bug, so please 00132 * NEVER EVER call this method directly: use read() instead 00133 */ 00134 bool readMS(ioHandler& handler,const bool complete=true); 00135 00136 /** 00137 * this function is required by MSVC only, as a workaround for a 00138 * very awful bug, which exists since MSVC V.4.0, and still by 00139 * V.6.0 with all bugfixes (so called "service packs") remains 00140 * there... This method is also public due to another bug, so please 00141 * NEVER EVER call this method directly: use write() instead 00142 */ 00143 bool writeMS(ioHandler& handler,const bool complete=true) const; 00144 # endif 00145 00146 // ------------------------------------------------ 00147 // the parameters 00148 // ------------------------------------------------ 00149 00150 /** 00151 * Since feature values can be very small, they can be scaled by the 00152 * monotonic function -sign(x)*log(abs(x)) by setting this to true. 00153 * Default is false 00154 */ 00155 bool scaling; 00156 00157 }; 00158 00159 /** 00160 * default constructor 00161 */ 00162 huMoments(); 00163 00164 /** 00165 * copy constructor 00166 * @param other the object to be copied 00167 */ 00168 huMoments(const huMoments& other); 00169 00170 /** 00171 * destructor 00172 */ 00173 virtual ~huMoments(); 00174 00175 /** 00176 * returns the name of this type ("huMoments") 00177 */ 00178 virtual const char* getTypeName() const; 00179 00180 /** 00181 * operates on a copy of the given %parameters. 00182 * @param src channel8 with the source data. 00183 * @param dest dvector containing the 7 hu moments. 00184 * @param more additional feature vector with 00185 * <ul> 00186 * <li>xcog 00187 * <li>ycog 00188 * <li>eigen1 00189 * <li>eigen2 00190 * <li>orientation [-Pi/2,Pi/2] 00191 * <li>m00 00192 * </ul> 00193 * @return true if apply successful or false otherwise. 00194 */ 00195 bool apply(const channel8& src, dvector& dest, dvector& more) const; 00196 00197 /** 00198 * operates on a copy of the given %parameters. 00199 * @param src channel with the source data. 00200 * @param dest dvector containing the 7 hu moments. 00201 * @param more additional feature vector with 00202 * <ul> 00203 * <li>xcog 00204 * <li>ycog 00205 * <li>eigen1 00206 * <li>eigen2 00207 * <li>orientation [-Pi/2,Pi/2] 00208 * <li>m00 00209 * </ul> 00210 * @return true if apply successful or false otherwise. 00211 */ 00212 bool apply(const channel& src, dvector& dest, dvector& more) const; 00213 00214 /** 00215 * operates on a copy of the given %parameters. 00216 * @param src channel8 with the source data. 00217 * @param dest dvector containing the 7 hu moments. 00218 * @return true if apply successful or false otherwise. 00219 */ 00220 bool apply(const channel8& src, dvector& dest) const; 00221 00222 /** 00223 * operates on a copy of the given %parameters. 00224 * @param src channel with the source data. 00225 * @param dest dvector containing the 7 hu moments. 00226 * @return true if apply successful or false otherwise. 00227 */ 00228 bool apply(const channel& src, dvector& dest) const; 00229 00230 /** 00231 * operates on a copy of the given %parameters. 00232 * @param src channel8 with the source data. 00233 * @param rect bounding rectangle of data to be regarded. 00234 * @param dest dvector containing the 7 hu moments. 00235 * @param more additional feature vector with 00236 * <ul> 00237 * <li>xcog 00238 * <li>ycog 00239 * <li>eigen1 00240 * <li>eigen2 00241 * <li>orientation [-Pi/2,Pi/2] 00242 * <li>m00 00243 * </ul> 00244 * @return true if apply successful or false otherwise. 00245 */ 00246 bool apply(const channel8& src, const rectangle& rect, dvector& dest, dvector& more) const; 00247 00248 /** 00249 * operates on a copy of the given %parameters. 00250 * @param src channel with the source data. 00251 * @param rect bounding rectangle of data to be regarded. 00252 * @param dest dvector containing the 7 hu moments. 00253 * @param more additional feature vector with 00254 * <ul> 00255 * <li>xcog 00256 * <li>ycog 00257 * <li>eigen1 00258 * <li>eigen2 00259 * <li>orientation [-Pi/2,Pi/2] 00260 * <li>m00 00261 * </ul> 00262 * @return true if apply successful or false otherwise. 00263 */ 00264 bool apply(const channel& src, const rectangle& rect, dvector& dest, dvector& more) const; 00265 00266 /** 00267 * operates on a copy of the given %parameters. 00268 * @param src channel8 with the source data. 00269 * @param rect bounding rectangle of data to be regarded. 00270 * @param dest dvector containing the 7 hu moments. 00271 * @return true if apply successful or false otherwise. 00272 */ 00273 bool apply(const channel8& src, const rectangle& rect, dvector& dest) const; 00274 00275 /** 00276 * operates on a copy of the given %parameters. 00277 * @param src channel with the source data. 00278 * @param rect bounding rectangle of data to be regarded. 00279 * @param dest dvector containing the 7 hu moments. 00280 * @return true if apply successful or false otherwise. 00281 */ 00282 bool apply(const channel& src, const rectangle& rect, dvector& dest) const; 00283 00284 /** 00285 * copy data of "other" functor. 00286 * @param other the functor to be copied 00287 * @return a reference to this functor object 00288 */ 00289 huMoments& copy(const huMoments& other); 00290 00291 /** 00292 * alias for copy member 00293 * @param other the functor to be copied 00294 * @return a reference to this functor object 00295 */ 00296 huMoments& operator=(const huMoments& other); 00297 00298 /** 00299 * returns a pointer to a clone of this functor. 00300 */ 00301 virtual functor* clone() const; 00302 00303 /** 00304 * returns used parameters 00305 */ 00306 const parameters& getParameters() const; 00307 00308 private: 00309 00310 /** 00311 * This is an internal function for computing sign(x)*log(abs(x)) 00312 * @param x value 00313 * @return sign(x)*log(abs(x)) 00314 */ 00315 double logn(double& x) const; 00316 }; 00317 } 00318 00319 #endif