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

ltiChannelStatistics.h

00001 /*
00002  * Copyright (C) 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-Lib: Image Processing and Computer Vision Library
00026  * file .......: ltiChannelStatistics.h
00027  * authors ....: Peter Doerfler
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 28.3.2002
00030  * revisions ..: $Id: ltiChannelStatistics.h,v 1.11 2006/02/07 18:35:19 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_CHANNEL_STATISTICS
00034 #define _LTI_CHANNEL_STATISTICS
00035 
00036 #include "ltiGlobalFeatureExtractor.h"
00037 #include "ltiContour.h"
00038 #include "ltiColors.h"
00039 #include "ltiSplitImage.h"
00040 
00041 namespace lti {
00042   /**
00043    * This functor splits an image into three channels of a color space
00044    * set in the parameters (see parameters::setSplitter() ). From
00045    * these channels it then calculates the Minimum, Maximum, Average,
00046    * Median or Average and Variance over their values, depending on
00047    * the parameter type.
00048    *
00049    * It is possible to define a "transparent color" which will be
00050    * ignored by the calculation.
00051    */
00052   class channelStatistics : public globalFeatureExtractor {
00053   public:
00054     /**
00055      * the parameters for the class channelStatistics
00056      */
00057     class parameters : public globalFeatureExtractor::parameters {
00058     public:
00059 
00060       /**
00061        * Specification of the filter type used on each channel to
00062        * calculate the feature %vector.
00063        * @see apply()
00064        * @see getMin()
00065        * @see getMax()
00066        * @see getAverage()
00067        * @see getGaussian()
00068        * @see getMedian()
00069        */
00070       enum eBRGBFilterType {
00071         Minimum=0, /*!< find the minimum value of each channel */
00072         Maximum, /*!< find the maximum value of each channel */
00073         Average, /*!< find the average value of each channel */
00074         Gaussian, /*!< find the mean and variance of each channel */
00075         Median /*!< find the median of all values of each channel */
00076       };
00077 
00078       /**
00079        * default constructor
00080        */
00081       parameters();
00082 
00083       /**
00084        * copy constructor
00085        * @param other the parameters object to be copied
00086        */
00087       parameters(const parameters& other);
00088 
00089       /**
00090        * destructor
00091        */
00092       ~parameters();
00093 
00094       /**
00095        * returns name of this type
00096        */
00097       const char* getTypeName() const;
00098 
00099       /**
00100        * copy the contents of a parameters object
00101        * @param other the parameters object to be copied
00102        * @return a reference to this parameters object
00103        */
00104       parameters& copy(const parameters& other);
00105 
00106       /**
00107        * copy the contents of a parameters object
00108        * @param other the parameters object to be copied
00109        * @return a reference to this parameters object
00110        */
00111       parameters& operator=(const parameters& other);
00112 
00113 
00114       /**
00115        * returns a pointer to a clone of the parameters
00116        */
00117       virtual functor::parameters* clone() const;
00118 
00119       /**
00120        * write the parameters in the given ioHandler
00121        * @param handler the ioHandler to be used
00122        * @param complete if true (the default) the enclosing begin/end will
00123        *        be also written, otherwise only the data block will be written.
00124        * @return true if write was successful
00125        */
00126       virtual bool write(ioHandler& handler,const bool complete=true) const;
00127 
00128       /**
00129        * read the parameters from the given ioHandler
00130        * @param handler the ioHandler to be used
00131        * @param complete if true (the default) the enclosing begin/end will
00132        *        be also written, otherwise only the data block will be written.
00133        * @return true if write was successful
00134        */
00135       virtual bool read(ioHandler& handler,const bool complete=true);
00136 
00137 #     ifdef _LTI_MSC_6
00138       /**
00139        * this function is required by MSVC only, as a workaround for a
00140        * very awful bug, which exists since MSVC V.4.0, and still by
00141        * V.6.0 with all bugfixes (so called "service packs") remains
00142        * there...  This method is also public due to another bug, so please
00143        * NEVER EVER call this method directly: use read() instead
00144        */
00145       bool readMS(ioHandler& handler,const bool complete=true);
00146 
00147       /**
00148        * this function is required by MSVC only, as a workaround for a
00149        * very awful bug, which exists since MSVC V.4.0, and still by
00150        * V.6.0 with all bugfixes (so called "service packs") remains
00151        * there...  This method is also public due to another bug, so please
00152        * NEVER EVER call this method directly: use write() instead
00153        */
00154       bool writeMS(ioHandler& handler,const bool complete=true) const;
00155 #     endif
00156 
00157       // ------------------------------------------------
00158       // the parameters
00159       // ------------------------------------------------
00160 
00161       //TODO: comment the parameters of your functor
00162       // If you add more parameters manually, do not forget to do following:
00163       // 1. indicate in the default constructor the default values
00164       // 2. make sure that the copy member also copy your new parameters
00165       // 3. make sure that the read and write members also read and
00166       //    write your parameters
00167 
00168       /**
00169        * Kind of calculation rule used to get the values. Default value
00170        * is Average
00171        */
00172       eBRGBFilterType type;
00173 
00174       /**
00175        * Indicates whether the %parameters own the splitImage pointer or not.
00176        * If they do, the pointer will be deleted in the destructor, if they
00177        * don't, the class using the channelStatistics is responsible for
00178        * deleting the the pointer. Default is true.<p>
00179        * When channelStatistics is read from a file, this parameter is set
00180        * to true, since a new pointer is generated.
00181        */
00182       bool ownsSplitter;
00183 
00184       /**
00185        * The color which is ignored when the statistics is built.
00186        * This works only with the unmasked apply methods. If a mask
00187        * or an areapoint object is given, these are used instead and 
00188        * this parameter is ignored.
00189        */
00190       rgbColor ignoreColor;
00191 
00192       /**
00193        * set the splitImage %functor to be used.  This will delete the
00194        * actual splitter (if this %object owns it), before assigning it
00195        * to the actual parameter pointer.
00196        *
00197        * @param theSplitter a pointer to the new functor to be used
00198        * @param own if true, this parameter object will take control of
00199        *            the memory deallocation of the object.  If false,
00200        *            this %object will never delete the %functor.
00201        */
00202       void setSplitter(splitImage* theSplitter,const bool own = true);
00203 
00204       /**
00205        * get a reference to the splitter object
00206        */
00207       const splitImage& getSplitter() const;
00208 
00209     protected:
00210       /**
00211        * The splitImage %functor used for selecting the channels. Default
00212        * is splitImageToRGB.
00213        */
00214       splitImage* splitter;
00215     };
00216 
00217     /**
00218      * default constructor
00219      */
00220     channelStatistics();
00221 
00222     /**
00223      * copy constructor
00224      * @param other the object to be copied
00225      */
00226     channelStatistics(const channelStatistics& other);
00227 
00228     /**
00229      * destructor
00230      */
00231     virtual ~channelStatistics();
00232 
00233     /**
00234      * returns the name of this type ("channelStatistics")
00235      */
00236     virtual const char* getTypeName() const;
00237 
00238     /**
00239      * Calculates statics for each channel of the part of the given image
00240      * indicated by the areaPoints. The kind of channels used depends on the
00241      * parameter splitter which is a pointer of splitImage. The different
00242      * statistics are chosen through the parameter type: <p>
00243      * <table>
00244      * <tr>
00245      * <td>Minimum</td><td>Minimum of each channel</td><td>3 dimensions</td>
00246      * </tr><tr>
00247      * <td>Maximum</td><td>Maximum of each channel</td><td>3 dimensions</td>
00248      * </tr><tr>
00249      * <td>Average</td><td>Average value of each channel</td>
00250      * <td>3 dimensions</td>
00251      * </tr><tr>
00252      * <td>Gaussian</td><td>First the mean values of each channel</td>
00253      * <td>6 dimensions</td>
00254      * <td></td><td>then the variances</td><td></td>
00255      * </tr><tr>
00256      * <td>Median</td><td>Median value of each channel</td>
00257      * <td>3 dimensions</td>
00258      * </tr></table>
00259      * @param src image for feature extraction.
00260      * @param obj area of the image that contains the %object
00261      * @param dest the feature %vector
00262      * @return true if apply successful or false otherwise.
00263      */
00264     bool apply(const image& src, const areaPoints& obj, dvector& dest) const;
00265 
00266     /**
00267      * Calculates statics for each channel of the given image.
00268      * The kind of channels used depends on the
00269      * parameter splitter which is a pointer of splitImage. 
00270      * Points which have the color param.ignoreColor are ignored.
00271      * @param src image for feature extraction.
00272      * @param dest the feature %vector
00273      * @return true if apply successful or false otherwise.
00274      */
00275     bool apply(const image& src, dvector& dest) const;
00276 
00277     /**
00278      * copy data of "other" functor.
00279      * @param other the functor to be copied
00280      * @return a reference to this functor object
00281      */
00282     channelStatistics& copy(const channelStatistics& other);
00283 
00284     /**
00285      * alias for copy member
00286      * @param other the functor to be copied
00287      * @return a reference to this functor object
00288      */
00289     channelStatistics& operator=(const channelStatistics& other);
00290 
00291     /**
00292      * returns a pointer to a clone of this functor.
00293      */
00294     virtual functor* clone() const;
00295 
00296     /**
00297      * returns used parameters
00298      */
00299     const parameters& getParameters() const;
00300 
00301   protected:
00302     /**
00303      * Calculates the minimum value of the points in obj of the given
00304      * %channel .
00305      * @param ch channel to be evaluated
00306      * @param obj list of points belonging to the %object
00307      * @param dest the minimum value
00308      * @return true if apply successful or false otherwise.
00309      */
00310     bool getMin(const channel& ch, const areaPoints& obj, double& dest) const;
00311 
00312    /**
00313      * Calculates the maximum value of the points in obj of the given
00314      * %channel .
00315      * @param ch channel to be evaluated
00316      * @param obj list of points belonging to the %object
00317      * @param dest the maximum value
00318      * @return true if apply successful or false otherwise.
00319      */
00320     bool getMax(const channel& ch, const areaPoints& obj, double& dest) const;
00321 
00322     /**
00323      * Calculates the average value of the points in obj of the given
00324      * %channel .
00325      * @param ch channel to be evaluated
00326      * @param obj list of points belonging to the %object
00327      * @param dest the average value
00328      * @return true if apply successful or false otherwise.
00329      */
00330     bool getAverage(const channel& ch, const areaPoints& obj,
00331                     double& dest) const;
00332 
00333     /**
00334      * Calculates the Gaussian, ie the mean and variance, of the points in
00335      * obj of the given %channel .
00336      * @param ch channel to be evaluated
00337      * @param obj list of points belonging to the %object
00338      * @param m the mean value
00339      * @param v the variance
00340      * @return true if apply successful or false otherwise.
00341      */
00342     bool getGaussian(const channel& ch, const areaPoints& obj,
00343                      double& m, double& v) const;
00344 
00345    /**
00346      * Calculates the median of all values of the points in obj of the
00347      * given %channel .
00348      * @param ch channel to be evaluated
00349      * @param obj list of points belonging to the %object
00350      * @param dest the median of all values
00351      * @return true if apply successful or false otherwise.
00352      */
00353     bool getMedian(const channel& ch, const areaPoints& obj,
00354                    double& dest) const;
00355 
00356 
00357     /**
00358      * Calculates the minimum value of the points of the given
00359      * %channel for which the mask entry is true.
00360      * @param ch channel to be evaluated
00361      * @param mask flag mask which tells for each point if it should
00362      *             be included in the statistics.
00363      * @param dest the minimum value
00364      * @return true if apply successful or false otherwise.
00365      */
00366     bool getMin(const channel& ch, 
00367                 const channel8& mask, double& dest) const;
00368 
00369     /**
00370      * Calculates the maximum value of the points of the given
00371      * %channel for which the mask entry is true.
00372      * @param ch channel to be evaluated
00373      * @param mask flag mask which tells for each point if it should
00374      *             be included in the statistics.
00375      * @param dest the minimum value
00376      * @return true if apply successful or false otherwise.
00377      */
00378     bool getMax(const channel& ch,
00379                 const channel8& mask, double& dest) const;
00380 
00381     /**
00382      * Calculates the average value of the points of the given
00383      * %channel for which the mask entry is true.
00384      * @param ch channel to be evaluated
00385      * @param mask flag mask which tells for each point if it should
00386      *             be included in the statistics.
00387      * @param dest the minimum value
00388      * @return true if apply successful or false otherwise.
00389      */
00390     bool getAverage(const channel& ch, const channel8& mask,
00391                     double& dest) const;
00392 
00393     /**
00394      * Calculates a gaussian distribution of the points of the given
00395      * %channel for which the mask entry is true.
00396      * @param ch channel to be evaluated
00397      * @param mask flag mask which tells for each point if it should
00398      *             be included in the statistics.
00399      * @param m the mean of the computed distribution
00400      * @param v the variance of the computed distribution
00401      * @return true if apply successful or false otherwise.
00402      */
00403     bool getGaussian(const channel& ch, const channel8& mask,
00404                      double& m, double& v) const;
00405 
00406     /**
00407      * Calculates the median of the points of the given
00408      * %channel for which the mask entry is true.
00409      * @param ch channel to be evaluated
00410      * @param mask flag mask which tells for each point if it should
00411      *             be included in the statistics.
00412      * @param dest the minimum value
00413      * @return true if apply successful or false otherwise.
00414      */
00415     bool getMedian(const channel& ch, const channel8& mask,
00416                    double& dest) const;
00417 
00418 
00419   };
00420 }
00421 
00422 #endif

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