Sub topic 6
From RGB to a designer-friendly description
This chapter assumes you know that screens mix red, green, and blue light, and that you can read short code samples. It covers why RGB is hard to design with, and how hue, saturation, and value are read back out of the same numbers.
What RGB tells you
A screen pixel is three small lights. RGB stores how bright each one is, usually as three numbers from 0 to 255. Pure red is 255, 0, 0. White is 255, 255, 255. Black is 0, 0, 0.
RGB matches how the hardware works, so software uses it everywhere. The hex code #3366CC is the same data in base 16: 33 is 51, 66 is 102, and CC is 204.
Why RGB is awkward for design decisions
Suppose you have rgb(51, 102, 204) and want a softer version of it. Which number do you change? Lowering one channel shifts the color toward another family. Lowering all three together mostly makes it darker. Nothing in the triple says "make it less intense" or "keep the same blue."
A designer thinks in different questions:
- Which color family is this? (hue)
- How vivid or gray is it? (saturation)
- How light or dark is it? (value)
These questions are about the relationships between the channels. The three numbers hide those relationships.
Reading the three properties from RGB
You can recover all three properties by comparing the channels. Rescale each channel to 0–1, then find the largest and smallest.
- Value is the largest channel. A bright color has at least one strong channel.
- Saturation is the gap between the largest and smallest channels, divided by the largest. If all three channels are equal, the gap is zero and the color is a gray.
- Hue is an angle on the color wheel. It depends on which channel is largest and how the other two compare.
This is the HSV reading of RGB. The next chapter compares it with HSL.
A worked example
Here are several colors from the same data:
| RGB | Hue | Saturation | Value | What you see |
|---|---|---|---|---|
| 255, 0, 0 | 0° | 100% | 100% | Pure red |
| 255, 255, 0 | 60° | 100% | 100% | Pure yellow |
| 0, 0, 128 | 240° | 100% | 50% | Dark navy |
| 128, 128, 128 | undefined | 0% | 50% | Mid gray |
| 51, 102, 204 | 220° | 75% | 80% | Medium blue |
Gray has no hue because the channels are equal, so no channel leads. Software usually reports 0° and you should ignore it.
The same conversion in Python, using the standard library:
import colorsys
def hex_to_hsv(hex_color):
hex_color = hex_color.lstrip("#")
r, g, b = (int(hex_color[i:i + 2], 16) / 255 for i in (0, 2, 4))
h, s, v = colorsys.rgb_to_hsv(r, g, b)
return round(h * 360), round(s * 100), round(v * 100)
print(hex_to_hsv("#3366CC")) # (220, 75, 80)
print(hex_to_hsv("#808080")) # (0, 0, 50)The function divides by 255 because colorsys expects values from 0 to 1. It multiplies the results back so you get degrees and percentages.
Common errors
- Forgetting the 0–1 range. Passing 0–255 values to
colorsysgives wrong results with no error message. - Treating the hue of a gray as meaningful. When saturation is 0, any hue value is arbitrary.
- Expecting a round trip to be exact. Rounding to whole numbers can change an RGB value by 1 after converting back.
Exercise
Without a tool, estimate the hue, saturation, and value of rgb(255, 128, 0). Use the rules above.
Show answer
The largest channel is 255, so value is 100%. The smallest is 0, so saturation is (255 − 0) / 255 = 100%. Red leads and green is about halfway up, so the hue sits about halfway between red (0°) and yellow (60°), at about 30°. The color is a vivid orange.