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), what the C, M, Y and K channels represent, and what a gamut is. You should also be able to read short Python. By the end you will be able to write the naive conversion, explain each step, and say why it is not what print work uses.
Why a conversion is needed at all
Screens and printing presses speak different languages. A photo from a camera or a colour picked in a web tool is stored as RGB numbers. A press needs the amount of cyan, magenta, yellow and black ink to lay down at each point. Somewhere between the two, a program must turn three numbers into four.
The simplest way to do that is a pure formula. It uses only arithmetic on the RGB values. It knows nothing about the screen you used, the inks on the press, or the paper. That is why it is called naive here: it is a model of the idea, not of the physical process.
The idea behind the formula
Cyan, magenta and yellow are the complements of red, green and blue.
- Cyan ink absorbs red light. More cyan means less red.
- Magenta ink absorbs green light. More magenta means less green.
- Yellow ink absorbs blue light. More yellow means less blue.
So, if you scale each RGB channel to the range 0 to 1, the "ink needed" for a channel is roughly 1 - channel. A pure red pixel (1, 0, 0) needs no cyan, full magenta and full yellow, because magenta plus yellow ink absorb green and blue and leave red.
If you stopped there, you would have CMY. The K channel is added because mixing equal amounts of C, M and Y should give black, but real inks give a muddy dark brown. Black ink is cheaper, darker and sharper for text. The naive formula therefore pulls the shared dark part out of the three colour channels and moves it into K.
The formula step by step
Start with 8-bit values r, g, b.
- Scale each to 0 to 1:
r' = r / 255, and the same forg'andb'. - Find the black amount:
k = 1 - max(r', g', b'). The brightest channel decides how much light is left, so the rest is dark. - If
kis 1, the pixel is pure black. Output (0, 0, 0, 1). - Otherwise compute each colour channel, with the black part removed:
c = (1 - r' - k) / (1 - k), and likewise form(usingg') andy(usingb').
Step 4 divides by 1 - k to stretch what remains back to the full 0 to 1 range after K has taken its share.
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)Worked example: orange
Take #ff8800, which is RGB (255, 136, 0).
- Scaled: r' = 1.0, g' = 136 / 255 = 0.533, b' = 0.0.
- The largest channel is 1.0, so k = 1 - 1.0 = 0.
- Because k is 0,
1 - kis 1, so no stretching happens. - c = 1 - 1.0 - 0 = 0. m = 1 - 0.533 - 0 = 0.467. y = 1 - 0 - 0 = 1.
The result is C 0%, M 47%, Y 100%, K 0%. That matches the printed output of the code above. It reads sensibly: a full yellow plus about half magenta gives orange.
Now a darker colour. Take RGB (128, 64, 0), a brown.
- Scaled: 0.502, 0.251, 0.
- k = 1 - 0.502 = 0.498.
- c = (1 - 0.502 - 0.498) / 0.502 = 0.
- m = (1 - 0.251 - 0.498) / 0.502 = 0.5.
- y = (1 - 0 - 0.498) / 0.502 = 1.
The brown becomes C 0, M 50%, Y 100%, K 50%. The darkness moved into K, and the hue ratios stayed the same as for the orange.
The next table shows a few more results, rounded to whole percentages.
| RGB | Colour | C | M | Y | K |
|---|---|---|---|---|---|
| 255, 255, 255 | White | 0 | 0 | 0 | 0 |
| 0, 0, 0 | Black | 0 | 0 | 0 | 100 |
| 255, 0, 0 | Red | 0 | 100 | 100 | 0 |
| 0, 0, 255 | Blue | 100 | 100 | 0 | 0 |
| 128, 128, 128 | Mid grey | 0 | 0 | 0 | 50 |
Notice that every grey comes out as K only. That is the formula's behaviour, and it is a useful property for neutral tones. It is not how a press-ready file usually treats photographs, as the next section shows.
Going the other way
The reverse formula is just as simple: r = 255 × (1 - c) × (1 - k), and the same for green with m and blue with y. It has the same flaw. It reproduces the arithmetic but not the appearance of real ink.
def cmyk_to_rgb_naive(c, m, y, k):
r = 255 * (1 - c) * (1 - k)
g = 255 * (1 - m) * (1 - k)
b = 255 * (1 - y) * (1 - k)
return round(r), round(g), round(b)
print(cmyk_to_rgb_naive(0, 0.467, 1, 0)) # (255, 136, 0)The round trip works here only because both functions are exact inverses of each other. Real conversions are not inverses, as the next sections explain.
Where the naive formula breaks down
Several separate problems stack up. Each one has a different cause.
It ignores what the numbers mean
An RGB triple only has a definite colour once you know its colour space. The same (255, 136, 0) looks different in sRGB and in a wide-gamut space such as Display P3. The formula does not ask which one you have. It also does not ask which inks you will print with. A "100% yellow" on glossy coated paper is not the same colour as 100% yellow on uncoated newsprint.
It treats channel values as linear light
The values in an sRGB file are not proportional to light intensity. The sRGB encoding applies a curve, often called gamma. A channel value of 128 is about 22% of full light, not 50%.
def srgb_to_linear(value_8bit):
c = value_8bit / 255
if c <= 0.04045:
return c / 12.92
return ((c + 0.055) / 1.055) ** 2.4
print(srgb_to_linear(128)) # about 0.2158, not 0.5The naive formula takes 1 - r' as if r' measured light. For mid-tones, the true amount of light absorbed differs a lot from what the formula assumes. The result is ink amounts that do not correspond to the brightness you saw on screen.
Real inks are imperfect
The formula assumes ideal inks. Ideal cyan would absorb all red and reflect all green and blue. Real cyan ink also absorbs some green. Real magenta absorbs some blue. Overlapping inks also do not combine by simple addition; the total printed result depends on how the ink sits on the paper and how much it spreads, a effect called dot gain.
Because of this, C, M and Y at 100% together do not give true black. They give a dark brownish tone. That is the practical reason for K, and it also shows why the formula's neat "pull out the shared dark part" step is a simplification.
The gamut does not match
Some RGB colours cannot be printed. A vivid screen cyan, a bright electric green and a saturated blue lie outside the range that typical CMYK inks can reproduce. The formula still returns numbers between 0 and 1 for them, so it hides the problem. A pure RGB blue (0, 0, 255) becomes C 100, M 100, Y 0 on paper, which prints as a darker, purplish blue, not the glowing blue on your monitor.
The formula never reports that a colour is out of gamut. It also never clips or adjusts sensibly. A colour managed conversion does both.
Total ink limits and black generation are ignored
A printing process has a maximum total ink coverage, often somewhere between 240% and 340% depending on paper and press. Adding the four percentages for a dark colour can exceed that, and the ink would not dry properly. The formula has no concept of this limit. It also makes a single fixed choice about how much black to use. Real workflows choose how much K replaces C, M and Y (called black generation) to suit the job.
The table summarises the limits.
| Limit | What the formula assumes | What really happens |
|---|---|---|
| Colour meaning | RGB numbers are absolute | They depend on the colour space |
| Brightness | Values are proportional to light | Values follow a gamma curve |
| Inks | Perfect absorbers | Impure inks, dot gain, paper effects |
| Gamut | All screen colours exist in print | Many bright colours are out of gamut |
| Black | One fixed rule | Chosen per press and paper |
| Ink total | No limit | Presses cap total coverage |
What replaces the formula
Print work uses colour management. The conversion is done by a colour engine that reads two ICC profiles, one for the source space and one for the destination. A profile is a data file that describes how a device or ink and paper combination turns numbers into real colours. The engine converts from the source into a device-independent colour space, then into the destination, and applies a rendering intent to decide what to do with out-of-gamut colours. The next chapter covers profiles and intents in detail.
For now, remember the division of labour:
- The naive formula is for understanding, quick previews, and cases where accuracy does not matter.
- An ICC based conversion is for anything that goes to a printer.
The next diagram compares the two paths.
Common mistakes
- Converting early and repeatedly. Each RGB to CMYK to RGB trip loses information, because out-of-gamut colours are clipped the first time. Keep the original RGB master and convert a copy once, at the end.
- Trusting the printed numbers from a formula. A hex code turned into CMYK by a website uses a formula like the one above, or a generic profile. Do not send those values to a printer without a proof.
- Expecting a round trip to return the start. Convert (0, 0, 255) to CMYK and back through a real profile and you get a duller blue.
- Ignoring the black channel in text. Small black text should be K only. A conversion that builds black from C, M and Y can misregister and blur thin strokes.
- Reading CMYK percentages as portable. The same CMYK values mean different colours on different presses.
Summary
- The naive formula scales RGB to 0 to 1, takes black as
1 - max(r, g, b), then derives C, M and Y from what is left. - It is a correct statement of the idea of subtractive mixing and a poor model of real ink.
- It fails because it ignores the colour space, gamma, ink impurity, gamut limits, black generation and total ink limits.
- Real print conversions use ICC profiles and rendering intents.
Exercise
Use the naive formula to convert RGB (0, 128, 255) to CMYK. Give C, M, Y and K as percentages rounded to the nearest whole number, then name one reason a press would not print this colour as the formula suggests.
Show answer
Scaled values are r' = 0, g' = 128/255 = 0.502, b' = 1. The largest is 1, so k = 0. Then c = 1 - 0 - 0 = 1, m = 1 - 0.502 = 0.498, y = 1 - 1 = 0. The result is C 100%, M 50%, Y 0%, K 0%. A press would not match it because this bright blue is likely outside the CMYK gamut. The real inks are impure and the formula ignores the gamma curve, so the printed colour is duller than the screen colour.
Exercise
Using the formula, what are the CMYK values for RGB (64, 64, 64), and why is the result a good fit for neutral greys but still not a safe choice for printing a photograph?
Show answer
Scaled values are all 0.251, so k = 1 - 0.251 = 0.749. For each colour channel, (1 - 0.251 - 0.749) / 0.251 = 0. The result is C 0, M 0, Y 0, K 75%. Neutral greys map cleanly to K alone. For a photograph the formula still ignores the colour space, gamma, ink limits and gamut, and it makes a single fixed black-generation choice. A profile-based conversion handles those, and may also build some greys from C, M and Y to get richer shadows.