LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiThresholding.h

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 .......: ltiThresholding.h
00027  * authors ....: Alexandros Matsikis
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 26.04.2000
00030  * revisions ..: $Id: ltiThresholding.h,v 1.7 2006/02/08 11:56:54 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_THRESHOLDING_H_
00034 #define _LTI_THRESHOLDING_H_
00035 
00036 #include "ltiImage.h"
00037 #include "ltiTypes.h"
00038 #include "ltiContour.h"
00039 
00040 #include "ltiModifier.h"
00041 
00042 namespace lti {
00043   /**
00044    * Threshold segmentation of a single channel (monochrom) image
00045    * or a contour. An upper and a lower threshold are used in
00046    * order to define the pixel-value-region where the thresholding
00047    * should operate.
00048    *
00049    * Attention: This class was ThresholdSegmentation, but 
00050    * the meaning of highThreshold and lowThreshold has been changed.
00051    */
00052   class thresholding : public modifier {
00053   public:
00054     /**
00055      * the parameters for the class thresholding
00056      */
00057     class parameters : public modifier::parameters {
00058     public:
00059 
00060       /**
00061        * Default constructor
00062        */
00063       parameters();
00064 
00065       /**
00066        * copy constructor
00067        */
00068       parameters(const parameters& other);
00069 
00070       /**
00071        * destructor
00072        */
00073       ~parameters();
00074 
00075       /**
00076        * returns name of this type
00077        */
00078       const char* getTypeName() const;
00079 
00080       /**
00081        * copy member
00082        */
00083       parameters& copy(const parameters& other);
00084 
00085       /**
00086        * returns a pointer to a clone of the parameters
00087        */
00088       virtual functor::parameters* clone() const;
00089 
00090       /**
00091        * write the parameters in the given ioHandler
00092        * @param handler the ioHandler to be used
00093        * @param complete if true (the default) the enclosing begin/end will
00094        *        be also written, otherwise only the data block will be written.
00095        * @return true if write was successful
00096        */
00097       virtual bool write(ioHandler& handler,
00098                          const bool complete=true) const;
00099 
00100       /**
00101        * write the parameters in the given ioHandler
00102        * @param handler the ioHandler to be used
00103        * @param complete if true (the default) the enclosing begin/end will
00104        *        be also written, otherwise only the data block will be written.
00105        * @return true if write was successful
00106        */
00107       virtual bool read(ioHandler& handler,const bool complete=true);
00108 
00109 #     ifdef _LTI_MSC_6
00110       /**
00111        * this function is required by MSVC only, as a workaround for a
00112        * very awful bug, which exists since MSVC V.4.0, and still by
00113        * V.6.0 with all bugfixes (so called "service packs") remains
00114        * there...  This method is public due to another bug!, so please
00115        * NEVER EVER call this method directly
00116        */
00117       bool readMS(ioHandler& handler,const bool complete=true);
00118 
00119       /**
00120        * this function is required by MSVC only, as a workaround for a
00121        * very awful bug, which exists since MSVC V.4.0, and still by
00122        * V.6.0 with all bugfixes (so called "service packs") remains
00123        * there...  This method is public due to another bug!, so please
00124        * NEVER EVER call this method directly
00125        */
00126       bool writeMS(ioHandler& handler,const bool complete=true) const;
00127 #     endif
00128 
00129 
00130       /**
00131        * Specifies whheter the pixel values in the outer threshold range should 
00132        * be retained instead of beeing replaced by outRegionValue.
00133        *
00134        * Default: false
00135        */
00136       bool keepOutRegion;
00137 
00138       /**
00139        * Specifies whether the pixel values in the inner threshold range should 
00140        * be retained instead of beeing replaced by inRegionValue.
00141        *
00142        * Default: true
00143        */
00144       bool keepInRegion;
00145 
00146       /**
00147        * The value assigned to the pixels with values between the upper
00148        * and the lower threshold (inclusive).
00149        * In case of keepInRegion=true (the default value), the values of the
00150        * original image-pixels are acquired.
00151        * For channel8s this value must be between 0 and 1.0. (it is internally
00152        * scaled to ubyte.
00153        * For channels this value should be between 0 and 1.0
00154        *
00155        * Default: 1.0
00156        */
00157       float inRegionValue;
00158 
00159       /**
00160        * The value assigned to the pixels with values outside the
00161        * upper and the lower threshold (inclusive). In
00162        * case of keepOutRegion=true, the values of the
00163        * original image-pixels are acquired. 
00164        * For channel8s this value must be between 0 and 1.0. ( it is internally
00165        * scaled to ubyte).
00166        * For channels this value should be between 0 and 1.0
00167        *
00168        * Default: 0.0
00169        */
00170       float outRegionValue;
00171 
00172       /**
00173        * The upper threshold value.
00174        * This value should be between 0 and 1.0. 
00175        * For channel8s any value greater than 1 will be interpreted as 1.
00176        * (internally as 255)
00177        * The closed interval to consider a pixel-value in the region will
00178        * be [lowThreshold,highThreshold].
00179        * It must be hold highThreshold >= lowThreshold.
00180        *
00181        * Default: maximum value of float
00182        */
00183       float highThreshold;
00184 
00185       /**
00186        * The lower threshold value.
00187        * For channel8s this value must between 0 and 1.0. ( it is internally
00188        * scaled to ubyte) 
00189        * The closed interval to consider a pixel-value in the region will
00190        * be [lowThreshold,highThreshold].
00191        * It must be hold highThreshold >= lowThreshold
00192        *
00193        * Default: 0.5
00194        */
00195       float lowThreshold;
00196     };
00197 
00198     /**
00199      * default constructor
00200      */
00201     thresholding();
00202 
00203     /**
00204      * Construct a functor using the given parameters
00205      */
00206     thresholding(const parameters& par);
00207 
00208     /**
00209      * copy constructor
00210      * @param other the object to be copied
00211      */
00212     thresholding(const thresholding& other);
00213 
00214     /**
00215      * destructor
00216      */
00217     virtual ~thresholding();
00218 
00219     /**
00220      * returns the name of this type ("thresholding")
00221      */
00222     virtual const char* getTypeName() const;
00223 
00224 
00225     /**
00226      * operates on the given parameter.
00227      * @param srcdest channel8 with the source data.  The result
00228      *                         will be left here too.
00229      * @return true if apply successful or false otherwise.
00230      */
00231     bool apply(channel8& srcdest) const;
00232 
00233     /**
00234      * segmentate the src channel and leave the result on dest
00235      * @param src channel8 with the source data.
00236      * @param dest channel8 where the result will be left.
00237      * @return true if apply successful or false otherwise.
00238      */
00239     bool apply(const channel8& src,channel8& dest) const;
00240 
00241     /**
00242      * segmentate the src channel and leave the result on dest.
00243      * this apply is slower because everytime it is invoked a new Lookuptable
00244      * is generated
00245      * @param src channel8 with the source data.
00246      * @param dest channel8 where the result will be left.
00247      * @param lowThreshold low threshold value
00248      * @param highThreshold high threshold value (optional Default: 1)
00249      * @param keepInRegion if the inner pixels should be kept (optional Default: true)
00250      * @param keepOutRegion if the outer pixels should be kept (optional Default: false)
00251      * @return true if apply successful or false otherwise.
00252      */
00253     bool apply(const channel8& src, channel8& dest, const float lowThreshold,
00254                const float highThreshold = 1.0f, 
00255                const bool keepInRegion = true,
00256                const bool keepOutRegion = false) const;
00257 
00258     /**
00259      * segmentates a channel on place
00260      * @param src channel with the source data. The result will be
00261      *             left here as well.
00262      * @return true if apply successful or false otherwise.
00263      */
00264     bool apply(channel& src) const;
00265 
00266     /**
00267      * generates a mask for the channel src.
00268      * @param src channel with the source data.
00269      * @param dest channel where the resulting mask will be left.
00270      * @return true if apply successful or false otherwise.
00271      */
00272     bool apply(const channel& src,channel8& dest) const;
00273 
00274     /**
00275      * segmentate the channel src, and leave the result in dest
00276      * @param src channel with the source data.
00277      * @param dest channel where the resulting mask will be left.
00278      * @return true if apply successful or false otherwise.
00279      */
00280     bool apply(const channel& src,channel& dest) const;
00281 
00282 
00283    /** 
00284      * segmentate the src channel and leave the result on dest.
00285      * @param src channel with the source data
00286      * @param dest channel where the results will be left
00287      * @param lowThreshold low threshold value
00288      * @param highThreshold high threshold value (optional Default: 1.0f)
00289      * @param keepInRegion if the inner pixels should be kept (optional Default: true)
00290      * @param keepOutRegion if the outer pixels should be kept (optional Default: false)
00291      * @param inRegionValue if keepInRegion is false the inner pixels are replaced with this value 
00292      * (optional Default: 1.0f)
00293      * @param outRegionValue if keepOutRegion is false the outer pixels are replaced with this value 
00294      * (optional Default: 0.0f)
00295      */
00296     bool apply(const channel& src,channel& dest,
00297                const float lowThreshold, const float highThreshold=1.0f,
00298                const bool keepInRegion=true, const bool keepOutRegion=false,
00299                const float inRegionValue=1.0f, const float outRegionValue=0.0f) const;
00300 
00301     /**
00302      * segmentate the channel src, and generate an area-points-list on for
00303      * the given dest-contour
00304      * @param src channel8 with the source data.
00305      * @param dest the area point-list where the result will be left.
00306      * @return true if apply successful or false otherwise.
00307      */
00308     bool apply(const channel8& src,areaPoints& dest) const;
00309 
00310     /**
00311      * segmentate the channel src, and generate an area-points-list on for
00312      * the given dest-contour
00313      * @param src channel with the source data.
00314      * @param dest the area point list where the result will be left.  Only the area
00315      *             points will be generated.  If you need another contour
00316      *             representation you can use the castFrom methods of the other
00317      *             point list types (see lti::borderPoints, lti::ioPoints)
00318      * @return true if apply successful or false otherwise.
00319      */
00320     bool apply(const channel& src,areaPoints& dest) const;
00321 
00322     /**
00323      * segmentate the src channel, and consider only the area points given
00324      * by the "comp" list.
00325      * @param src channel8 with the source data.
00326      * @param comp the list of points that should be segmented
00327      * @param dest point list where the result will be left.
00328      * @return true if apply successful or false otherwise.
00329      */
00330     bool apply(const channel8& src,
00331                       const areaPoints& comp, areaPoints& dest) const;
00332 
00333 
00334     /**
00335      * segmentate the src channel, and consider only the area points given
00336      * by the "comp" point list .
00337      * @param src channel with the source data.
00338      * @param comp the list of points that should be segmented
00339      * @param dest point list where the result will be left.
00340      * @return true if apply successful or false otherwise.
00341      */
00342     bool apply(const channel& src,
00343                       const areaPoints& comp, areaPoints& dest) const;
00344 
00345     /**
00346      * copy data of "other" functor.
00347      */
00348     thresholding& copy(const thresholding& other);
00349 
00350     /**
00351      * returns a pointer to a clone of the functor.
00352      */
00353     virtual functor* clone() const;
00354 
00355     /**
00356      * sets the functor's parameters.
00357      * This member makes a copy of <em>theParam</em>: the functor
00358      * will keep its own copy of the parameters!
00359      */
00360     virtual bool updateParameters();
00361 
00362     /**
00363      * returns used parameters
00364      */
00365     const parameters& getParameters() const;
00366 
00367   protected:
00368     /**
00369      * This look up table will be used to accelerate the segmentation of
00370      * channel8 data.  It contains the value to be assigned to the
00371      * destination channel
00372      * It will be generated within the member setParameters
00373      */
00374     ubyte lut[256];
00375 
00376     /**
00377      * This look up table will be used to accelerate the segmentation of
00378      * channel8 data.  It contains 0 if the value must be considered as
00379      * background or 1 otherwise.
00380      * It will be generated within the member setParameters
00381      */
00382     ubyte mask[256];
00383 
00384    /**
00385     * Method to init the lookuptables.
00386     * The lookuptables will be used to accelerate the segmentation of channel8 data.
00387     * Usually they are initialized within invocation of setParameters() but also
00388     * in applies to channel8 which contains Thresholds as parameters.
00389     * @param lut where to store the look up table
00390     * @param mask where to store the mask table
00391     * @param lowThreshold low threshold value
00392     * @param highThreshold high threshold value
00393     * @param keepInRegion whether the inner pixels of the original channel8 should be kept
00394     * @param keepOutRegion whether the outer pixels of the original channel8 should be kept
00395     * @param inRegionValue if keepInRegion is false, the pixel will be overwritten with this value
00396     * @param outRegionValue if keepOutRegion is false, the pixel will be overwritten with this value
00397     */
00398     bool initLut(ubyte *lut,ubyte *mask, 
00399                  const float lowThreshold, const float highThreshold,
00400                  const bool keepInRegion, const bool keepOutRegion,
00401                  const float inRegionValue, const float outRegionValue) const;
00402 
00403   };
00404 }
00405 
00406 #endif

Generated on Sat Apr 10 15:26:17 2010 for LTI-Lib by Doxygen 1.6.1