⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 color.h

📁 mean-shift. pointer sample
💻 H
📖 第 1 页 / 共 4 页
字号:
/*!  \file\verbatimCopyright (c) 2004, Sylvain Paris and Francois SillionAll rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions aremet:    * Redistributions of source code must retain the above copyright    notice, this list of conditions and the following disclaimer.        * Redistributions in binary form must reproduce the above    copyright notice, this list of conditions and the following    disclaimer in the documentation and/or other materials provided    with the distribution.    * Neither the name of ARTIS, GRAVIR-IMAG nor the names of its    contributors may be used to endorse or promote products derived    from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOTLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FORA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHTOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOTLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANYTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USEOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\endverbatim   These files contain code made by Sylvain Paris under supervision of  Fran鏾is Sillion for his PhD work with <a  href="http://artis.imag.fr">ARTIS project</a>. ARTIS is a  research project in the GRAVIR/IMAG laboratory, a joint unit of  CNRS, INPG, INRIA and UJF.    Source code can be downloaded from  <a href="http://artis.imag.fr/Members/Sylvain.Paris/index.html#code">Sylvain Paris' page</a>. <!--'-->  The class Basic_color represents a color in 3D space. It is optimized  for operations within this space (mean, distance,...). It is not adapted for  reguler queries to the RGB component.  The class must be instanciated with a \e trait that provides two functions:  \e from_RGB_to_cartesian() and \e from_cartesian_to_RGB() and a typedef for  the type of the components within the color space: \e component_type.  Usual typedefs are defined.   */#ifndef __COLOR__#define __COLOR__#include <cmath>#include <algorithm>#include <iterator>#include <list>#include <vector>#ifndef WITHOUT_LIMITS#include <limits>#endif#include "io_tools.h"#include "msg_stream.h"#ifndef WITHOUT_STATIC_CONST  // in case of trouble with gcc 2.96#define CONST_STATIC const#else#define CONST_STATIC#endif/*  ###############  # typedef ... #  ###############   */template<typename RGB_converter> class Basic_color;template<typename Real> class RGB_color;template<typename Real> class HSV_color;template<typename Real> class XYZ_color;template<typename Real> class Luv_color;template<typename Real> class Lab_color;template<typename Real> class Grey_level_color;template<typename Real> class RGB_converter_to_RGB;template<typename Real> class RGB_converter_to_HSV;template<typename Real> class RGB_converter_to_XYZ;template<typename Real> class RGB_converter_to_Luv;template<typename Real> class RGB_converter_to_Lab;template<typename Real> class RGB_converter_to_grey_level;typedef RGB_color<float>         RGB_f_color;typedef RGB_color<double>        RGB_d_color;typedef HSV_color<float>         HSV_f_color;typedef HSV_color<double>        HSV_d_color;typedef XYZ_color<float>         XYZ_f_color;typedef XYZ_color<double>        XYZ_d_color;typedef Luv_color<float>         Luv_f_color;typedef Luv_color<double>        Luv_d_color;typedef Lab_color<float>         Lab_f_color;typedef Lab_color<double>        Lab_d_color;typedef Grey_level_color<float>  Grey_level_f_color;typedef Grey_level_color<double> Grey_level_d_color;template<typename RGB_converter>std::ostream& operator<<(std::ostream& s,			 const Basic_color<RGB_converter>& c);/*  #####################  # class Basic_color #  #####################*///! Class representing a color. Optimized for operations within the//! color space (mean, distance,...)/*!  An object with the following functions must provided:  - void from_RGB_to_cartesian(const double,const double,const double b,Real* const,Real* const, Real* const)  - static void from_cartesian_to_RGB(const Real,const Real,const Real,double* const,double* const,double* const)  The coordinate type must also be given (float by default). */template<typename RGB_converter>class Basic_color{public:  typedef typename RGB_converter::component_type component_type;  typedef component_type                         distance_type;  typedef RGB_converter  converter_type;    Basic_color();    Basic_color(const char r,  const char g,  const char b);  Basic_color(const float r, const float g, const float b);  Basic_color(const double r,const double g,const double b);    Basic_color(const Basic_color<RGB_converter>& c);    inline Basic_color<RGB_converter>&  operator=(const Basic_color<RGB_converter>& c);  inline bool operator==(const Basic_color<RGB_converter>& c) const;  inline bool operator!=(const Basic_color<RGB_converter>& c) const;    //@{  //! Return the RGB components.    inline void get_RGB(char* const r,  char* const g,  char* const b) const;  inline void get_RGB(float* const r, float* const g, float* const b) const;  inline void get_RGB(double* const r,double* const g,double* const b) const;    //@}  //@{  //! Return the 3D position in the color space.    inline void get_space_position(component_type* const x_space,				 component_type* const y_space,				 component_type* const z_space) const;  template<typename Space_vector>  inline void get_space_position(Space_vector* const space_vector) const;  //@}    //@{  //! Change the 3D position in the color space.    inline void set_space_position(const component_type x_space,				 const component_type y_space,				 const component_type z_space);  template<typename Space_vector>  inline void set_space_position(const Space_vector& space_vector);  //@}  //! Test if the color is not initialzed.  inline bool is_not_a_color() const;  //! Write the color in a binary format to a stream.  inline void write_to_bytes(std::ostream& out) const;  //! Read the color in a binary format from a stream.  inline void read_from_bytes(std::istream& in);  //! Compute the square distance in the color space.  inline static distance_type  square_distance(const Basic_color<RGB_converter>& c1,		  const Basic_color<RGB_converter>& c2);  //! Compute the distance in the color space.  inline static distance_type  distance(const Basic_color<RGB_converter>& c1,	   const Basic_color<RGB_converter>& c2);    //@{  //! Compute the mean color of a color set.    template<typename Basic_color_iterator>  static void mean(Basic_color_iterator first,		   Basic_color_iterator last,		   Basic_color<RGB_converter>* const result);  template<typename Basic_color_iterator,typename Weight_iterator>  static void mean(Basic_color_iterator first_clr,		   Basic_color_iterator last_clr,		   Weight_iterator first_w,		   Weight_iterator last_w,		   Basic_color<RGB_converter>* const result);  //@}  //@{  //! Compute a robust mean of a color set. The colors whose distance to the mean is over the standard deviation are discarded.  template<typename Basic_color_iterator>  static void robust_mean(Basic_color_iterator first,			  Basic_color_iterator last,			  Basic_color<RGB_converter>* const result,			  const unsigned int n_iter = 1);  template<typename Basic_color_iterator,typename Weight_iterator>  static void robust_mean(Basic_color_iterator first_clr,			  Basic_color_iterator last_clr,			  Weight_iterator first_w,			  Weight_iterator last_w,			  Basic_color<RGB_converter>* const result,			  const unsigned int n_iter = 1);  //@}  //! Display the main colors noth in RGB and the color space coordinate system.  //! Mainly a debug tool.  static void main_conversion_output(std::ostream& out = std::cout) ;  //@{  //! Compute the variance of color set.    template<typename Basic_color_iterator>  inline static distance_type  square_deviation(const Basic_color_iterator first,		   const Basic_color_iterator last);  template<typename Basic_color_iterator>  static distance_type  square_deviation(const Basic_color_iterator first,		   const Basic_color_iterator last,		   Basic_color<RGB_converter>* const mean_color);  //@}  //@{  //! Predefined color.  static const Basic_color<RGB_converter> black;  static const Basic_color<RGB_converter> grey;  static const Basic_color<RGB_converter> white;    static const Basic_color<RGB_converter> red;  static const Basic_color<RGB_converter> green;  static const Basic_color<RGB_converter> blue;  static const Basic_color<RGB_converter> cyan;  static const Basic_color<RGB_converter> magenta;  static const Basic_color<RGB_converter> yellow;  //@}  static void cycle(const double alpha,		    Basic_color<RGB_converter>* const result,		    const Basic_color<RGB_converter>& clr_0 = red,		    const Basic_color<RGB_converter>& clr_1 = blue,		    const Basic_color<RGB_converter>& clr_2 = yellow,		    const Basic_color<RGB_converter>& clr_3 = magenta);    //! "ASCII" output  friend std::ostream&  operator<<<RGB_converter>(std::ostream& s,			    const Basic_color<RGB_converter>& c);private:  //@{  //! Coordinate in the color space.    component_type x,y,z;  //@}};/*  ###################  # class RGB_color #  ################### */template<typename Real>class RGB_color  :public Basic_color<RGB_converter_to_RGB<Real> >{public:    RGB_color()    :Basic_color<RGB_converter_to_RGB<Real> >(){}    RGB_color(const char r,  const char g,  const char b)    :Basic_color<RGB_converter_to_RGB<Real> >(r,g,b){}  RGB_color(const float r, const float g, const float b)    :Basic_color<RGB_converter_to_RGB<Real> >(r,g,b){}  RGB_color(const double r,const double g,const double b)    :Basic_color<RGB_converter_to_RGB<Real> >(r,g,b){}    RGB_color(const Basic_color<RGB_converter_to_RGB<Real> >& c)    :Basic_color<RGB_converter_to_RGB<Real> >(c){}};/*  ###################  # class HSV_color #  ################### */template<typename Real>class HSV_color  :public Basic_color<RGB_converter_to_HSV<Real> >{public:    HSV_color()    :Basic_color<RGB_converter_to_HSV<Real> >(){}    HSV_color(const char r,  const char g,  const char b)    :Basic_color<RGB_converter_to_HSV<Real> >(r,g,b){}    HSV_color(const float r, const float g, const float b)    :Basic_color<RGB_converter_to_HSV<Real> >(r,g,b){}    HSV_color(const double r,const double g,const double b)    :Basic_color<RGB_converter_to_HSV<Real> >(r,g,b){}    HSV_color(const Basic_color<RGB_converter_to_HSV<Real> >& c)    :Basic_color<RGB_converter_to_HSV<Real> >(c){}};/*  ###################  # class XYZ_color #  ################### */template<typename Real>class XYZ_color  :public Basic_color<RGB_converter_to_XYZ<Real> >{public:    XYZ_color()    :Basic_color<RGB_converter_to_XYZ<Real> >(){}    XYZ_color(const char r,  const char g,  const char b)    :Basic_color<RGB_converter_to_XYZ<Real> >(r,g,b){}    XYZ_color(const float r, const float g, const float b)    :Basic_color<RGB_converter_to_XYZ<Real> >(r,g,b){}    XYZ_color(const double r,const double g,const double b)    :Basic_color<RGB_converter_to_XYZ<Real> >(r,g,b){}    XYZ_color(const Basic_color<RGB_converter_to_XYZ<Real> >& c)    :Basic_color<RGB_converter_to_XYZ<Real> >(c){}};/*  ###################  # class Luv_color #  ################### */template<typename Real>class Luv_color  :public Basic_color<RGB_converter_to_Luv<Real> >{public:    Luv_color()    :Basic_color<RGB_converter_to_Luv<Real> >(){}    Luv_color(const char r,  const char g,  const char b)    :Basic_color<RGB_converter_to_Luv<Real> >(r,g,b){}    Luv_color(const float r, const float g, const float b)    :Basic_color<RGB_converter_to_Luv<Real> >(r,g,b){}    Luv_color(const double r,const double g,const double b)    :Basic_color<RGB_converter_to_Luv<Real> >(r,g,b){}    Luv_color(const Basic_color<RGB_converter_to_Luv<Real> >& c)    :Basic_color<RGB_converter_to_Luv<Real> >(c){}};/*  ###################  # class Lab_color #  ################### */template<typename Real>class Lab_color  :public Basic_color<RGB_converter_to_Lab<Real> >{public:    Lab_color()    :Basic_color<RGB_converter_to_Lab<Real> >(){}    Lab_color(const char r,  const char g,  const char b)    :Basic_color<RGB_converter_to_Lab<Real> >(r,g,b){}    Lab_color(const float r, const float g, const float b)    :Basic_color<RGB_converter_to_Lab<Real> >(r,g,b){}    Lab_color(const double r,const double g,const double b)    :Basic_color<RGB_converter_to_Lab<Real> >(r,g,b){}    Lab_color(const Basic_color<RGB_converter_to_Lab<Real> >& c)    :Basic_color<RGB_converter_to_Lab<Real> >(c){}};/*  ##########################  # class Grey_level_color #  ########################## */template<typename Real>class Grey_level_color  :public Basic_color<RGB_converter_to_grey_level<Real> >{public:    Grey_level_color()    :Basic_color<RGB_converter_to_grey_level<Real> >(){}  Grey_level_color(const char c)    :Basic_color<RGB_converter_to_grey_level<Real> >(c,c,c){}  Grey_level_color(const float f)    :Basic_color<RGB_converter_to_grey_level<Real> >(f,f,f){}  Grey_level_color(const double d)    :Basic_color<RGB_converter_to_grey_level<Real> >(d,d,d){}    Grey_level_color(const char r,  const char g,  const char b)    :Basic_color<RGB_converter_to_grey_level<Real> >(r,g,b){}    Grey_level_color(const float r, const float g, const float b)    :Basic_color<RGB_converter_to_grey_level<Real> >(r,g,b){}    Grey_level_color(const double r,const double g,const double b)    :Basic_color<RGB_converter_to_grey_level<Real> >(r,g,b){}    Grey_level_color(const Basic_color<RGB_converter_to_grey_level<Real> >& c)    :Basic_color<RGB_converter_to_grey_level<Real> >(c){}};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -