last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 1998-2005 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 /** 00043 * \file cvrHueLUT.h 00044 * Contains the hue lookup table. 00045 * \author Pablo Alvarado 00046 * \author Peter Doerfler 00047 * \date 28.04.2005 00048 * 00049 * $Id: cvrHueLUT.h,v 1.3 2007/12/26 04:49:23 alvarado Exp $ 00050 */ 00051 00052 #ifndef _CVR_HUE_LUT_H_ 00053 #define _CVR_HUE_LUT_H_ 00054 00055 #include "cvrObject.h" 00056 #include "cvrMath.h" 00057 #include "cvrAssert.h" 00058 00059 namespace cvr { 00060 /** 00061 * Following class provides a mono-state object that contains a 0.5MB Look-up 00062 * Table to accelerate the computation of hues. 00063 * 00064 * The hue is defined in terms of the RGB components and rgb chromaticities 00065 * as 00066 * \f[ 00067 * \begin{aligned} 00068 * H &= \arccos\left(\frac{\frac{1}{2}\left[(R-G) + (R-B)\right]} 00069 * {\sqrt{(R-G)^2+(R-B)(G-B))}}\right) \\ 00070 * &= \arccos\left(\frac{\frac{1}{2}\left[(r-g) + (r-b)\right]} 00071 * {\sqrt{(r-g)^2+(r-b)(g-b))}}\right) \\ 00072 * &= \arccos\left[\frac{3r-1} 00073 {2\sqrt{3r^2+3g^2+3rg-3r-3g+1}}\right] 00074 * \end{aligned} 00075 * \f] 00076 * 00077 * where for the last equation it was used the fact that \f$ r=1-g-b \f$. 00078 * 00079 * \b Note: This class normalizes the hue to be in the range [0,1] 00080 * which is more practical for the CVR-Lib than the typical 0..360 00081 * degrees definition. 00082 * 00083 * The LUT uses the fact that r+g+b=255 and thus only takes r and g as 00084 * inputs, where r,g, and b are the chromaticity values obtained by 00085 * normalization as r=R/(R+G+B), g=G/(R+G+B). These values need to be 00086 * multiplied by 511, which is the last index the LUT takes. Note that 00087 * r+g<512, and r,g >= 0 00088 * 00089 * As a mono-state class, only one instance of the LUT array will be created. 00090 * 00091 * @ingroup gColor 00092 */ 00093 class hueLUT : public object { 00094 public: 00095 /** 00096 * Construct the class 00097 * Here, the LUT will be build just once (if not already done). 00098 * The first time you construct this class, it will take about 0.15 seconds 00099 * to build the LUT. 00100 */ 00101 hueLUT(); 00102 00103 /** 00104 * return the hue for (r,g). r,g >=0 and r+g<512 00105 * 00106 * @param r red component 00107 * @param g green component 00108 * @return hue between 0 and 1 00109 */ 00110 inline float operator() (const int r,const int g) const; 00111 00112 /** 00113 * Returns the name of this class 00114 */ 00115 virtual const std::string& name() const; 00116 00117 /** 00118 * Returns a pointer to a clone of the parameters. 00119 */ 00120 virtual hueLUT* clone() const; 00121 00122 /** 00123 * Returns a pointer to a clone of the parameters. 00124 */ 00125 virtual hueLUT* newInstance() const; 00126 00127 protected: 00128 /** 00129 * Construct a hue LUT. It assumes that r,g>=0 and r+g<512. The 00130 * 0.5MB memory required should not be a problem in modern PCs 00131 * anymore!. 00132 */ 00133 static void constructHueLUT(); 00134 00135 /** 00136 * Type required to create the LUT as a const structure 00137 */ 00138 typedef const float* cfloatptr_; 00139 00140 /** 00141 * The hueLUT with floats. 00142 */ 00143 static const cfloatptr_* hueLUT_; 00144 }; 00145 00146 inline float hueLUT::operator() (const int r,const int g) const { 00147 00148 #ifdef _CVR_DEBUG 00149 _lti_debug4("r=" << r << " g=" << g << "\n"); 00150 #endif 00151 00152 // check in debug modus that range is ok 00153 assert((r>=0) && (g>=0) && ((r+g)<512)); 00154 00155 // just return the value 00156 return hueLUT_[r][g]; 00157 } 00158 00159 00160 } 00161 00162 #endif