Sub topic 10
Converting RGB to CMYK: the naive formula and its limits
This chapter assumes you know how RGB channels work (0 to 255 per channel), how CMYK uses ink plus a black channel K, and what a gamut is. You do not need to run code, but the Python example helps.
The naive formula
A colour model is a way of describing colour with numbers. RGB and CMYK are different models, so converting between them needs a rule. The simplest rule treats ink as the opposite of light. Scale each RGB channel to the range 0 to 1, then work out how much black is needed, then how much of each ink remains.
- Scale: r, g, b = R/255, G/255, B/255.
- Black: K = 1 − max(r, g, b).
- Colour inks: C = (1 − r − K) / (1 − K), M = (1 − g − K) / (1 − K), Y = (1 − b − K) / (1 − K).
- If K is 1, the colour is pure black, so C, M and Y are all 0. This also avoids dividing by zero.
def rgb_to_cmyk_naive(r, g, b):
r, g, b = r / 255, g / 255, b / 255
k = 1 - max(r, g, b)
if k == 1:
return 0.0, 0.0, 0.0, 1.0
c = (1 - r - k) / (1 - k)
m = (1 - g - k) / (1 - k)
y = (1 - b - k) / (1 - k)
return c, m, y, k
print(rgb_to_cmyk_naive(255, 136, 0)) # (0.0, 0.466..., 1.0, 0.0)Walk through the orange #ff8800, which is (255, 136, 0). The largest channel is red at 1.0, so K = 0. Cyan is 0 because red is at full strength. Magenta is about 0.47 because green is about half. Yellow is 1.0 because blue is 0. The result is no cyan, about 47% magenta, full yellow and no black. That is plausible: yellow and magenta inks absorb blue and some green, leaving orange.
Why the formula is only an approximation
The formula is pure arithmetic. It knows nothing about real devices, so it fails in several ways.
- No colour space. An RGB triple means different colours in sRGB and in Adobe RGB. The formula ignores which space the numbers belong to.
- No gamut awareness. Some saturated screen colours, such as vivid cyans and electric blues, lie outside what ink can print. The formula still returns valid-looking percentages, but the printed result will be duller.
- Idealised inks. Real inks do not absorb light perfectly. Cyan ink reflects some green, and magenta ink absorbs some red. Real mixes shift in hue.
- Paper matters. Glossy coated stock gives brighter, more saturated colour than uncoated newsprint. The same ink values look different on each.
- Dot gain. Ink dots spread when printed, so midtones come out darker than the numbers suggest.
- Linear maths on gamma values. sRGB channel values are non-linear (see the gamma chapter). The formula treats them as if they were proportional to light.
- Black generation is fixed. The formula pulls out as much K as possible. Real print workflows choose how much black to use and limit total ink coverage, which is the sum of C, M, Y and K percentages.
A quick check of the limits
Run the formula on pure black and on a light grey to see the K rule at work.
print(rgb_to_cmyk_naive(0, 0, 0)) # (0.0, 0.0, 0.0, 1.0)
print(rgb_to_cmyk_naive(200, 200, 200)) # (0.0, 0.0, 0.0, ~0.216)Neutral greys map to K alone, with no C, M or Y. That looks tidy, but on press a grey made only from black ink often has a slightly warm or flat cast. Many print profiles instead build greys from a mix of all four inks. The formula cannot choose this because it has no model of the press.
Common errors
- Treating the percentages as exact. They describe an idealised device, not your printer.
- Converting twice. RGB to CMYK and back does not return the original values, because out-of-gamut colours are clipped on the first trip.
- Converting too early. Keep artwork in RGB while editing, and convert once at the end, ideally with the printer's profile.
- Forgetting that CMYK numbers are percentages of ink, while RGB numbers are light levels. A higher value means opposite things.
Exercise
Using the naive formula, what are the CMYK values for pure red, RGB (255, 0, 0)? Why might a real printer produce a duller red than the screen shows?
Show answer
Scaled values are r = 1, g = 0, b = 0. K = 1 − 1 = 0. C = (1 − 1 − 0) / 1 = 0, M = (1 − 0 − 0) / 1 = 1, Y = 1. So CMYK is (0, 1, 1, 0): full magenta and full yellow. A real printer gives a duller red because screen red is highly saturated and sits near or outside the printable gamut, and real magenta and yellow inks absorb light imperfectly.
Exercise
Name two things a conversion needs that the naive formula does not have.
Show answer
Any two of: knowledge of the source colour space, the destination device's gamut, the behaviour of real inks and paper, and a rule for handling out-of-gamut colours. An ICC profile supplies this information.