CVR-Lib last update 20 Sep 2009

cvrColorQuantization.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1998-2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  *
00006  * This file is part of the Computer Vision and Robotics Library (CVR-Lib)
00007  *
00008  * The CVR-Lib is free software; you can redistribute it and/or
00009  * modify it under the terms of the BSD License.
00010  *
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright notice,
00017  *    this list of conditions and the following disclaimer.
00018  *
00019  * 2. Redistributions in binary form must reproduce the above copyright notice,
00020  *    this list of conditions and the following disclaimer in the documentation
00021  *    and/or other materials provided with the distribution.
00022  *
00023  * 3. Neither the name of the authors nor the names of its contributors may be
00024  *    used to endorse or promote products derived from this software without
00025  *    specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * POSSIBILITY OF SUCH DAMAGE.
00038  */
00039 
00040 
00041 /**
00042  * \file   cvrColorQuantization.h
00043  *         Contains parent class for all color quantization algorithms.
00044  * \author Pablo Alvarado
00045  * \date   08.05.2001 (CVR-Lib 1)
00046  * \date   12.01.2006 (CVR-Lib )
00047  *
00048  * $Id: cvrColorQuantization.h,v 1.2 2006/01/15 22:15:27 alvarado Exp $
00049  */
00050 
00051 #ifndef _CVR_COLOR_QUANTIZATION_H_
00052 #define _CVR_COLOR_QUANTIZATION_H_
00053 
00054 #include "cvrFunctor.h"
00055 #include "cvrMatrix.h"
00056 #include "cvrImage.h"
00057 
00058 namespace cvr {
00059 
00060   /**
00061    * Abstract parent class for all color quantization algorithms.
00062    *
00063    * All color quantization functors must overload the apply-methods defined
00064    * here (see colorQuantization::apply())
00065    *
00066    * The final quantized color image can be generated using the cvr::usePalette
00067    * functor.
00068    *
00069    * @ingroup gColorQuantization
00070    */
00071   class colorQuantization : public functor {
00072   public:
00073     /**
00074      * The parameters for the class colorQuantization
00075      */
00076     class parameters : public functor::parameters {
00077     public:
00078       /**
00079        * Default constructor.
00080        */
00081       parameters();
00082 
00083       /**
00084        * Copy constructor.
00085        *
00086        * @param other the parameters object to be copied
00087        */
00088       parameters(const parameters& other);
00089 
00090       /**
00091        * Destructor
00092        */
00093       virtual ~parameters();
00094 
00095       /**
00096        * Returns the name of this type
00097        */
00098       virtual const std::string& name() const;
00099 
00100       /**
00101        * Returns a pointer to a clone of the parameters
00102        */
00103       virtual parameters* clone() const;
00104 
00105       /**
00106        * Returns a pointer to a new instance of the parameters
00107        */
00108       virtual parameters* newInstance() const;
00109 
00110       /**
00111        * Copy the other instance.here.
00112        */
00113       parameters& copy(const parameters& other);
00114 
00115       /**
00116        * Copy the contents of a parameters object.
00117        *
00118        * @param other the parameters object to be copied
00119        * @return a reference to this parameters object
00120        */
00121       parameters& operator=(const parameters& other);
00122 
00123       /**
00124        * Write the parameters in the given ioHandler.
00125        *
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 write(ioHandler& handler,const bool complete=true) const;
00132 
00133       /**
00134        * Read the parameters from the given ioHandler.
00135        *
00136        * @param handler the ioHandler to be used
00137        * @param complete if true (the default) the enclosing begin/end will
00138        *        be also written, otherwise only the data block will be written.
00139        * @return true if write was successful
00140        */
00141       virtual bool read(ioHandler& handler,const bool complete=true);
00142 
00143       // ------------------------------------------------
00144       // the parameters
00145       // ------------------------------------------------
00146 
00147       /**
00148        * Number of colors that the resulting quantization must have.
00149        *
00150        * Usually this value must be between 2 and 256, but each functor
00151        * can modify this requirement.
00152        *
00153        * Default value: 256
00154        */
00155       int numberOfColors;
00156 
00157     };
00158 
00159     /**
00160      * Default constructor.
00161      */
00162     colorQuantization();
00163 
00164     /**
00165      * Copy constructor.
00166      *
00167      * @param other the object to be copied
00168      */
00169     colorQuantization(const colorQuantization& other);
00170 
00171     /**
00172      * Destructor.
00173      */
00174     virtual ~colorQuantization();
00175 
00176     /**
00177      * Returns the name of this type.
00178      */
00179     virtual const std::string& name() const;
00180 
00181     /**
00182      * Copy data of "other" functor.
00183      *
00184      * @param other the functor to be copied
00185      * @return a reference to this functor object
00186      */
00187     colorQuantization& copy(const colorQuantization& other);
00188 
00189     /**
00190      * Returns a pointer to a clone of this functor.
00191      */
00192     virtual colorQuantization* clone() const = 0;
00193 
00194     /**
00195      * Returns a pointer to a clone of this functor.
00196      */
00197     virtual colorQuantization* newInstance() const = 0;
00198 
00199     /**
00200      * Returns used parameters
00201      */
00202     const parameters& getParameters() const;
00203 
00204     /**
00205      * Quantize the colors of src and leave the labels for the quantized colors
00206      * in dest, and in the palette entries corresponding to the labels the
00207      * mean colors for each label.
00208      *
00209      * @param src original image with the true-color data
00210      * @param dest channel8 where the indexes of the also calculated palette
00211      *             will be.
00212      * @param thePalette the color palette used by the channel.
00213      * @return true if apply successful or false otherwise.
00214      */
00215     virtual bool apply(const image& src,
00216                        matrix<ubyte>& dest,
00217                        palette& thePalette) const = 0;
00218 
00219     /**
00220      * Quantize the colors of src and leave the labels for the quantized colors
00221      * in dest, and in the palette entries corresponding to the labels the
00222      * mean colors for each label.
00223      *
00224      * @param src original image with the true-color data
00225      * @param dest channel8 where the indexes of the also calculated palette
00226      *             will be.
00227      * @param thePalette the color palette used by the channel.
00228      * @return true if apply successful or false otherwise.
00229      */
00230     virtual bool apply(const image& src,
00231                        matrix<int32>& dest,
00232                        palette& thePalette) const = 0;
00233 
00234     /**
00235      * Quantize the colors of the given image.
00236      *
00237      * @param srcdest image with the source data.  The result
00238      *                 will be left here too.
00239      * @return true if apply successful or false otherwise.
00240      */
00241     virtual bool apply(image& srcdest) const;
00242 
00243     /**
00244      * Quantize the colors of the given src image and leave the result in dest.
00245      *
00246      * @param src image with the source data.
00247      * @param dest image with only the number of colors specified in
00248      *             the parameters
00249      * @return true if apply successful or false otherwise.
00250      */
00251     virtual bool apply(const image& src,image& dest) const;
00252   };
00253 }
00254 
00255 #endif
00256 

Generated on Sun Sep 20 22:07:59 2009 for CVR-Lib by Doxygen 1.5.8