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

ltiMaskImage.h

00001 /*
00002  * Copyright (C) 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 .......: ltiMaskImage.h
00027  * authors ....: Pablo Alvarado
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 6.8.2003
00030  * revisions ..: $Id: ltiMaskImage.h,v 1.8 2006/02/08 11:26:14 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_MASK_IMAGE_H_
00034 #define _LTI_MASK_IMAGE_H_
00035 
00036 #include "ltiImage.h"
00037 #include "ltiFunctor.h"
00038 
00039 namespace lti {
00040   /**
00041    * This functor is used to mask color images with labeled or
00042    * unlabeled masks.  You can give a color palette to indicate which
00043    * colors should be used for each region.  Using the alpha (or
00044    * dummy) rgbPixel component in the palette entries you can specify
00045    * the transparency degree of each region in the mask.  This way,
00046    * you can completely suppress regions (like background), leave regions
00047    * complete untouched, or overlay colored patches.
00048    * 
00049    * Example
00050    *
00051    * \code
00052    *
00053    * #include <ltiKMeansSegmentation.h>
00054    * #include <ltiMaskImage.h>
00055    * #include <ltiViewer.h>
00056    * #include <cstdio>
00057    * ...
00058    * 
00059    * lti::image img,masked;
00060    * lti::imatrix mask;
00061    *
00062    * // let's assume, you load a colored image into img
00063    *
00064    * // simple segmentation 
00065    * lti::kMeansSegmentation segmenter;
00066    * segmenter.apply(img,mask);
00067    *
00068    * // get a masked image
00069    * lti::maskImage masker(true); // assume labeled mask and enhance borders
00070    * masker.apply(img,mask,masked);
00071    *
00072    * // show original image and masked one
00073    * lti::viewer vieworig("Original");
00074    * lti::viewer viewmask("Masked");
00075    *
00076    * vieworig.show(img);
00077    * viewmask.show(masked);
00078    *
00079    * getchar(); // wait for ENTER key pressed
00080    * \endcode
00081    */
00082   class maskImage : public functor {
00083   public:
00084     /**
00085      * the parameters for the class maskImage
00086      */
00087     class parameters : public functor::parameters {
00088     public:
00089       /**
00090        * default constructor
00091        */
00092       parameters();
00093 
00094       /**
00095        * copy constructor
00096        * @param other the parameters object to be copied
00097        */
00098       parameters(const parameters& other);
00099 
00100       /**
00101        * destructor
00102        */
00103       ~parameters();
00104 
00105       /**
00106        * returns name of this type
00107        */
00108       const char* getTypeName() const;
00109 
00110       /**
00111        * copy the contents of a parameters object
00112        * @param other the parameters object to be copied
00113        * @return a reference to this parameters object
00114        */
00115       parameters& copy(const parameters& other);
00116 
00117       /**
00118        * copy the contents of a parameters object
00119        * @param other the parameters object to be copied
00120        * @return a reference to this parameters object
00121        */
00122       parameters& operator=(const parameters& other);
00123 
00124 
00125       /**
00126        * returns a pointer to a clone of the parameters
00127        */
00128       virtual functor::parameters* clone() const;
00129 
00130       /**
00131        * write the parameters in the given ioHandler
00132        * @param handler the ioHandler to be used
00133        * @param complete if true (the default) the enclosing begin/end will
00134        *        be also written, otherwise only the data block will be written.
00135        * @return true if write was successful
00136        */
00137       virtual bool write(ioHandler& handler,const bool complete=true) const;
00138 
00139       /**
00140        * read the parameters from the given ioHandler
00141        * @param handler the ioHandler to be used
00142        * @param complete if true (the default) the enclosing begin/end will
00143        *        be also written, otherwise only the data block will be written.
00144        * @return true if write was successful
00145        */
00146       virtual bool read(ioHandler& handler,const bool complete=true);
00147 
00148 #     ifdef _LTI_MSC_6
00149       /**
00150        * this function is required by MSVC only, as a workaround for a
00151        * very awful bug, which exists since MSVC V.4.0, and still by
00152        * V.6.0 with all bugfixes (so called "service packs") remains
00153        * there...  This method is also public due to another bug, so please
00154        * NEVER EVER call this method directly: use read() instead
00155        */
00156       bool readMS(ioHandler& handler,const bool complete=true);
00157 
00158       /**
00159        * this function is required by MSVC only, as a workaround for a
00160        * very awful bug, which exists since MSVC V.4.0, and still by
00161        * V.6.0 with all bugfixes (so called "service packs") remains
00162        * there...  This method is also public due to another bug, so please
00163        * NEVER EVER call this method directly: use write() instead
00164        */
00165       bool writeMS(ioHandler& handler,const bool complete=true) const;
00166 #     endif
00167 
00168       // ------------------------------------------------
00169       // the parameters
00170       // ------------------------------------------------
00171 
00172       /**
00173        * If true, the given mask will be assumed as labeled and all values
00174        * will be considered as a different object label.  If false, only 
00175        * the background label will be considered as background and the rest
00176        * of labels as objects.  In the latter case the "colors" entry 0 will
00177        * be used for background and the colors entry 1 for not-background.
00178        * 
00179        * Default value: false
00180        */
00181       bool assumeLabeledMask;
00182 
00183       /**
00184        * background label used to the background, in case assumeLabeldMask is
00185        * false.
00186        * 
00187        * Default value: 0
00188        */
00189       int backgroundLabel;
00190       
00191       /**
00192        * Colors used to mask each label.  If the mask being used
00193        * contains more labels than color entries, a modulo-like
00194        * operation will be used to choose the next color.  The color
00195        * entry 0 is used only one.  Let k be the index and n the
00196        * number of color entries.  The color used will be k if k<n,
00197        * 1+(k%(n-1)) otherwise.
00198        *
00199        * The \e dummy component of each rgbPixel will be used to
00200        * indicate the transparency level: 0 means completely opaque
00201        * and 255 totally transparent.  This way, you can place colored
00202        * indicators in visualization tasks.
00203        * 
00204        * Default value: - (0,0,0,0),         // black background opaque
00205        *                - (255,255,255,255), // white 100% transparent
00206        *                - (255,128,128,128), // red 50% transparent
00207        *                - (128,255,128,128), // green 50% transparent
00208        *                - (128,128,255,128), // blue 50% transparent
00209        *                - (255,255,0,128),   // yellow 50% transparent
00210        *                - (255,0,255,128),   // magenta 50% transparent
00211        *                - (0,255,255,128)    // cyan 50% transparent
00212        */
00213       palette colors;
00214 
00215       /**
00216        * Border colors.
00217        *
00218        * This parameters is only used in case you activate
00219        * \a enhanceRegionBorders, which is normally set to false.
00220        *
00221        * If this palette is empty, the colors for the borders will be
00222        * the solid colors specied in \a colors, which are a the same time
00223        * the used for the region, with the transparency specified there.
00224        *
00225        * You can optionally specify the colors for the borders, also
00226        * with transparency, so that you have much more flexibility with
00227        * the produced masks.
00228        *
00229        * Default value: empty palette
00230        */
00231       palette borderColors;
00232       
00233 
00234       /**
00235        * If assumeLabeledMask is true, you can also activate a region
00236        * border enhancement.
00237        *
00238        * If the \a borderColors is empty, the borders of the regions will be
00239        * drawn without any transparency, using the colors in \a colors.  Note
00240        * that in this case, the enhancement will be noticeable only if the
00241        * used colors have some transparency!
00242        *
00243        * If the \a borderColors parameters is not empty, the colors therein,
00244        * with the respective transparency will be used.
00245        * 
00246        * Default value: false
00247        */
00248       bool enhanceRegionBorders;
00249 
00250     };
00251 
00252     /**
00253      * default constructor
00254      */
00255     maskImage();
00256 
00257     /**
00258      * create a functor with the specified parameter attributes
00259      */
00260     maskImage(const bool assumeLabeledMask,
00261               const bool enhanceRegionBorders=true);
00262 
00263     /**
00264      * Construct a functor using the given parameters
00265      */
00266     maskImage(const parameters& par);
00267 
00268     /**
00269      * copy constructor
00270      * @param other the object to be copied
00271      */
00272     maskImage(const maskImage& other);
00273 
00274     /**
00275      * destructor
00276      */
00277     virtual ~maskImage();
00278 
00279     /**
00280      * returns the name of this type ("maskImage")
00281      */
00282     virtual const char* getTypeName() const;
00283 
00284     /**
00285      * Mask the src image using the given mask and colors for mask entries.
00286      * @param src image with the source data.
00287      * @param mask labeled or unlabeled mask
00288      * @param colors color entries used to mask the image.  The "dummy" entry
00289      *        of each pixel denotes the transparency of the color used: 0 means
00290      *        opaque and 255 totally transparent.  The \e colors attribute of
00291      *        the parameters class will be ignored.
00292      * @param dest destination masked image.
00293      * @return true if apply successful or false otherwise.
00294      */
00295     bool apply(const image& src,
00296                const channel8& mask,
00297                const palette& colors,
00298                image& dest) const;
00299 
00300     /**
00301      * Mask the src image using the given mask and colors for mask entries.
00302      * @param src image with the source data.
00303      * @param mask labeled or unlabeled mask
00304      * @param colors color entries used to mask the image.  The "dummy" entry
00305      *        of each pixel denotes the transparency of the color used: 0 means
00306      *        opaque and 255 totally transparent. The \e colors attribute of
00307      *        the parameters class will be ignored.
00308      * @param dest destination masked image.
00309      * @return true if apply successful or false otherwise.
00310      */
00311     bool apply(const image& src,
00312                const imatrix& mask,
00313                const palette& colors,
00314                image& dest) const;
00315 
00316     /**
00317      * Mask the src image using the given mask and colors for mask entries.
00318      * @param src image with the source data.
00319      * @param mask labeled or unlabeled mask
00320      * @param dest destination masked image.
00321      * @return true if apply successful or false otherwise.
00322      */
00323     bool apply(const image& src,
00324                const channel8& mask,
00325                image& dest) const;
00326 
00327     /**
00328      * Mask the src image using the given mask and colors for mask entries.
00329      * @param src image with the source data.
00330      * @param mask labeled or unlabeled mask
00331      * @param dest destination masked image.
00332      * @return true if apply successful or false otherwise.
00333      */
00334     bool apply(const image& src,
00335                const imatrix& mask,
00336                image& dest) const;
00337 
00338     /**
00339      * copy data of "other" functor.
00340      * @param other the functor to be copied
00341      * @return a reference to this functor object
00342      */
00343     maskImage& copy(const maskImage& other);
00344 
00345     /**
00346      * alias for copy member
00347      * @param other the functor to be copied
00348      * @return a reference to this functor object
00349      */
00350     maskImage& operator=(const maskImage& other);
00351 
00352     /**
00353      * returns a pointer to a clone of this functor.
00354      */
00355     virtual functor* clone() const;
00356 
00357     /**
00358      * returns used parameters
00359      */
00360     const parameters& getParameters() const;
00361 
00362   protected:
00363     /**
00364      * combine two pixels considering the transparency of the second one
00365      */
00366     inline void combine(const rgbPixel& src,
00367                         const rgbPixel& mask,
00368                         rgbPixel& dest) const;
00369 
00370     /**
00371      * fix the index to fit into the colors
00372      */
00373     inline int fixIdx(const int idx,const int palLastIdx) const;
00374 
00375 
00376     /**
00377      * Mask the src image using the given mask and colors for mask entries.
00378      * @param src image with the source data.
00379      * @param mask labeled or unlabeled mask
00380      * @param colors color entries used to mask the image.  The "dummy" entry
00381      *        of each pixel denotes the transparency of the color used: 0 means
00382      *        opaque and 255 totally transparent. The \e colors attribute of
00383      *        the parameters class will be ignored.
00384      * @param dest destination masked image.
00385      * @return true if apply successful or false otherwise.
00386      */
00387     bool labeled(const image& src,
00388                  const imatrix& mask,
00389                  const palette& colors,
00390                  image& dest) const;
00391 
00392     /**
00393      * Mask the src image using the given mask and colors for mask entries.
00394      * @param src image with the source data.
00395      * @param mask labeled or unlabeled mask
00396      * @param colors color entries used to mask the image.  The "dummy" entry
00397      *        of each pixel denotes the transparency of the color used: 0 means
00398      *        opaque and 255 totally transparent. The \e colors attribute of
00399      *        the parameters class will be ignored.
00400      * @param dest destination masked image.
00401      * @return true if apply successful or false otherwise.
00402      */
00403     bool unlabeled(const image& src,
00404                  const imatrix& mask,
00405                  const palette& colors,
00406                  image& dest) const;
00407     
00408     /**
00409      * Mask the src image using the given mask and colors for mask entries.
00410      * @param src image with the source data.
00411      * @param mask labeled or unlabeled mask
00412      * @param colors color entries used to mask the image.  The "dummy" entry
00413      *        of each pixel denotes the transparency of the color used: 0 means
00414      *        opaque and 255 totally transparent. The \e colors attribute of
00415      *        the parameters class will be ignored.
00416      * @param dest destination masked image.
00417      * @return true if apply successful or false otherwise.
00418      */
00419     bool labeled(const image& src,
00420                  const channel8& mask,
00421                  const palette& colors,
00422                  image& dest) const;
00423 
00424     /**
00425      * Mask the src image using the given mask and colors for mask entries.
00426      * @param src image with the source data.
00427      * @param mask labeled or unlabeled mask
00428      * @param colors color entries used to mask the image.  The "dummy" entry
00429      *        of each pixel denotes the transparency of the color used: 0 means
00430      *        opaque and 255 totally transparent. The \e colors attribute of
00431      *        the parameters class will be ignored.
00432      * @param dest destination masked image.
00433      * @return true if apply successful or false otherwise.
00434      */
00435     bool unlabeled(const image& src,
00436                    const channel8& mask,
00437                    const palette& colors,
00438                    image& dest) const;
00439     
00440   };
00441 }
00442 
00443 #endif

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