Sub topic 11
What a Colour Space Defines
Assume you know basic arrays, bytes, and common image files such as JPEG and PNG. This chapter focuses on the working model: a colour space gives meaning to channel numbers.
A pixel such as (128, 64, 32) is not a complete description of a visible colour. The numbers need rules. A colour space is a defined system that says how channel values correspond to colours. Its definition usually includes:
- The primary colours used by the channels.
- A white point, which defines what “white” means.
- A transfer function, which defines how stored values relate to light.
- The range and encoding of valid values.
Why the same numbers can look different
Consider an RGB pixel with values (255, 0, 0). It means “maximum red” in that space, but the exact red depends on the space’s red primary. The red primary in sRGB is different from the red primary in Display P3. Display P3 can represent some vivid colours that sRGB cannot.
Therefore, RGB is a colour model, not one single colour space. It describes the use of red, green, and blue channels. A named space such as sRGB adds the missing definitions.
| Term | What it defines | Example |
|---|---|---|
| Colour model | How components describe colour | RGB |
| Colour space | Model plus colour meaning and encoding rules | sRGB |
| Colour profile | Data that identifies or describes a space in a file | An embedded ICC profile |
A colour space can also be device-dependent or device-independent. A camera or monitor may have its own measurable response. CIE XYZ and CIE Lab are designed as device-independent reference systems, although real conversions still require carefully defined viewing conditions.
Stored values and light
Many image formats store encoded values rather than light intensity. In sRGB, the stored value 128 is not half the physical light of 255. A transfer function allocates more code values to darker ranges, where changes are easier to notice.
import numpy as np
def srgb_to_linear(value):
c = np.asarray(value, dtype=float) / 255.0
return np.where(
c <= 0.04045,
c / 12.92,
((c + 0.055) / 1.055) ** 2.4,
)
for value in (0, 128, 255):
print(value, round(float(srgb_to_linear(value)), 4))The output shows that 128 represents about 0.216 linear light, not 0.5. Image arithmetic such as blending and averaging should often use linear-light values, then encode the result for storage or display.
A colour-space interpretation pipeline
Choosing a space
Use sRGB for broad web compatibility. Use Display P3 when a managed workflow and wider-gamut display are available. Use Lab when comparing perceptual colour differences. Use a linear-light representation for physical calculations, compositing, or rendering.
Exercise
Why is (255, 0, 0) not enough to identify one exact visible red?
Show answer
The colour space must define the red primary, white point, and encoding rules.