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

ltiChrominanceMapMasking.h

00001 /*
00002  * Copyright (C) 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-Lib: Image Processing and Computer Vision Library
00026  * file .......: ltiChrominanceMapMasking.h
00027  * authors ....: Claudia Goenner
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 14.2.2004
00030  * revisions ..: $Id: ltiChrominanceMapMasking.h,v 1.3 2006/02/07 18:36:13 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_CHROMINANCE_MAP_MASKING_H_
00034 #define _LTI_CHROMINANCE_MAP_MASKING_H_
00035 
00036 #include "ltiImage.h"
00037 #include "ltiModifier.h"
00038 #include "cstdlib"
00039 
00040 namespace lti {
00041   /**
00042    * This class performs color segmentation in the chrominance plane using
00043    * a chrominance map which may be drawn manually or computed by the
00044    * chrominance map estimator class.
00045    *
00046    * For achromatic objects a threshold may be specifies to distinguish
00047    * between black, grey and white.
00048    *
00049    * @see overlappingSets2D, chrominanceModelEstimator, chrominanceMapEstimator
00050    */
00051   class chrominanceMapMasking : public modifier {
00052   public:
00053     /**
00054      * The parameters for the class chrominanceMapMasking
00055      */
00056     class parameters : public modifier::parameters {
00057     public:
00058       /**
00059        * Default constructor
00060        */
00061       parameters();
00062 
00063       /**
00064        * Copy constructor
00065        * @param other the parameters object to be copied
00066        */
00067       parameters(const parameters& other);
00068 
00069       /**
00070        * Destructor
00071        */
00072       ~parameters();
00073 
00074       /**
00075        * Returns name of this type
00076        */
00077       const char* getTypeName() const;
00078 
00079       /**
00080        * Copy the contents of a parameters object
00081        * @param other the parameters object to be copied
00082        * @return a reference to this parameters object
00083        */
00084       parameters& copy(const parameters& other);
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& operator=(const parameters& other);
00092 
00093 
00094       /**
00095        * Returns a pointer to a clone of the parameters
00096        */
00097       virtual functor::parameters* clone() const;
00098 
00099       /**
00100        * Write the parameters in the given ioHandler
00101        * @param handler the ioHandler to be used
00102        * @param complete if true (the default) the enclosing begin/end will
00103        *        be also written, otherwise only the data block will be written.
00104        * @return true if write was successful
00105        */
00106       virtual bool write(ioHandler& handler,const bool complete=true) const;
00107 
00108       /**
00109        * Read the parameters from the given ioHandler
00110        * @param handler the ioHandler to be used
00111        * @param complete if true (the default) the enclosing begin/end will
00112        *        be also written, otherwise only the data block will be written.
00113        * @return true if write was successful
00114        */
00115       virtual bool read(ioHandler& handler,const bool complete=true);
00116 
00117 #     ifdef _LTI_MSC_6
00118       /**
00119        * This function is required by MSVC only, as a workaround for a
00120        * very awful bug, which exists since MSVC V.4.0, and still by
00121        * V.6.0 with all bugfixes (so called "service packs") remains
00122        * there...  This method is also public due to another bug, so please
00123        * NEVER EVER call this method directly: use read() instead
00124        */
00125       bool readMS(ioHandler& handler,const bool complete=true);
00126 
00127       /**
00128        * This function is required by MSVC only, as a workaround for a
00129        * very awful bug, which exists since MSVC V.4.0, and still by
00130        * V.6.0 with all bugfixes (so called "service packs") remains
00131        * there...  This method is also public due to another bug, so please
00132        * NEVER EVER call this method directly: use write() instead
00133        */
00134       bool writeMS(ioHandler& handler,const bool complete=true) const;
00135 #     endif
00136 
00137       // ------------------------------------------------
00138       // the parameters
00139       // ------------------------------------------------
00140 
00141       /**
00142        * Achromatic objects which a luminance below this value are interpreted
00143        * as black.
00144        */
00145       ubyte blackLuminance;
00146 
00147       /**
00148        * Achromatic objects which a luminance above this value are interpreted
00149        * as white.
00150        */
00151       ubyte whiteLuminance;
00152 
00153       /**
00154        * The label of the achromatic region in the chrominance map.
00155        */
00156       int achromaticLabel;
00157 
00158       /**
00159        * The label of white objects in the destination.
00160        */
00161       int whiteLabel;
00162 
00163       /**
00164        * The label of grey objects in the destination.
00165        */
00166       int greyLabel;
00167       
00168       /**
00169        * The label of black objects in the destination.
00170        */
00171       int blackLabel;
00172 
00173       /**
00174        * Each color band usually contains 8bit resulting in a 256x256
00175        * histogram. For efficiency the histograms may be downsampled by
00176        * 2 power shrinkFactor.
00177        *
00178        * Default: 0.
00179        */
00180       int shrinkFactor;
00181 
00182     };
00183 
00184     /**
00185      * Default constructor
00186      */
00187     chrominanceMapMasking();
00188 
00189     /**
00190      * Construct a functor using the given parameters
00191      */
00192     chrominanceMapMasking(const parameters& par);
00193 
00194     /**
00195      * Copy constructor
00196      * @param other the object to be copied
00197      */
00198     chrominanceMapMasking(const chrominanceMapMasking& other);
00199 
00200     /**
00201      * Destructor
00202      */
00203     virtual ~chrominanceMapMasking();
00204 
00205     /**
00206      * Returns the name of this type ("chrominanceMapMasking")
00207      */
00208     virtual const char* getTypeName() const;
00209 
00210     /**
00211      * Copy data of "other" functor.
00212      * @param other the functor to be copied
00213      * @return a reference to this functor object
00214      */
00215     chrominanceMapMasking& copy(const chrominanceMapMasking& other);
00216 
00217     /**
00218      * Alias for copy member
00219      * @param other the functor to be copied
00220      * @return a reference to this functor object
00221      */
00222     chrominanceMapMasking& operator=(const chrominanceMapMasking& other);
00223 
00224     /**
00225      * Returns a pointer to a clone of this functor.
00226      */
00227     virtual functor* clone() const;
00228 
00229     /**
00230      * Returns used parameters
00231      */
00232     const parameters& getParameters() const;
00233 
00234     /**
00235      * @name Apply methods for entire images or channel8s.
00236      */
00237     //@{
00238 
00239     /**
00240      * Color segmentation based on a chrominance map and thresholding on the
00241      * luminance for achromatic objects.
00242      * @param y channel8 with the luminance.
00243      * @param u channel8 with the 1st chrominance band.
00244      * @param v channel8 with the 2nd chrominance ban.
00245      * @param dest color segmentation.
00246      * @return true on success and false otherwise.
00247      */
00248     bool apply(const channel8& y, const channel8& u, const channel8& v,
00249          channel8& dest);
00250 
00251     /**
00252      * Color segmentation based on a chrominance map and thresholding on the
00253      * luminance for achromatic objects.
00254      * @param y channel8 with the luminance.
00255      * @param u channel8 with the 1st chrominance band.
00256      * @param v channel8 with the 2nd chrominance ban.
00257      * @param dest color segmentation.
00258      * @param prob the probability of the segmented object.
00259      * @return true on success and false otherwise.
00260      */
00261     bool apply(const channel8& y, const channel8& u, const channel8& v,
00262          channel8& dest, channel& prob);
00263 
00264     /**
00265      * Color segmentation based on a chrominance map only.
00266      * @param u channel8 with the 1st chrominance band.
00267      * @param v channel8 with the 2nd chrominance ban.
00268      * @param dest color segmentation.
00269      * @return true on success and false otherwise.
00270      */
00271     bool apply(const channel8& u, const channel8& v, channel8& dest);
00272 
00273     /**
00274      * Color segmentation based on a chrominance map only.
00275      * @param u channel8 with the 1st chrominance band.
00276      * @param v channel8 with the 2nd chrominance ban.
00277      * @param dest color segmentation.
00278      * @param prob the probability of the segmented object.
00279      * @return true on success and false otherwise.
00280      */
00281     bool apply(const channel8& u, const channel8& v,
00282          channel8& dest, channel& prob);
00283     //@}  
00284 
00285     /**
00286      * Set a link to the chrominance map. Please ensure that the
00287      * chrominance map is not deleted while this class or pointer exists.
00288      * @param map the chrominance map.
00289      * @return true on success and false otherwise.
00290      */
00291     bool useExternalChrominanceMap(const channel8* map);
00292 
00293     /**
00294      * Set the chrominance map. The map is copied.
00295      * @param map the chrominance map.
00296      * @return true on success and false otherwise.
00297      */
00298     bool setChrominanceMap(const channel8& map);
00299     
00300     /**
00301      * Set a link to the probability map. Please ensure that the
00302      * probability is not deleted while this class or pointer exists.
00303      * @param map the probability map.
00304      * @return true on success and false otherwise.
00305      */
00306     bool useExternalProbabilityMap(const channel* map);
00307 
00308     /**
00309      * Set the probability map. The map is copied.
00310      * @param map the probability map.
00311      * @return true on success and false otherwise.
00312      */   
00313     bool setProbabilityMap(const channel& map);
00314     
00315     /**
00316      * Get the chrominance map.
00317      */   
00318     const channel8& getChrominanceMap() const;
00319     
00320     /**
00321      * Get the probability map for the most likely object.
00322      */   
00323     const channel& getProbabilityMap() const;
00324     
00325     /**
00326      * Is the chrominance map valid, e.g. is is set and does it have equal
00327      * dimensions?
00328      * @return true on success and false otherwise.
00329      */ 
00330     bool isChrominanceMapValid() const;
00331     
00332     /**
00333      * Is the probability map valid, e.g. is is set and does it have equal
00334      * dimensions?
00335      * @return true on success and false otherwise.
00336      */ 
00337     bool isProbabilityMapValid() const;
00338     
00339     /**
00340      * Are the chrominance map and probability map consistent, e.g. have
00341      * the same dimensions and are both valid?
00342      * @return true on success and false otherwise.
00343      */ 
00344     bool areMapsConsistent() const;
00345     
00346     /**
00347      * Read the chrominance map from disk. The chrominance map is interpreted
00348      * as a color image.
00349      * @param filename the name of the chrominance map file.
00350      * @param colors  conversion between the colored stored map and the labels
00351      *  used by vision processing.
00352      * @return true on success and false otherwise.
00353      */
00354     bool readChrominanceMap(const std::string& filename,
00355           const std::vector<rgbPixel>& colors);
00356     
00357   protected:
00358 
00359     /**
00360      * Check if the input channel8 have the same dimension.
00361      * @param y channel8 with the luminance.
00362      * @param u channel8 with the 1st chrominance band.
00363      * @param v channel8 with the 2nd chrominance ban.
00364      * @return true on success and false otherwise.
00365      */
00366     bool checkInput(const channel8& y,
00367         const channel8& u, const channel8& v);
00368     
00369     /**
00370      * Check if the input channel8 have the same dimension.
00371      * @param u channel8 with the 1st chrominance band.
00372      * @param v channel8 with the 2nd chrominance ban.
00373      * @return true on success and false otherwise.
00374      */
00375     bool checkInput(const channel8& u, const channel8& v);
00376 
00377     /**
00378      * Get the shift used because the chrominance map is downsampled.
00379      * @return the shift
00380      */
00381     int getShift() const;
00382 
00383     /**
00384      * Set the shift used because the chrominance map is downsampled.
00385      */
00386     void setShift();  
00387 
00388     /**
00389      * Remember if the probability map must be destroyed on destruction
00390      * or re-initialization.
00391      */
00392     bool m_destroyProbability;
00393 
00394     /**
00395      * Remember if the chrominance map must be destroyed on destruction
00396      * or re-initialization.
00397      */
00398     bool m_destroyChrominance;
00399 
00400     /**
00401      * the probability map
00402      */
00403     const channel *m_probabilityMap;
00404     
00405     /**
00406      * the chrominance map
00407      */
00408     const channel8 *m_chrominanceMap;
00409     
00410     /**
00411      * scaling between the size of the chrominance map and 8-bit
00412      */
00413     int m_shift;
00414   };
00415 }
00416 
00417 #endif

Generated on Sat Apr 10 15:25:13 2010 for LTI-Lib by Doxygen 1.6.1