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

ltiBackgroundModel.h

00001 /*
00002  * Copyright (C) 2019
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 .......: ltiBackgroundModel.h
00027  * authors ....: Ruediger Weiler
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 19.1.2019
00030  * revisions ..: $Id: ltiBackgroundModel.h,v 1.9 2006/02/07 18:29:04 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_BACKGROUND_MODEL_H_
00034 #define _LTI_BACKGROUND_MODEL_H_
00035 
00036 //TODO: include only those files which are needed in this header!!
00037 #include "ltiImage.h"
00038 #include "ltiSerialVectorStats.h"
00039 #include <vector>
00040 
00041 // TODO: Check this include to parent class:
00042 #include "ltiSegmentation.h"
00043 
00044 namespace lti {
00045   //TODO: comment your class
00046   /**
00047    * Implementation of an part of the paper 'Pfinder: Real-Time Tracking of the Human Body'
00048    * from Wren, Azarbayejani, Darrell and Pentland published in
00049    * IEEE PAMI July 1997, vol 19, no 7, pp. 780-785.
00050    * This functor can separate things in front of a background.
00051    * The background model is generate of same images displaying only the
00052    * background. With this model you can than separate objects witch belong
00053    * not to the background. The model is a statistic representation of
00054    * every pixel in the scene. And the foreground objects are alle
00055    * colored faces witch do not fit to the statistic model. The rule
00056    * wether a pixel fit ore not is the malanowis distance, a distance between
00057    * a vector(r,g,b) to the mean vector. Furthermore you can adapt the model
00058    * with the images displaying back and foreground. The claas adapt, if you
00059    * want, all pixels with the malanowis smaler as a threshold. The normal
00060    * way of operation is: addd with the 'addBackgrund' function same images,
00061    * with only background, to the model, than use the apply function with
00062    * an image with fore and background and you get in the channel8 the
00063    * malanowis of each pixel to the background. You can set the outputTreshold
00064    * parameter for displying only foreground objects (try 500). If you set the
00065    * flag binaryOutput you get the background black an the foreground white.
00066    */
00067   class backgroundModel : public segmentation {
00068   public:
00069     /**
00070      * the parameters for the class backgroundModel
00071      */
00072     class parameters : public segmentation::parameters {
00073     public:
00074       /**
00075        * default constructor
00076        */
00077       parameters();
00078 
00079       /**
00080        * copy constructor
00081        * @param other the parameters object to be copied
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 the contents of a parameters object
00097        * @param other the parameters object to be copied
00098        * @return a reference to this parameters object
00099        */
00100       parameters& copy(const parameters& other);
00101 
00102       /**
00103        * copy the contents of a parameters object
00104        * @param other the parameters object to be copied
00105        * @return a reference to this parameters object
00106        */
00107       parameters& operator=(const parameters& other);
00108 
00109 
00110       /**
00111        * returns a pointer to a clone of the parameters
00112        */
00113       virtual functor::parameters* clone() 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 write(ioHandler& handler,const bool complete=true) const;
00123 
00124       /**
00125        * read the parameters from the given ioHandler
00126        * @param handler the ioHandler to be used
00127        * @param complete if true (the default) the enclosing begin/end will
00128        *        be also written, otherwise only the data block will be written.
00129        * @return true if write was successful
00130        */
00131       virtual bool read(ioHandler& handler,const bool complete=true);
00132 
00133 #     ifdef _LTI_MSC_6
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 also public due to another bug, so please
00139        * NEVER EVER call this method directly: use read() instead
00140        */
00141       bool readMS(ioHandler& handler,const bool complete=true);
00142 
00143       /**
00144        * this function is required by MSVC only, as a workaround for a
00145        * very awful bug, which exists since MSVC V.4.0, and still by
00146        * V.6.0 with all bugfixes (so called "service packs") remains
00147        * there...  This method is also public due to another bug, so please
00148        * NEVER EVER call this method directly: use write() instead
00149        */
00150       bool writeMS(ioHandler& handler,const bool complete=true) const;
00151 #     endif
00152 
00153       // ------------------------------------------------
00154       // the parameters
00155       // ------------------------------------------------
00156 
00157       /**
00158        * The value of each pixel in the distance output channel
00159        * must be grater than outputThreshold to be drawn. Every other
00160        * pixels are set to zero.
00161        */
00162       float outputThreshold;
00163 
00164       /**
00165        * If this is set true every value bigger than outputThreshold is set to
00166        * one.  every other value is set to zero. You get a kind of a mask as
00167        * output.
00168        */
00169       bool binaryOutput;
00170 
00171       /**
00172        * Al pixels with a malanowis distance smaler than 'adaptationThreshold'
00173        * are adept. The other pixel are not touched because they do not belong
00174        * to the background.
00175        */
00176       float adaptationThreshold;
00177 
00178       /**
00179        * If this is set true the backgroundModel is updatet on every apply.
00180        * Only the regions with a diatance smaler than adaptationThreshold
00181        * become adapt.
00182        */
00183       bool adaptModel;
00184 
00185       /**
00186        * The weight of the new images added adaptModelive to the background.
00187        * Range 0 to 1. If 'alpha' is set to 0.5 the saved model and the new
00188        * image witch become adapt are wighted 50%. If 'alpha' is set to 0 the
00189        * new image is ignored.
00190        *
00191        * If 'alpha' is set to 1 the new model constist only of the new image.
00192        */
00193       float alpha;
00194 
00195 
00196     };
00197 
00198     /**
00199      * default constructor
00200      */
00201     backgroundModel();
00202 
00203     /**
00204      * copy constructor
00205      * @param other the object to be copied
00206      */
00207     backgroundModel(const backgroundModel& other);
00208 
00209     /**
00210      * destructor
00211      */
00212     virtual ~backgroundModel();
00213 
00214     /**
00215      * returns the name of this type ("backgroundModel")
00216      */
00217     virtual const char* getTypeName() const;
00218 
00219     /**
00220      * The function calculates the malanowis distance of each pixel in the image
00221      * to the same pixel in the model. The outpout channel is filled with the rules
00222      * in the parameters. If adaptModel is set true the backgroundmoldel is updated
00223      * with the background of the image 'src'. Every pixel with a distance smaler than
00224      * 'adaptaionThreshold' is background of the image.
00225      * @param src image with the source data.
00226      * @param dest channel with the distance of each pixel
00227      * @return true if apply successful or false otherwise.
00228      */
00229     bool apply(const image& src, channel& dest);
00230 
00231     /**
00232      * Implements first the apply with channel and cast than the result into
00233      * a channel8.
00234      * @param src image with the source data.
00235      * @param dest channel with the distance of each pixel
00236      * @return true if apply successful or false otherwise.
00237      */
00238     bool apply(const image& src, channel8& dest);
00239 
00240 
00241     /**
00242      * Adds a image to the backgroud model. You must call this function serveral times
00243      * with images displaing the same scene with no foreground objects. The functor creates
00244      * the initial backgroundmodel based on thus images. It is absolutly reqired that
00245      * all the images disply the same scene.
00246      *
00247      */
00248     bool addBackground(const image& src);
00249 
00250     /**
00251      * With this fuction you can adapt the model by hand. You can define a mask with the
00252      * values 0 and not 0. The image and the mask must have the same size. The model is
00253      * adept with the image at every point where the mask is equal to zero.
00254      */
00255     bool adaptBackground(const image& src, const channel8& mask);
00256 
00257     /**
00258      * This function returns an image of the background model.
00259      * The image consist of the mean color values of each pixel.
00260      */
00261     bool getModel(image& model);
00262 
00263     /**
00264      * This function emptys the model saved in the class.
00265      * After calling this funktion you have to add backgroundimages
00266      * before you can call the apply function
00267      */
00268     bool clearMoldel();
00269 
00270     /**
00271      * copy data of "other" functor.
00272      * @param other the functor to be copied
00273      * @return a reference to this functor object
00274      */
00275     backgroundModel& copy(const backgroundModel& other);
00276 
00277     /**
00278      * alias for copy member
00279      * @param other the functor to be copied
00280      * @return a reference to this functor object
00281      */
00282     backgroundModel& operator=(const backgroundModel& other);
00283 
00284     /**
00285      * returns a pointer to a clone of this functor.
00286      */
00287     virtual functor* clone() const;
00288 
00289     /**
00290      * returns used parameters
00291      */
00292     const parameters& getParameters() const;
00293 
00294     /**
00295      * Update functor's parameters
00296      *
00297      * Initialize internal data according to the parameters
00298      */
00299     virtual bool updateParameters();
00300 
00301     /**
00302      * write the functor in the given ioHandler. The default implementation
00303      * is to write just the parameters object.
00304      * @param handler the ioHandler to be used
00305      * @param complete if true (the default) the enclosing begin/end will
00306      *        be also written, otherwise only the data block will be written.
00307      * @return true if write was successful
00308      */
00309     virtual bool write(ioHandler& handler,
00310                        const bool complete=true) const;
00311 
00312     /**
00313      * read the parameters from the given ioHandler. The default implementation
00314      * is to read just the parameters object.
00315      * @param handler the ioHandler to be used
00316      * @param complete if true (the default) the enclosing begin/end will
00317      *        be also written, otherwise only the data block will be written.
00318      * @return true if write was successful
00319      */
00320     virtual bool read(ioHandler& handler,const bool complete=true);
00321   protected:
00322 
00323     /**
00324      * For each point of the image a statistic functor. This functor creates
00325      * the variance and the mean value of alle pixels in the  images added to the model.
00326      */
00327     std::vector< std::vector< serialVectorStats<float> > > bgStat;
00328 
00329   };
00330 }
00331 
00332 #endif

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