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 .......: ltiDilation.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 19.7.2000 00030 * revisions ..: $Id: ltiDilation.h,v 1.12 2006/02/07 18:44:54 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_DILATION_H_ 00034 #define _LTI_DILATION_H_ 00035 00036 #include "ltiObject.h" 00037 #include "ltiMath.h" 00038 #include "ltiImage.h" 00039 #include "ltiLinearKernels.h" 00040 #include "ltiMorphology.h" 00041 #include "ltiConvolutionHelper.h" 00042 00043 namespace lti { 00044 /** 00045 * Dilation functor. 00046 * 00047 * This functor implements the morphological operator "dilation". 00048 * Through the parameters a "binary" or "gray scale" modus can be choosen, 00049 * and the structuring element (represented by a linear filter kernel) can 00050 * be given. 00051 * 00052 * For mode Binary the destination image is set to the norm value of 00053 * the kernel used if there is a source element in the kernel region 00054 * that is not zero and to zero otherwise. 00055 * 00056 * The definition for mode Gray can be found in e.g. Gonzalez, 00057 * R. and Woods, R. Digital Image Processing, 2nd Edition, 00058 * pp. 550--553, Prentice Hall, 2002 00059 * 00060 * /code 00061 * dest(s,t) = max(src(s-x, t-y) + kernel(x,y)) 00062 * /endcode 00063 * 00064 * where the regions of the kernel and source overlap. Qualitatively 00065 * the Gray operation results in brightening esp. dark details. For 00066 * channel8 the resulting values are clipped to be in the allowed 00067 * range of [0,255]. Note that for channels the kernel values should 00068 * be much lower than the default 1.f. Also note that when the 00069 * kernel is separable (sepKernel) the values of all column and row 00070 * kernels are subtracted. An example is chessBoardKernel. 00071 * 00072 * 00073 * Example: 00074 * 00075 * \code 00076 * lti::dilation dilator; // the dilation functor 00077 * lti::dilation::parameters dilationParam; // the parameters 00078 * 00079 * lti::euclideanKernel<float> theKern(3); // a circular kernel 00080 * 00081 * // binary dilation 00082 * dilationParam.mode = lti::dilation::parameters::Binary; 00083 * dilationParam.setKernel(theKern); 00084 * 00085 * // set the parameters 00086 * dilator.setParameters(dilationParam); 00087 * 00088 * // apply the dilation to a channel "chnlSrc" and leave the result in 00089 * // "chnlDest" 00090 * 00091 * dilator.apply(chnlSrc,chnlDest); 00092 * \endcode 00093 * 00094 * @ingroup gMorphology 00095 */ 00096 class dilation : public morphology { 00097 public: 00098 /** 00099 * the parameters for the class dilation 00100 */ 00101 class parameters : public morphology::parameters { 00102 public: 00103 /** 00104 * type to specify what kind of dilation should be applied. See 00105 * lti::dilation for more information. 00106 */ 00107 enum eMode { 00108 Binary, /*!< Binary dilation */ 00109 Gray /*!< Gray valued dilation */ 00110 }; 00111 00112 /** 00113 * default constructor 00114 */ 00115 parameters(); 00116 00117 /** 00118 * copy constructor 00119 * @param other the parameters object to be copied 00120 */ 00121 parameters(const parameters& other); 00122 00123 /** 00124 * destructor 00125 */ 00126 ~parameters(); 00127 00128 /** 00129 * returns name of this type 00130 */ 00131 const char* getTypeName() const; 00132 00133 /** 00134 * copy the contents of a parameters object 00135 * @param other the parameters object to be copied 00136 * @return a reference to this parameters object 00137 */ 00138 parameters& copy(const parameters& other); 00139 00140 /** 00141 * returns a pointer to a clone of the parameters 00142 */ 00143 virtual functor::parameters* clone() const; 00144 00145 /** 00146 * sets the filter kernel to be used. 00147 * A copy of the given parameter will be made! 00148 * @param aKernel the filter kernel to be used 00149 */ 00150 void setKernel(const mathObject& aKernel); 00151 00152 /** 00153 * returns the kernel in use. If it is not set yet, an 00154 * lti::invalidParameters exception will be thrown 00155 * @return a const reference to the filter kernel. 00156 */ 00157 const mathObject& getKernel() const; 00158 00159 /** 00160 * write the parameters in the given ioHandler 00161 * @param handler the ioHandler to be used 00162 * @param complete if true (the default) the enclosing begin/end will 00163 * be also written, otherwise only the data block will be written. 00164 * @return true if write was successful 00165 */ 00166 virtual bool write(ioHandler& handler,const bool complete=true) const; 00167 00168 /** 00169 * write the parameters in the given ioHandler 00170 * @param handler the ioHandler to be used 00171 * @param complete if true (the default) the enclosing begin/end will 00172 * be also written, otherwise only the data block will be written. 00173 * @return true if write was successful 00174 */ 00175 virtual bool read(ioHandler& handler,const bool complete=true); 00176 00177 # ifdef _LTI_MSC_6 00178 /** 00179 * this function is required by MSVC only, as a workaround for a 00180 * very awful bug, which exists since MSVC V.4.0, and still by 00181 * V.6.0 with all bugfixes (so called "service packs") remains 00182 * there... This method is public due to another bug, so please 00183 * NEVER EVER call this method directly: use read() instead! 00184 */ 00185 bool readMS(ioHandler& handler,const bool complete=true); 00186 00187 /** 00188 * this function is required by MSVC only, as a workaround for a 00189 * very awful bug, which exists since MSVC V.4.0, and still by 00190 * V.6.0 with all bugfixes (so called "service packs") remains 00191 * there... This method is public due to another bug, so please 00192 * NEVER EVER call this method directly: use write() instead! 00193 */ 00194 bool writeMS(ioHandler& handler,const bool complete=true) const; 00195 # endif 00196 00197 // --------------------------------------------------- 00198 // the parameters 00199 // --------------------------------------------------- 00200 00201 /** 00202 * Dilation mode. 00203 * 00204 * The dilation is defined for "Binary" images (only two values per 00205 * pixel) and for gray scaled images (channels or channel8). 00206 * In "Binary" modus, the channels and channel8s will be interpreted as 00207 * binary with 0 as "0" and everything else as "1" 00208 * The default value is "Binary" 00209 */ 00210 eMode mode; 00211 00212 protected: 00213 /** 00214 * The kernel to be used. This parameter can only be set through the 00215 * setKernel member. 00216 */ 00217 mathObject* kernel; 00218 }; 00219 00220 /** 00221 * default constructor 00222 */ 00223 dilation(); 00224 00225 /** 00226 * construct with the given kernel 00227 */ 00228 dilation(const mathObject& aKernel); 00229 00230 /** 00231 * copy constructor 00232 * @param other the object to be copied 00233 */ 00234 dilation(const dilation& other); 00235 00236 /** 00237 * destructor 00238 */ 00239 virtual ~dilation(); 00240 00241 /** 00242 * returns the name of this type ("dilation") 00243 */ 00244 virtual const char* getTypeName() const; 00245 00246 /** 00247 * operates on the given parameter. 00248 * @param srcdest channel with the source data. The result 00249 * will be left here too. 00250 * @return true if successful, false otherwise. 00251 */ 00252 bool apply(channel& srcdest) const; 00253 00254 /** 00255 * operates on the given parameter. 00256 * @param srcdest channel8 with the source data. The result 00257 * will be left here too. 00258 * @return true if successful, false otherwise. 00259 */ 00260 bool apply(channel8& srcdest) const; 00261 00262 /** 00263 * operates on the given parameter. 00264 * @param srcdest fvector with the source data. The result 00265 * will be left here too. 00266 * @return true if successful, false otherwise. 00267 */ 00268 bool apply(fvector& srcdest) const; 00269 00270 /** 00271 * operates on the given parameter. 00272 * @param srcdest vector<channel8::value_type> with the source data. 00273 * The result will be left here too. 00274 * @return true if successful, false otherwise. 00275 */ 00276 bool apply(vector<channel8::value_type>& srcdest) const; 00277 00278 /** 00279 * operates on a copy of the given parameters. 00280 * @param src channel with the source data. 00281 * @param dest channel where the result will be left. 00282 * @result true if ok, false otherwise. 00283 */ 00284 bool apply(const channel& src,channel& dest) const; 00285 00286 /** 00287 * operates on a copy of the given parameters. 00288 * @param src channel8 with the source data. 00289 * @param dest channel8 where the result will be left. 00290 * @result true if ok, false otherwise. 00291 */ 00292 bool apply(const channel8& src,channel8& dest) const; 00293 00294 /** 00295 * operates on a copy of the given parameters. 00296 * @param src fvector with the source data. 00297 * @param dest fvector where the result will be left. 00298 * @result true if ok, false otherwise. 00299 */ 00300 bool apply(const fvector& src,fvector& dest) const; 00301 00302 /** 00303 * operates on a copy of the given parameters. 00304 * @param src vector<channel8::value_type> with the source data. 00305 * @param dest vector<channel8::value_type> where the result will be left. 00306 * @result true if ok, false otherwise. 00307 */ 00308 bool apply(const vector<channel8::value_type>& src, 00309 vector<channel8::value_type>& dest) const; 00310 00311 /** 00312 * copy data of "other" functor. 00313 * @param other the functor to be copied 00314 * @return a reference to this functor object 00315 */ 00316 dilation& copy(const dilation& other); 00317 00318 /** 00319 * returns a pointer to a clone of this functor. 00320 */ 00321 virtual functor* clone() const; 00322 00323 /** 00324 * returns used parameters 00325 */ 00326 const parameters& getParameters() const; 00327 /** 00328 * shortcut to set the filter kernel in the functor parameters. 00329 * The other parameters remain unchanged. 00330 */ 00331 void setKernel(const mathObject& aKernel); 00332 00333 private: 00334 /** 00335 * This is the accumulator class needed by the convolution helper to 00336 * act as a dilation operator for gray valued images. 00337 * 00338 * The type T is the type of the elements of the object to be filtered 00339 * The (optional) type U is the type of the accumulator variable for 00340 * the filter. 00341 */ 00342 template<class T,class U=T> 00343 class accumulatorGray { 00344 public: 00345 /** 00346 * Default constructor 00347 */ 00348 accumulatorGray(); 00349 00350 /** 00351 * Accumulate the values of filter and src 00352 */ 00353 inline void accumulate(const T& filter,const T& src); 00354 00355 /** 00356 * Accumulate the values of T(0) and src 00357 */ 00358 inline void accumulateZero(const T& src); 00359 00360 /** 00361 * Accumulate the values of filter and srcL and srcR 00362 * for symmetric filter kernel 00363 * src: srcL * middle * srcR 00364 * filter: * * * middle * * * 00365 * used filter part: * * * middle 00366 */ 00367 inline void accumulateSym(const T& filter,const T& srcL,const T& srcR); 00368 00369 /** 00370 * Accumulate the values of filter and src 00371 * for asymmetric filter kernel 00372 * src: srcL * middle * srcR 00373 * filter: * * * middle * * * 00374 * used filter part: * * * middle 00375 */ 00376 inline void accumulateASym(const T& filter,const T& srcL,const T& srcR); 00377 00378 00379 /** 00380 * Get the state of the accumulator 00381 */ 00382 inline T getResult() const; 00383 00384 /** 00385 * Reset the state of the accumulator 00386 */ 00387 inline void reset(); 00388 00389 /** 00390 * set norm (unused) 00391 */ 00392 inline void setNorm(const T& n); 00393 00394 protected: 00395 /** 00396 * the accumulated value 00397 */ 00398 U state; 00399 00400 /** 00401 * the norm 00402 */ 00403 T norm; 00404 }; 00405 00406 /** 00407 * This is the accumulator class needed by the convolution helper to 00408 * act as a dilation operator for binary valued images. 00409 * 00410 * The type T is the type of the elements of the object to be filtered 00411 * The (optional) type U is the type of the accumulator variable for 00412 * the filter. 00413 */ 00414 template<class T,class U=T> 00415 class accumulatorBin { 00416 public: 00417 /** 00418 * Default constructor 00419 */ 00420 accumulatorBin(); 00421 00422 /** 00423 * Accumulate the values of filter and src 00424 */ 00425 inline void accumulate(const T& filter,const T& src); 00426 00427 /** 00428 * Accumulate the values of T(0) and src 00429 */ 00430 inline void accumulateZero(const T& src); 00431 00432 /** 00433 * Accumulate the values of filter and srcL and srcR 00434 * for symmetric filter kernel 00435 * src: srcL * middle * srcR 00436 * filter: * * * middle * * * 00437 * used filter part: * * * middle 00438 */ 00439 inline void accumulateSym(const T& filter,const T& srcL,const T& srcR); 00440 00441 /** 00442 * Accumulate the values of filter and src 00443 * for asymmetric filter kernel 00444 * src: srcL * middle * srcR 00445 * filter: * * * middle * * * 00446 * used filter part: * * * middle 00447 */ 00448 inline void accumulateASym(const T& filter,const T& srcL,const T& srcR); 00449 00450 00451 /** 00452 * Get the state of the accumulator 00453 */ 00454 inline T getResult() const; 00455 00456 /** 00457 * Reset the state of the accumulator 00458 */ 00459 inline void reset(); 00460 00461 /** 00462 * set norm (unused) 00463 */ 00464 inline void setNorm(const T& nrm); 00465 00466 protected: 00467 /** 00468 * the accumulated value 00469 */ 00470 U state; 00471 00472 /** 00473 * the norm 00474 */ 00475 T norm; 00476 }; 00477 00478 }; 00479 } 00480 00481 #include "ltiDilation_template.h" 00482 00483 #endif