PUTTING COLORS IN ORDER ----------------------------------------------------------------- A new method of looking at RGB color space as Hue, Value and Chroma ----------------------------------------------------------------- Harry J. Smith
There are several systems for the specification of colors. For example 1) The 1931 Commission Internationale l'Eclairage (CIE) standard observer. 2) The Munsell System, Munsell Book of Colors. 3) The Optical Society of America Uniform Color Scale. 4) CIE Uniform Color Space. These and other systems are well documented in the literature. A good reference is "Color and the Computer" edited by H. John Durrett, Academic Press. This book has 16 individual articles on its subject, all with extensive references to other articles.
The method proposed to convert R,G,B to H,V,C is based on my new paradigm which is a geometric model for looking at a color specification. The model is a two dimensional graph, see figure 1. Any color is represented on this graph as three points equally spaced around the circumference of a circle with their vertical coordinates between 0.0 and 1.0. The vertical coordinates of these three points are considered to be the relative intensity of the three phosphor colors R-red, G-green and B-blue. The vertical coordinate of the center of the circle is considered to be the V- value parameter of the color. The angle that the radius from the center to the G-green point makes with a vertical base line is considered to be the H-hue of the color. The radius of the circle is considered to be the C-chroma of the color.
Given an R,G,B triplet or vector it is not easy to know how to plot them so that they lie on a circle, but equations for this will be developed here. First we start with an H,V,C triplet and derive equations for computing R,G,B and then find the inverse of this transformation. Looking at figure 1 we see that the angle from the vertical base to R is H + 120 degrees, to G is H and to B is H - 120 degrees, so it is easy to see that
R = V - C cos(H + 120 degrees) G = V - C cos(H) B = V - C cos(H - 120 degrees)
H = atan2(R - B, (sqrt(3) / 3)(R - 2G + B)) V = (R + G + B) / 3 C = (R - 2G + B) / (3 cos(H) or C = (R - B) / (sqrt(3) sin(H)),
V = (R + G + B) / 3 H = atan2(R - B, sqrt(3)(V - G)) C = (V - G) / cos(H) if |cos(H)| > 0.2 C = (R - B) / (sqrt(3) sin(H)) if |cos(H)| <= 0.2.
The EGA standard for the IBM PCs and compatibles define 64 colors, any 16 of which can be mapped to the usable palette at any given time. If you display these 64 colors in numerical order, 16 at a time, you get a hodgepodge of colors in no logical order. The 64 EGA color numbers are assigned in a way that the numbers can easily be converted to a relative intensity of each of the three phosphor colors R,G,B. If the number is converted to six bit binary, the most significant three bits represent the 25% level of R,G,B in that order and the least significant three bits represent the 75% level of R,G,B in that order. Take EGA color 53 for example. In binary, 53 is 110101. Since both R bits are on, R = 1.0. Of the G bits only the 25% bit is on so G = 0.25. Of the B bits only the 75% bit is on so B = 0.75. For this color
V = (1.0 + 0.25 + 0.75) / 3 = 0.6667 H = atan2(0.25, sqrt(3)(0.4167)) = 19.1066 degrees C = 0.4167 / cos(19.1066 degrees) = 0.4410
The IBM VGA 256K color mode allows a number from 0 to 63 to be used to specify the relative intensity of each of the three phosphor colors R-red, G-green and B-blue. These numbers, call them Rv, Gv, Bv, can be divided by their max value 63 to produce the R,G,V vector needed for the transformation to H,V,C. If we wanted to produce a continuous spectrum of color hues at maximum value and maximum chroma, we can easily do this if we keep our mind focused on the two dimensional color bubble. We start at H = 0 with Bv = 63, Rv = 63 and Gv = 0. Then as the bubble rotates, keeping it at maximum size, Rv and Gv will not change but Bv will decrease by one for each producible color until Bv = 0. Then Rv and Bv will not change but Gv will increase by one for each producible color until Gv = 63. This process will continue until Gv = 0 and Rv = 63 which is where we started.
Once this new way of looking at color as a two dimensional bubble floating above a horizontal line, rotating, rising, falling, expanding and contracting is mastered, it becomes relatively easy to travel through color space in an orderly manner.
Turbo Pascal 5.0 listings are included with this article. Listing 1 is a procedure for converting R,G,B to H,V,C. Listing 2 is a procedure for converting H,V,C to R,G,B. Listing 3 is a procedure for converting EGA color numbers (0-63) to R,G,B.
-----------------------------The End----------------------------- Harry is a Division Principal Engineer, Software, specializing in satellite telemetry data processing. He can be reached at Litton Computer Services 1300 Villa Street, Mountain View, CA 94039 or at his home 19628 Via Monte Drive, Saratoga, CA 95070.