[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] cmyk -> gray conversion
From: |
Gaius Mulley |
Subject: |
Re: [Groff] cmyk -> gray conversion |
Date: |
Mon, 29 Oct 2001 17:24:13 +0000 |
Hi Werner,
> Does somebody know a conversion algorithm CMYK -> gray? For RGB, I
> use
>
> 0.299r + 0.587g + 0.114b
I find the color space faq useful [see >>>] hope this helps?
Gaius
5.1 - RGB, CMY, and CMYK
The most popular color spaces are RGB and CMY. These two acronyms stand
for Red-Green-Blue and Cyan-Magenta-Yellow. They're device-dependent.
The first is normally used on monitors, the second on printers.
RGB are called primary colors because a color is produced by adding
the three components, red, green, and blue.
CMY is called secondary colors because to describe a color in this color
space, you consider the reflecting result. So, you become like a painter
who puts some (secondary) colors on a sheet of paper. A *white* light is
received on the sheet. You have to keep in mind that white in RGB is all
components set up to their maximum values. The white color is reflected on
the sheet so that the components of white (primary colors) are subtracted
from the components of the 'painting' (secondary colors). Such reflecting
colors are called secondary colors, for the previous reasons...
RGB -> CMY | CMY -> RGB
Red = 1-Cyan (0<=Cyan<=1) | Cyan = 1-Red (0<=Red<=1)
Green = 1-Magenta (0<=Magenta<=1) | Magenta = 1-Green (0<=Green<=1)
Blue = 1-Yellow (0<=Yellow<=1) | Yellow = 1-Blue (0<=Blue<=1)
On printer devices, a component of black is added to the CMY, and the
second color space is then called CMYK (Cyan-Magenta-Yellow-blacK). This
component is actually used because cyan, magenta, and yellow set up to the
maximum should produce a black color. (The RGB components of the white are
completly substracted from the CMY components.) But the resulting color
isn't physically a 'true' black. The most usual definition for the CMYK
color space is given below:
CMY -> CMYK | CMYK -> CMY
Black=minimum(Cyan,Magenta,Yellow) | Cyan=minimum(1,Cyan*(1-Black)+Black)
Cyan=(Cyan-Black)/(1-Black) |
Magenta=minimum(1,Magenta*(1-Black)+Black)
Magenta=(Magenta-Black)/(1-Black) |
Yellow=minimum(1,Yellow*(1-Black)+Black)
Yellow=(Yellow-Black)/(1-Black) |
RGB -> CMYK | CMYK -> RGB
Black=minimum(1-Red,1-Green,1-Blue) | Red=1-minimum(1,Cyan*(1-Black)+Black)
Cyan=(1-Red-Black)/(1-Black) |
Green=1-minimum(1,Magenta*(1-Black)+Black)
Magenta=(1-Green-Black)/(1-Black) |
Blue=1-minimum(1,Yellow*(1-Black)+Black)
Yellow=(1-Blue-Black)/(1-Black) |
Of course, I assume that C, M, Y, K, R, G, and B have a range of [0;1].
5.2 - HSL, HSV
The representation of the colors in the RGB space is quite adapted for
monitors but from a human being, this is not a useful definition. To
provide a user representation in the user interfaces, we preferr the HSL
color space. The acronym stand for Hue (see definition of Hue in item 2),
Saturation (see definition of Colorfulness in item 2), and Luminosity
(see definition of Luminancy in item 2).
The HSV model can be represented by a trigonal cone, as:
Green
/\
/ \ ^
/V=1 x \ \ Hue (angle, so that Hue(Red)=0, Hue(Green)=120,
and Hue(blue)=240 deg)
Blue -------------- Red
\ | /
\ |-> Saturation (distance from the central axis)
\ | /
\ | /
\ | /
\ |/
V=0 x (Value=0 at the top of the apex and =1 at the base of the
cone)
The big disadvantage of this model is the conversion. Most of publishings
(Microsoft, and Foley's "Computer Graphics: Principles and Practice",
included) give unaccurate transforms. Actually, the transforms are really
complicate, as given below:
Hue = (Alpha-arctan((Red-Luminosity)*(3^0.5)/(Green-Blue)))/(2*PI)
with { Alpha=PI/2 if Green>Blue
{ Aplha=3*PI/2 if Green CIE XYZccir601-1 (C illuminant):
|X| |0.606881 0.173505 0.200336| |Red |
|Y| = |0.298912 0.586611 0.114478| * |Green|
|Z| |0.000000 0.066097 1.116157| |Blue |
Because I'm a programer, I preferr to round these values up or down (in
regard with the new precision) and I get:
RGB -> CIE XYZccir601-1 (C illuminant) | CIE XYZccir601-1 (C
illuminant) -> RGB
X = 0.607*Red+0.174*Green+0.200*Blue | Red =
1.910*X-0.532*Y-0.288*Z
Y = 0.299*Red+0.587*Green+0.114*Blue | Green =
-0.985*X+1.999*Y-0.028*Z
Z = 0.000*Red+0.066*Green+1.116*Blue | Blue =
0.058*X-0.118*Y+0.898*Z
The other common recommendation is the 709. The white point is D65 and have
coordinates fixed as (xn;yn)=(0.312713;0.329016). The RGB chromacity
coordinates are:
Red: xr=0.64 yr=0.33
Green: xg=0.30 yg=0.60
Blue: xb=0.15 yb=0.06
Finally, we have RGB -> CIE XYZccir709 (709):
|X| |0.412411 0.357585 0.180454| |Red |
|Y| = |0.212649 0.715169 0.072182| * |Green|
|Z| |0.019332 0.119195 0.950390| |Blue |
This provides the formula to transform RGB to CIE XYZccir709 and vice-versa:
RGB -> CIE XYZccir709 (D65) | CIE XYZccir709 (D65) -> RGB
X = 0.412*Red+0.358*Green+0.180*Blue | Red =
3.241*X-1.537*Y-0.499*Z
Y = 0.213*Red+0.715*Green+0.072*Blue | Green =
-0.969*X+1.876*Y+0.042*Z
Z = 0.019*Red+0.119*Green+0.950*Blue | Blue =
0.056*X-0.204*Y+1.057*Z
Recently (about one year ago), CCIR and CCITT were both absorbed into their
parent body, the International Telecommunications Union (ITU). So you must
*not* use CCIR 601-1 and CCIR 709 anymore. Furthermore, their names have
changed respectively to Rec 601-1 and Rec 709 ("Rec" stands for
Recommendation). Here is the new ITU recommendation.
The white point is D65 and have coordinates fixed as (xn;yn)=(0.312713;
0.329016). The RGB chromacity coordinates are:
Red: xr=0.64 yr=0.33
Green: xg=0.29 yg=0.60
Blue: xb=0.15 yb=0.06
Finally, we have RGB -> CIE XYZitu (D65):
|X| |0.430574 0.341550 0.178325| |Red |
|Y| = |0.222015 0.706655 0.071330| * |Green|
|Z| |0.020183 0.129553 0.939180| |Blue |
This provides the formula to transform RGB to CIE XYZitu and vice-versa:
RGB -> CIE XYZitu (D65) | CIE XYZitu (D65) -> RGB
X = 0.431*Red+0.342*Green+0.178*Blue | Red =
3.063*X-1.393*Y-0.476*Z
Y = 0.222*Red+0.707*Green+0.071*Blue | Green =
-0.969*X+1.876*Y+0.042*Z
Z = 0.020*Red+0.130*Green+0.939*Blue | Blue =
0.068*X-0.229*Y+1.069*Z
All the conversions I presented until there in this item are not just for
fun ;-). They can really be useful. For example, in most of your
applications you have true color images in RGB color space. How to render
them fastly on your screen or on your favorite printer. This is simple.
You can convert your picture instantaneously in gray scale pictures see
even in a black and white pictures as a magician.
To do so, you just need to convert your RGB values into the Y component.
Actually, Y is linked to the luminosity (Y is an achromatic component) and
X and Z are linked to the colorfulness (X and Z are two chromatic
components). Old softwares used Rec 601-1 and produced:
Gray scale=Y=(299*Red+587*Green+114*Blue)/1000
With Rec 709, we have:
Gray scale=Y=(213*Red+715*Green+72*Blue)/1000
Some others do as if:
Gray scale=Green (They don't consider the red and blue components at all)
Or Gray scale=(Red+Green+Blue)/3
But now all people *should* use the most accurate, it means ITU standard:
>>> Gray scale=Y=(222*Red+707*Green+71*Blue)/1000
(That's very close to Rec 709!)
I made some personal tests and have sorted them in regard with the global
resulting luminosity of the picture (from my eye point of view!). The
following summary gives what I found ordered increasingly:
+-----------------------------+----------------+
|Scheme |Luminosity level|
+-----------------------------+----------------+
|Gray=Green | 1 |
|Gray=ITU (D65) | 2 |
|Gray=Rec 709 (D65) | 3 |
|Gray=Rec 601-1 (C illuminant)| 4 |
|Gray=(Red+Green+Blue)/3 | 5 |
+-----------------------------+----------------+
So softwares with Gray=Rec 709 (D65) produce a more dark picture than with
Gray=Green. Even if you theorically lose many details with Gray=Green
scheme, in fact, and with the 64-gray levels of a VGA card of a PC it is
hard to distinguish the losts.