Sub topic 19
ICC profiles and colour management
This chapter assumes you know that an image is an array of channel values, that the same RGB numbers can mean different colours in different colour spaces, and that sRGB uses gamma encoding. It covers how a file says which colour space its numbers use, and how software acts on that.
The problem a profile solves
A pixel of (200, 30, 30) is only a recipe: "200 parts of the first primary, 30 of the second, 30 of the third." The colour you see depends on which primaries the numbers refer to and which transfer curve (gamma) they use. A wide-gamut display has more saturated primaries than a standard sRGB display. If it shows those numbers directly, the red looks more vivid than the author intended.
An ICC profile fixes this. It is a small binary file, defined by the International Color Consortium, that describes how one device or colour space relates to a shared reference. The file records the colour space the image's numbers are in. It does not change the pixels.
What is inside a profile
A profile has a header and a set of tagged tables. The parts that matter in practice:
- Header: the profile class (display, input, output), the data colour space (RGB, CMYK, grey), and the profile connection space (PCS).
- Primaries and white point: where the red, green, and blue primaries sit, usually stored as CIE XYZ coordinates.
- Tone reproduction curves: the transfer function for each channel, such as the sRGB curve or a plain gamma 2.2.
- Lookup tables (LUTs): for devices such as printers, which a few matrices and curves cannot describe.
The PCS is a device-independent space, either CIE XYZ or CIE Lab, with a D50 white point. Every profile converts to and from the PCS, so any two profiles can be linked through it. You do not need a separate conversion for every pair of devices.
Embedded, tagged, and untagged images
Where a profile lives determines what software does with it.
- Embedded: the file contains the profile bytes. JPEG stores them in APP2 segments, PNG in an
iCCPchunk, and TIFF in a tag. - Tagged by reference: PNG can instead carry an
sRGBchunk, which only says "this is sRGB" without storing a profile. - Untagged: no information at all. Software must guess, and the usual guess is sRGB.
Many web workflows strip profiles to save a few kilobytes. That is safe only when the pixels are already in sRGB. If you strip the profile from a Display P3 image, browsers read the numbers as sRGB and the colours look washed out.
Converting between profiles
Colour management does two different things, and mixing them up is a common error.
| Operation | What changes | When to use it |
|---|---|---|
| Assign (tag) | The profile label only. The pixel values stay the same. | The image was untagged or tagged wrongly, and you know its real space. |
| Convert | The pixel values change so the colour appearance stays the same. | You need the image in a different space, such as sRGB for the web. |
The Python example below reads an embedded profile and converts to sRGB. It uses Pillow's ImageCms module, which wraps the Little CMS engine.
import io
from PIL import Image, ImageCms
# Build an image and embed a (built-in) sRGB profile in a PNG.
srgb_bytes = ImageCms.ImageCmsProfile(ImageCms.createProfile("sRGB")).tobytes()
img = Image.new("RGB", (4, 4), (200, 30, 30))
buf = io.BytesIO()
img.save(buf, format="PNG", icc_profile=srgb_bytes)
buf.seek(0)
# Read it back and honour the embedded profile.
loaded = Image.open(buf)
embedded = loaded.info.get("icc_profile")
if embedded is None:
print("Untagged: assume sRGB")
else:
src = ImageCms.ImageCmsProfile(io.BytesIO(embedded))
dst = ImageCms.createProfile("sRGB")
converted = ImageCms.profileToProfile(loaded, src, dst, outputMode="RGB")
print(converted.getpixel((0, 0))) # at or very near (200, 30, 30)Because the source and destination are both sRGB here, the values barely move. With a wide-gamut source, they would change noticeably.
Gamut, clipping, and rendering intents
A gamut is the set of colours a space can represent. When a colour in the source falls outside the destination gamut, the converted value would need a channel below 0 or above 1. You can check this with a few lines of NumPy. The code converts the most saturated red of Display P3 into linear sRGB, using the standard D65 matrices.
import numpy as np
p3_to_xyz = np.array([[0.4865709, 0.2656677, 0.1982173],
[0.2289746, 0.6917385, 0.0792869],
[0.0000000, 0.0451134, 1.0439444]])
xyz_to_srgb = np.array([[ 3.2404542, -1.5371385, -0.4985314],
[-0.9692660, 1.8760108, 0.0415560],
[ 0.0556434, -0.2040259, 1.0572252]])
p3_red_linear = np.array([1.0, 0.0, 0.0])
srgb_linear = xyz_to_srgb @ p3_to_xyz @ p3_red_linear
print(srgb_linear.round(2)) # about [ 1.22 -0.04 -0.02]
print(np.clip(srgb_linear, 0.0, 1.0)) # about [1. 0. 0.]The values 1.22, -0.04, and -0.02 show the colour is outside sRGB. Plain clipping gives (1, 0, 0), which is the most saturated red sRGB can show, but it is not the same colour. A rendering intent tells the colour engine how to handle this.
| Intent | Behaviour | Typical use |
|---|---|---|
| Perceptual | Compresses the whole gamut so relationships between colours are kept. | Photographs |
| Relative colorimetric | Keeps in-gamut colours exact and clips the rest. Maps the white point to the destination white. | Most screen work, and the usual default |
| Absolute colorimetric | Like relative, but keeps the source white point. | Proofing how paper will look |
| Saturation | Boosts saturation. | Charts and graphics |
Relative colorimetric is often combined with black point compensation, which scales the black levels so shadow detail is not crushed.
Common mistakes
- Ignoring the profile when loading. Libraries such as OpenCV return the raw numbers and drop the profile. If a model needs sRGB input and your files are P3 or Adobe RGB, convert first.
- Converting twice. Applying a source-to-sRGB conversion to an image that is already sRGB, because you assumed it was not, shifts the colours a second time.
- Treating a profile as a fix. A converted image cannot regain colours that were clipped on an earlier conversion. Work in the widest space you have, and narrow only at the end.
- Mixing 8-bit wide-gamut with 8-bit sRGB. Wide-gamut images spread the same 256 steps over a larger range, so banding appears sooner. Use 16 bits when editing in a large space.
Where this fits
Earlier chapters gave you the pieces: channels, gamma, sRGB, and CIE Lab. An ICC profile joins them. It names the primaries and curve that define a space, and it gives a route through XYZ or Lab to any other space. The result is that one set of numbers can be displayed, printed, or analysed with the colours the author meant.
Exercise
A photographer exports a Display P3 JPEG with the embedded profile stripped, and uploads it to a website. Viewers see duller colours than the photographer intended. Explain why, and name two ways to fix it.
Show answer
Without a profile, browsers assume the numbers are sRGB. Display P3 has more saturated primaries, so its values, read as sRGB, produce less saturated colours. Fix it by keeping the Display P3 profile embedded, so the browser converts correctly. Alternatively, convert the image to sRGB before export and then tag it as sRGB or leave it untagged.
Exercise
In the NumPy example, why does clipping the result to [0, 1] not preserve the original colour? Which rendering intent would clip and which would compress?
Show answer
The negative and above-one values mean the colour is outside the sRGB gamut. Clipping forces them to 0 and 1, which changes the ratio between channels and so changes the hue and saturation. Relative colorimetric clips out-of-gamut colours. Perceptual compresses the gamut so the relationships between colours are kept.