Skip to content
Prev 67249 / 398502 Next

hex format

"Thomas Lumley" <tlumley at u.washington.edu> wrote in message
news:Pine.A41.4.61b.0504071034420.346778 at homer12.u.washington.edu...
Colo(u)rs and numbers are interchangeable to me.  When you look at a
picture, don't you "see" numbers?

Maybe you don't see a number here, but I do. #ff0080 is interpreted in some
(non-R) contexts as a single number.  In many contexts, including HTML,
colors are represented as three bytes in hex with this notation and the "#"
means "hexadecimal".  The RGB color componets can be discerned quite easily:
hex FF is decimal 255 (red), hex 00 is decimal 0 (green), hex 80 is decimal
128 (blue).  Some programs, e.g., Dreamweaver, allow specification of colors
in this hex 3-byte form directly.  The "16 million" colors you seen on a
"true color" display are from the 256*256*256 (or in hex FF*FF*FF) possible
RGB triples.
Sorry if some consider this off topic:
HSV as a color space is really only liked by computer scientists.  Image
processing and color engineers rarely if ever use HSV.

There are MANY other color spaces and computations possible (see "color
spaces" or "color conversions" or other color topics on  this page
http://www.efg2.com/Lab/Library/Color/Science.htm).  Most of these color
manipulations in R are not easy because the very first step, converting
colors, I mean numbers <g>, like #ff0080 to the red, green components is
hindered because one must reinvent the wheel of hex-to-decimal conversion.

Perhaps R will someday introduce a "pixel" type that would encapsulate the
three color components (for color images at least).  A matrix of pixels
could easily be made into an image.  Some color computations such a Maxwell
Triangle, or a CIE Chromaticity Chart (sorry the links are currently broken,
but the image can be seen on this Chinese translation page)
http://bluemoon.myrice.com/efg/color/chromaticity.htm in R is more difficult
than it should be because of how R is designed now.  Many image processing
statistical problems could be tackled directly in R if there were an easier
way to manipulate pixels and images.

But the hex manipulations I'm advocating could be used for variety of other
purposes.  E.g, I must periodically deal with a binary data stream of flow
cytometery data -- part ASCII, part binary.  Reading this stream directly
from R would be nice and is almost doable.  Working with raw data and
understanding  exactly what you've got would be facilitated by better
conversion capabilities within R.

efg