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 .......: ltiThresholdSegmentation.h 00027 * authors ....: Alexandros Matsikis 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 26.04.2000 00030 * revisions ..: $Id: ltiThresholdSegmentation.h,v 1.13 2006/02/08 11:56:44 ltilib Exp $ 00031 */ 00032 00033 /** 00034 * \file ltiThresholdSegmentation.h Deprecated. Use 00035 * ltiThresholding.h instead 00036 */ 00037 00038 #include "ltiMacroSymbols.h" 00039 00040 #ifndef _LTI_IGNORE_THRESH_DEP_WARNING 00041 #ifdef _LTI_MSC_VER 00042 #pragma message("ltiThresholdSegmentation.h deprecated, use ltiThresholding.h instead!") 00043 #else 00044 #warning "ltiThresholdSegmentation.h deprecated, use ltiThresholding.h instead!" 00045 #endif 00046 #endif 00047 00048 #ifndef _LTI_THRESHOLD_SEGMENTATION_H_ 00049 #define _LTI_THRESHOLD_SEGMENTATION_H_ 00050 00051 #include "ltiImage.h" 00052 #include "ltiTypes.h" 00053 #include "ltiContour.h" 00054 00055 #include "ltiSegmentation.h" 00056 00057 namespace lti { 00058 /** 00059 * Threshold segmentation of a single channel (monochrom) image 00060 * or a contour. An upper and a lower threshold are used in 00061 * order to define the pixel-value-region where the thresholding 00062 * should operate. 00063 */ 00064 class thresholdSegmentation : public segmentation { 00065 public: 00066 /** 00067 * the parameters for the class thresholdSegmentation 00068 */ 00069 class parameters : public segmentation::parameters { 00070 public: 00071 /** 00072 * default constructor 00073 * Per default, the threshold values will be defined in the value 00074 * range of channel8 (0 to 255). If you want to work with channels 00075 * than specify in the constructor of the parameters (false), this 00076 * way the value range of the thresholds will lay between 0 and 1.0 00077 */ 00078 parameters(const bool& useChannel8 = true); 00079 00080 /** 00081 * copy constructor 00082 */ 00083 parameters(const parameters& other); 00084 00085 /** 00086 * destructor 00087 */ 00088 ~parameters(); 00089 00090 /** 00091 * returns name of this type 00092 */ 00093 const char* getTypeName() const; 00094 00095 /** 00096 * copy member 00097 */ 00098 parameters& copy(const parameters& other); 00099 00100 /** 00101 * returns a pointer to a clone of the parameters 00102 */ 00103 virtual functor::parameters* clone() const; 00104 00105 /** 00106 * write the parameters in the given ioHandler 00107 * @param handler the ioHandler to be used 00108 * @param complete if true (the default) the enclosing begin/end will 00109 * be also written, otherwise only the data block will be written. 00110 * @return true if write was successful 00111 */ 00112 virtual bool write(ioHandler& handler, 00113 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 public due to another bug!, so please 00130 * NEVER EVER call this method directly 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 public due to another bug!, so please 00139 * NEVER EVER call this method directly 00140 */ 00141 bool writeMS(ioHandler& handler,const bool complete=true) const; 00142 # endif 00143 00144 /** 00145 * Constant value used to specify that the channel pixel values 00146 * should be retained in the segmented image, instead of generating 00147 * a mask, with only two values. 00148 */ 00149 static const float Original; 00150 00151 /** 00152 * The value assigned to the pixels with values between the upper 00153 * and the lower threshold (inclusive) or "Original". 00154 * In case of Original (the default value), the values of the 00155 * original image-pixels are acquired. 00156 * For channel8s this value must be between 0 and 255. 00157 * For channels this value should be between 0 and 1.0 00158 */ 00159 float inRegionValue; 00160 00161 /** 00162 * The value assigned to the pixels with values outside the 00163 * upper and the lower threshold (inclusive) or "Original". In 00164 * case of Original, the values of the 00165 * original image-pixels are acquired. (Default: 0.0) 00166 * For channel8s this value must be between 0 and 255. 00167 * For channels this value should be between 0 and 1.0 00168 */ 00169 float outRegionValue; 00170 00171 /** 00172 * The upper threshold value. 00173 * Default value: 255 for channel8 or 1.0 for channels (see constructor 00174 * parameters(const bool)). 00175 * Note that this value will be interpreted "as is" by the apply methods, 00176 * i.e., if you say the highThreshold is 0.8 (default value for channels) 00177 * and you apply the functor to a channel8, than eevery pixel will be 00178 * considered to lay out of the region! 00179 * The closed interval to consider a pixel-value in the region will 00180 * be [lowThreshold,highThreshold]. 00181 * It must be hold highThreshold >= lowThreshold 00182 */ 00183 float highThreshold; 00184 00185 /** 00186 * The lower threshold value. 00187 * Default value: 0 00188 * Note that this value will be interpreted "as is" by the apply methods, 00189 * i.e., if you say the lowThreshold is 127, then for a "standard" 00190 * channel, which usually contains values <= 1.0, everything will lay 00191 * out of the region! 00192 * The closed interval to consider a pixel-value in the region will 00193 * be [lowThreshold,highThreshold]. 00194 * It must be hold highThreshold >= lowThreshold 00195 */ 00196 float lowThreshold; 00197 }; 00198 00199 /** 00200 * default constructor 00201 */ 00202 thresholdSegmentation(); 00203 00204 /** 00205 * copy constructor 00206 * @param other the object to be copied 00207 */ 00208 thresholdSegmentation(const thresholdSegmentation& other); 00209 00210 /** 00211 * destructor 00212 */ 00213 virtual ~thresholdSegmentation(); 00214 00215 /** 00216 * returns the name of this type ("thresholdSegmentation") 00217 */ 00218 virtual const char* getTypeName() const; 00219 00220 00221 /** 00222 * operates on the given parameter. 00223 * @param srcdest channel8 with the source data. The result 00224 * will be left here too. 00225 * @return a reference to the <code>srcdest</code>. 00226 */ 00227 channel8& apply(channel8& srcdest) const; 00228 00229 /** 00230 * segmentate the src channel and leave the result on dest 00231 * @param src channel8 with the source data. 00232 * @param dest channel8 where the result will be left. 00233 * @return a reference to the <code>dest</code>. 00234 */ 00235 channel8& apply(const channel8& src,channel8& dest) const; 00236 00237 /** 00238 * segmentates a channel on place 00239 * @param src channel with the source data. The result will be 00240 * left here as well. 00241 * @return a reference to the <code>dest</code>. 00242 */ 00243 channel& apply(channel& src) const; 00244 00245 /** 00246 * generates a mask for the channel src. 00247 * If the parameters specified "Original" for the output values, the 00248 * values between 0.0 and 1.0 will be linearly mapped between 0 and 255. 00249 * @param src channel with the source data. 00250 * @param dest channel where the resulting mask will be left. 00251 * @return a reference to the <code>dest</code>. 00252 */ 00253 channel8& apply(const channel& src,channel8& dest) const; 00254 00255 /** 00256 * segmentate the channel src, and leave the result in dest 00257 * @param src channel with the source data. 00258 * @param dest channel where the resulting mask will be left. 00259 * @return a reference to the <code>dest</code>. 00260 */ 00261 channel& apply(const channel& src,channel& dest) const; 00262 00263 /** 00264 * segmentate the channel src, and generate an area-points-list on for 00265 * the given dest-contour 00266 * @param src channel8 with the source data. 00267 * @param dest the area point-list where the result will be left. 00268 * @return a reference to the <code>dest</code>. contour is of IO type 00269 */ 00270 areaPoints& apply(const channel8& src,areaPoints& dest) const; 00271 00272 /** 00273 * segmentate the channel src, and generate an area-points-list on for 00274 * the given dest-contour 00275 * @param src channel with the source data. 00276 * @param dest the area point list where the result will be left. Only the area 00277 * points will be generated. If you need another contour 00278 * representation you can use the castFrom methods of the other 00279 * point list types (see lti::borderPoints, lti::ioPoints) 00280 * @return a reference to the <code>dest</code>. contour is of IO type 00281 */ 00282 areaPoints& apply(const channel& src,areaPoints& dest) const; 00283 00284 /** 00285 * segmentate the src channel, and consider only the area points given 00286 * by the "comp" list. 00287 * @param src channel8 with the source data. 00288 * @param comp the list of points that should be segmented 00289 * @param dest point list where the result will be left. 00290 * @return a reference to the <code>dest</code>. 00291 */ 00292 areaPoints& apply(const channel8& src, 00293 const areaPoints& comp, areaPoints& dest) const; 00294 00295 00296 /** 00297 * segmentate the src channel, and consider only the area points given 00298 * by the "comp" point list . 00299 * @param src channel with the source data. 00300 * @param comp the list of points that should be segmented 00301 * @param dest point list where the result will be left. 00302 * @return a reference to the <code>dest</code>. 00303 */ 00304 areaPoints& apply(const channel& src, 00305 const areaPoints& comp, areaPoints& dest) const; 00306 00307 /** 00308 * copy data of "other" functor. 00309 */ 00310 thresholdSegmentation& copy(const thresholdSegmentation& other); 00311 00312 /** 00313 * returns a pointer to a clone of the functor. 00314 */ 00315 virtual functor* clone() const; 00316 00317 /** 00318 * sets the functor's parameters. 00319 * This member makes a copy of <em>theParam</em>: the functor 00320 * will keep its own copy of the parameters! 00321 */ 00322 virtual bool updateParameters(); 00323 00324 /** 00325 * returns used parameters 00326 */ 00327 const parameters& getParameters() const; 00328 00329 protected: 00330 /** 00331 * This look up table will be used to accelerate the segmentation of 00332 * channel8 data. It contains the value to be assigned to the 00333 * destination channel 00334 * It will be generated within the member setParameters 00335 */ 00336 ubyte lut[256]; 00337 00338 /** 00339 * This look up table will be used to accelerate the segmentation of 00340 * channel8 data. It contains 0 if the value must be considered as 00341 * background or 1 otherwise. 00342 * It will be generated within the member setParameters 00343 */ 00344 ubyte mask[256]; 00345 00346 }; 00347 } 00348 00349 #endif