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 .......: ltioptimalThresholding.h 00027 * authors ....: Benjamin Winkler 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 13.12.2000 00030 * revisions ..: $Id: ltiOptimalThresholding.h,v 1.9 2006/02/08 11:35:37 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_OPTIMAL_THRESHOLD_H_ 00034 #define _LTI_OPTIMAL_THRESHOLD_H_ 00035 00036 #include "ltiImage.h" 00037 00038 #include "ltiThresholding.h" 00039 00040 namespace lti { 00041 /** 00042 * Threshold segmentation of a single channel with the optimal 00043 * threshold value. The optimal threshold value is calculated 00044 * iteratively according to Sonky, Hlavac, Boyle: "Image Processing, 00045 * Analysis and Machine Vision", p.129) 00046 */ 00047 class optimalThresholding : public thresholding { 00048 public: 00049 00050 /** 00051 * the parameters for the class optimalThresholding 00052 */ 00053 class parameters : public thresholding::parameters { 00054 public: 00055 /** 00056 * default constructor 00057 */ 00058 parameters(); 00059 00060 /** 00061 * copy constructor 00062 * @param other the parameters object to be copied 00063 */ 00064 parameters(const parameters& other); 00065 00066 /** 00067 * destructor 00068 */ 00069 ~parameters(); 00070 00071 /** 00072 * returns name of this type 00073 */ 00074 const char* getTypeName() const; 00075 00076 /** 00077 * copy the contents of a parameters object 00078 * @param other the parameters object to be copied 00079 * @return a reference to this parameters object 00080 */ 00081 parameters& copy(const parameters& other); 00082 00083 /** 00084 * copy the contents of a parameters object 00085 * @param other the parameters object to be copied 00086 * @return a reference to this parameters object 00087 */ 00088 parameters& operator=(const parameters& other); 00089 00090 /** 00091 * returns a pointer to a clone of the parameters 00092 */ 00093 virtual functor::parameters* clone() const; 00094 00095 /** 00096 * write the parameters in the given ioHandler 00097 * @param handler the ioHandler to be used 00098 * @param complete if true (the default) the enclosing begin/end will 00099 * be also written, otherwise only the data block will be written. 00100 * @return true if write was successful 00101 */ 00102 virtual bool write(ioHandler& handler,const bool complete=true) const; 00103 00104 /** 00105 * write the parameters in the given ioHandler 00106 * @param handler the ioHandler to be used 00107 * @param complete if true (the default) the enclosing begin/end will 00108 * be also written, otherwise only the data block will be written. 00109 * @return true if write was successful 00110 */ 00111 virtual bool read(ioHandler& handler,const bool complete=true); 00112 00113 # ifdef _LTI_MSC_6 00114 /** 00115 * this function is required by MSVC only, as a workaround for a 00116 * very awful bug, which exists since MSVC V.4.0, and still by 00117 * V.6.0 with all bugfixes (so called "service packs") remains 00118 * there... This method is also public due to another bug, so please 00119 * NEVER EVER call this method directly: use read() instead 00120 */ 00121 bool readMS(ioHandler& handler,const bool complete=true); 00122 00123 /** 00124 * this function is required by MSVC only, as a workaround for a 00125 * very awful bug, which exists since MSVC V.4.0, and still by 00126 * V.6.0 with all bugfixes (so called "service packs") remains 00127 * there... This method is also public due to another bug, so please 00128 * NEVER EVER call this method directly: use write() instead 00129 */ 00130 bool writeMS(ioHandler& handler,const bool complete=true) const; 00131 # endif 00132 00133 // ------------------------------------------------ 00134 // the parameters 00135 // ------------------------------------------------ 00136 00137 // If you add more parameters manually, do not forget to do following: 00138 // 1. indicate in the default constructor the default values 00139 // 2. make sure that the copy member also copy your new parameters 00140 // 3. make sure that the read and write members also read and 00141 // write your parameters 00142 00143 00144 /** 00145 * precision of threshold determination. 00146 * iteration stops, when the changes are smaller or equal than 00147 * the given precision valid precision values range from 0.0 00148 * (inclusive) to 1.0. when using channel8, the values are 00149 * linearly mapped to 0..255. default precision = 0.003915 00150 * (which is < 1/255 and > 1/256) 00151 */ 00152 float precision; 00153 00154 }; 00155 00156 /** 00157 * default constructor 00158 */ 00159 optimalThresholding(); 00160 00161 /** 00162 * copy constructor 00163 * @param other the object to be copied 00164 */ 00165 optimalThresholding(const optimalThresholding& other); 00166 00167 /** 00168 * destructor 00169 */ 00170 virtual ~optimalThresholding(); 00171 00172 /** 00173 * returns the name of this type ("optimalThresholding") 00174 */ 00175 virtual const char* getTypeName() const; 00176 00177 /** 00178 * segmentates a channel on place 00179 * lowThreshold is set to the optimal threshold value, 00180 * highThreshold is set to 1.0 and thresholding is applied 00181 * @param srcdest channel with the source data. The result 00182 * will be left here too. 00183 * @return true if apply successful or false otherwise 00184 */ 00185 bool apply(channel& srcdest); 00186 00187 /** 00188 * segmentates a channel on place 00189 * lowThreshold is set to the optimal threshold value, 00190 * highThreshold is set to 1.0 and thresholding is applied 00191 * @param srcdest channel8 with the source data. The result 00192 * will be left here too. 00193 * @return true if apply successful or false otherwise 00194 */ 00195 bool apply(channel8& srcdest); 00196 00197 /** 00198 * segmentate the channel src, and leave the result in dest 00199 * lowThreshold is set to the optimal threshold value, 00200 * highThreshold is set to 1.0 and thresholding is applied 00201 * @param src channel8 with the source data. 00202 * @param dest The segmentated data 00203 * will be left here. 00204 * @return true if apply successful or false otherwise 00205 */ 00206 bool apply(const channel& src,channel& dest); 00207 00208 /** 00209 * segmentate the channel src, and leave the result in dest. 00210 * lowThreshold is set to the optimal threshold value, 00211 * highThreshold is set to 1.0 and thresholding is applied 00212 * @param src channel8 with the source data. 00213 * @param dest channel8 where the segmentated data will be left. 00214 * @return true if apply successful or false otherwise 00215 */ 00216 bool apply(const channel8& src,channel8& dest); 00217 00218 /** 00219 * copy data of "other" functor. 00220 * @param other the functor to be copied 00221 * @return a reference to this functor object 00222 */ 00223 optimalThresholding& copy(const optimalThresholding& other); 00224 00225 /** 00226 * returns a pointer to a clone of this functor. 00227 */ 00228 virtual functor* clone() const; 00229 00230 /** 00231 * returns used parameters 00232 */ 00233 const parameters& getParameters() const; 00234 00235 /** 00236 * calculates the optimal thresholding value for a given channel 00237 */ 00238 float getThreshold(const channel& src) const; 00239 00240 /** 00241 * calculates the optimal thresholding value for a given channel 00242 */ 00243 int getThreshold(const channel8& src) const; 00244 00245 /** 00246 * calculates the optimal thresholding value for the given histogram 00247 * @param histo the vector containing a 1D histogram 00248 * @return the index in the histogram which corresponds to the optimal 00249 * threshold. 00250 */ 00251 int getThreshold(const vector<float>& histo) const; 00252 00253 /** 00254 * calculates the optimal thresholding value for the given histogram 00255 * @param histo the vector containing a 1D histogram 00256 * @return the index in the histogram which corresponds to the optimal 00257 * threshold. 00258 */ 00259 int getThreshold(const vector<double>& histo) const; 00260 00261 /** 00262 * calculates the optimal thresholding value for the given histogram 00263 * @param histo the vector containing a 1D histogram 00264 * @return the index in the histogram which corresponds to the optimal 00265 * threshold. 00266 */ 00267 int getThreshold(const vector<int>& histo) const; 00268 00269 }; 00270 } 00271 00272 #endif