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 .......: ltiGHoughTransform.h 00027 * authors ....: Jens Rietzschel 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 22.05.2001 00030 * revisions ..: $Id: ltiGHoughTransform.h,v 1.10 2007/01/10 02:25:54 alvarado Exp $ 00031 */ 00032 00033 00034 #ifndef _LTI_GND_HOUGH_TRANSFORM_H_ 00035 #define _LTI_GND_HOUGH_TRANSFORM_H_ 00036 00037 #include "ltiImage.h" 00038 #include "ltiModifier.h" 00039 #include "ltiPointList.h" 00040 #include "ltiTensor.h" 00041 #include <list> 00042 #include <map> 00043 00044 namespace lti { 00045 /** 00046 * \brief The Generalized-Hough-Transform 00047 * 00048 * The Generalized-Hough-Transform detects arbitrary shapes, which 00049 * have to be specified before (by use()). It transforms the channel 00050 * into a four dimensional parameter space (discretisation can be 00051 * set in parameters). Therefore it requires a lot of storage and 00052 * extensive computation. Peaks in parameter-space are searched and 00053 * returned as result. The found object can be drawn back into the 00054 * image by draw(). 00055 * 00056 * @see lti::orientedHLTransform 00057 */ 00058 class gHoughTransform : public modifier { 00059 public: 00060 /** 00061 * the parameters for the class houghTransform 00062 */ 00063 class parameters : public modifier::parameters { 00064 public: 00065 /** 00066 * default constructor 00067 */ 00068 parameters(); 00069 00070 /** 00071 * copy constructor 00072 * @param other the parameters object to be copied 00073 */ 00074 parameters(const parameters& other); 00075 00076 /** 00077 * destructor 00078 */ 00079 ~parameters(); 00080 00081 /** 00082 * returns name of this type 00083 */ 00084 const char* getTypeName() const; 00085 00086 /** 00087 * copy the contents of a parameters object 00088 * @param other the parameters object to be copied 00089 * @return a reference to this parameters object 00090 */ 00091 parameters& copy(const parameters& other); 00092 00093 /** 00094 * copy the contents of a parameters object 00095 * @param other the parameters object to be copied 00096 * @return a reference to this parameters object 00097 */ 00098 parameters& operator=(const parameters& other); 00099 00100 00101 /** 00102 * returns a pointer to a clone of the parameters 00103 */ 00104 virtual functor::parameters* clone() const; 00105 00106 /** 00107 * write the parameters in the given ioHandler 00108 * @param handler the ioHandler to be used 00109 * @param complete if true (the default) the enclosing begin/end will 00110 * be also written, otherwise only the data block will be written. 00111 * @return true if write was successful 00112 */ 00113 virtual bool write(ioHandler& handler,const bool complete=true) const; 00114 00115 /** 00116 * write the parameters in the given ioHandler 00117 * @param handler the ioHandler to be used 00118 * @param complete if true (the default) the enclosing begin/end will 00119 * be also written, otherwise only the data block will be written. 00120 * @return true if write was successful 00121 */ 00122 virtual bool read(ioHandler& handler,const bool complete=true); 00123 00124 # ifdef _LTI_MSC_6 00125 /** 00126 * this function is required by MSVC only, as a workaround for a 00127 * very awful bug, which exists since MSVC V.4.0, and still by 00128 * V.6.0 with all bugfixes (so called "service packs") remains 00129 * there... This method is also public due to another bug, so please 00130 * NEVER EVER call this method directly: use read() instead 00131 */ 00132 bool readMS(ioHandler& handler,const bool complete=true); 00133 00134 /** 00135 * this function is required by MSVC only, as a workaround for a 00136 * very awful bug, which exists since MSVC V.4.0, and still by 00137 * V.6.0 with all bugfixes (so called "service packs") remains 00138 * there... This method is also public due to another bug, so please 00139 * NEVER EVER call this method directly: use write() instead 00140 */ 00141 bool writeMS(ioHandler& handler,const bool complete=true) const; 00142 # endif 00143 00144 // ------------------------------------------------ 00145 // the parameters 00146 // ------------------------------------------------ 00147 00148 /** 00149 * Local maxima of parameter-space with values above 00150 * thresholdLocalMaximum are considered as found objects in 00151 * image-space. 00152 * 00153 * Values depend on number of pixels in image. Higher values 00154 * fasten the search for maxima. 00155 * 00156 * Default:10 00157 */ 00158 float thresholdLocalMaximum; 00159 00160 00161 /** 00162 * kernelSize is size of environment which is considered in 00163 * search for local maxima at each position in parameter-space 00164 * for row and column. 00165 * 00166 * Default: 11 00167 */ 00168 int kernelSizeTranslation; 00169 00170 /** 00171 * kernelSizeRotation is size of environment which is considered 00172 * in search for local maxima at each position in parameter-space 00173 * for rotation. 00174 * 00175 * Default: 21 00176 */ 00177 int kernelSizeRotation; 00178 00179 /** 00180 * kernelSizeSize is size of environment which is considered in 00181 * search for local maxima at each position in parameter-space 00182 * for size 00183 * 00184 * Default: 11 00185 */ 00186 int kernelSizeScale; 00187 00188 /** 00189 * number of Objects to be found (default 1) 00190 */ 00191 int numberOfObjects; 00192 00193 /** 00194 * Values above thresholdEdgePixel are considered as pixel of edges and 00195 * transformed into parameter space. 00196 * 00197 * Best to use previously an edge detector e.g. susanEdges. 00198 * 00199 * default 0.9 00200 */ 00201 float thresholdEdgePixel; 00202 00203 /** 00204 * true: search for local maxima (is very computational intensive) 00205 * false: search for global maxima (is faster and default) 00206 */ 00207 00208 bool findLocalMaximum; 00209 00210 /** 00211 * size of third dimension of parameter-space 00212 * discretisation of parameter size 00213 */ 00214 int disSize; 00215 00216 /** 00217 * size of forth dimension of parameter-space 00218 * discretisation of paramter rotation 00219 */ 00220 int disRotation; 00221 00222 /** 00223 * range of object-extension which is considered 00224 */ 00225 float extension; 00226 00227 /** 00228 * Number of lists regarded for each pixel symmetrical to its 00229 * orientation angle phi. High values gain better result but more 00230 * computational intensive. 00231 */ 00232 int numberOfAngleLists; 00233 00234 }; 00235 00236 /** 00237 * default constructor 00238 */ 00239 gHoughTransform(); 00240 00241 /** 00242 * copy constructor 00243 * @param other the object to be copied 00244 */ 00245 gHoughTransform(const gHoughTransform& other); 00246 00247 /** 00248 * destructor 00249 */ 00250 virtual ~gHoughTransform(); 00251 00252 /** 00253 * returns the name of this type ("houghTransform") 00254 */ 00255 virtual const char* getTypeName() const; 00256 00257 00258 /** 00259 * @param src channel of object which is to be found later on 00260 */ 00261 bool use (const channel& src); 00262 00263 /** 00264 * @param src tpointList of object which is to be found later on 00265 */ 00266 bool use (const tpointList<int>& src); 00267 00268 00269 00270 /** 00271 * Apply 00272 * 00273 * @param src: find object specified by use in channel src 00274 * @param dest: list containing vectors, that each represent 00275 * a found object by five entries: shift_x, 00276 * shift_y,size factor,rotation,relevance 00277 */ 00278 bool apply(const channel& src,std::list<vector<float> >& dest); 00279 00280 /** 00281 * Apply 00282 * 00283 * @param sample: channel of object which is to be found later on 00284 * @param src: find object specified by sample in channel src 00285 * @param dest: list containing vectors, that each represent 00286 * a found object by five entries: shift_x, 00287 * shift_y,size factor,rotation,relevance 00288 */ 00289 bool apply(const channel& sample,const channel& src, 00290 std::list<vector<float> >& dest); 00291 00292 /** 00293 * Apply 00294 * 00295 * @param contour: tpointList of object which is to be found later on 00296 * @param src: find object specified by contour in channel src 00297 * @param dest: list containing vectors, that each represent 00298 * a found object by five entries: shift_x, 00299 * shift_y,size factor,rotation,relevance 00300 */ 00301 bool apply(const tpointList<int>& contour,const channel& src, 00302 std::list<vector<float> >& dest); 00303 00304 /** 00305 * Draw 00306 * 00307 * @param src: list containing vectors, that each represent 00308 * a found object by five entries: shift_x, 00309 * shift_y,size factor,rotation,relevance 00310 * and is computed by apply-method 00311 * @param dest: draw into this image 00312 * @param color: use this color for drawing 00313 */ 00314 bool draw(const std::list<vector<float> >& src, 00315 image& dest, 00316 const rgbPixel& color=rgbPixel(255,0,0)); 00317 00318 /** 00319 * copy data of "other" functor. 00320 * @param other the functor to be copied 00321 * @return a reference to this functor object 00322 */ 00323 gHoughTransform& copy(const gHoughTransform& other); 00324 00325 /** 00326 * returns a pointer to a clone of this functor. 00327 */ 00328 virtual functor* clone() const; 00329 00330 /** 00331 * returns used parameters 00332 */ 00333 const parameters& getParameters() const; 00334 00335 private: 00336 00337 //used to store maxima of parameterspace 00338 class listEntry{ 00339 public: 00340 int row; 00341 int column; 00342 int sizeIndex; 00343 int rotationIndex; 00344 float value; 00345 bool operator<(const listEntry& a); 00346 }; 00347 00348 00349 // used within findMaximum4D to check minimum distances according 00350 // to kernelsize 00351 bool distance_remove(std::list<listEntry>& src,int& n); 00352 00353 //searches for maxima in parametersspace (global/local) 00354 bool findMaximum4D(tensor<float>& accu,int rows,int columns,int disSize, 00355 int disRotation, std::list<listEntry>& dest); 00356 00357 //data structure used for representation of object to find (map) 00358 class referenceTable{ 00359 public: 00360 referenceTable(); 00361 referenceTable(const channel& src,float threshold,int disRTable); 00362 referenceTable(const tpointList<int>& src,int disRTable); 00363 bool push (float alpha,float r,double phi); 00364 bool getAlphaRList(double phi,double rotation,tpointList<float>& dest); 00365 bool buildReferenceTable(const channel& src, 00366 float threshold, 00367 int disRTable); 00368 bool buildReferenceTable(const tpointList<int>& src,int disRTable); 00369 00370 std::map<int,tpointList<float> > refTable; 00371 tpointList<int> allPoints; 00372 tpoint<int> anchor; 00373 private: 00374 int numberOfAngleLists; 00375 }; 00376 00377 // member referenceTable 00378 referenceTable myReferenceTable; 00379 00380 // true if initialised by use(sample) or apply(sample) 00381 bool isSet; 00382 00383 }; 00384 } 00385 #endif