요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
.. _colorspaces:
***********
Colorspaces
***********
'Color' is a very complex concept and depends on physics, chemistry and
biology. Just because you have three numbers that describe the 'red',
'green' and 'blue' components of the color of a pixel does not mean that
you can accurately display that color. A colorspace defines what it
actually *means* to have an RGB value of e.g. (255, 0, 0). That is,
which color should be reproduced on the screen in a perfectly calibrated
environment.
In order to do that we first need to have a good definition of color,
i.e. some way to uniquely and unambiguously define a color so that
someone else can reproduce it. Human color vision is trichromatic since
the human eye has color receptors that are sensitive to three different
wavelengths of light. Hence the need to use three numbers to describe
color. Be glad you are not a mantis shrimp as those are sensitive to 12
different wavelengths, so instead of RGB we would be using the
ABCDEFGHIJKL colorspace...
Color exists only in the eye and brain and is the result of how strongly
color receptors are stimulated. This is based on the Spectral Power
Distribution (SPD) which is a graph showing the intensity (radiant
power) of the light at wavelengths covering the visible spectrum as it
enters the eye. The science of colorimetry is about the relationship
between the SPD and color as perceived by the human brain.
Since the human eye has only three color receptors it is perfectly
possible that different SPDs will result in the same stimulation of
those receptors and are perceived as the same color, even though the SPD
of the light is different.
In the 1920s experiments were devised to determine the relationship
between SPDs and the perceived color and that resulted in the CIE 1931
standard that defines spectral weighting functions that model the
perception of color. Specifically that standard defines functions that
can take an SPD and calculate the stimulus for each color receptor.
After some further mathematical transforms these stimuli are known as
the *CIE XYZ tristimulus* values and these X, Y and Z values describe a
color as perceived by a human unambiguously. These X, Y and Z values are
all in the range [0…1].
The Y value in the CIE XYZ colorspace corresponds to luminance. Often
the CIE XYZ colorspace is transformed to the normalized CIE xyY
colorspace:
x = X / (X + Y + Z)
y = Y / (X + Y + Z)
The x and y values are the chromaticity coordinates and can be used to
define a color without the luminance component Y. It is very confusing
to have such similar names for these colorspaces. Just be aware that if
colors are specified with lower case 'x' and 'y', then the CIE xyY
colorspace is used. Upper case 'X' and 'Y' refer to the CIE XYZ
colorspace. Also, y has nothing to do with luminance. Together x and y
specify a color, and Y the luminance. That is really all you need to
remember from a practical point of view. At the end of this section you
will find reading resources that go into much more detail if you are
interested.
A monitor or TV will reproduce colors by emitting light at three
different wavelengths, the combination of which will stimulate the color
receptors in the eye and thus cause the perception of color.
Historically these wavelengths were defined by the red, green and blue
phosphors used in the displays. These *color primaries* are part of what
defines a colorspace.
Different display devices will have different primaries and some
primaries are more suitable for some display technologies than others.
This has resulted in a variety of colorspaces that are used for
different display technologies or uses. To define a colorspace you need
to define the three color primaries (these are typically defined as x, y
chromaticity coordinates from the CIE xyY colorspace) but also the white
reference: that is the color obtained when all three primaries are at
maximum power. This determines the relative power or energy of the
primaries. This is usually chosen to be close to daylight which has been
defined as the CIE D65 Illuminant.
To recapitulate: the CIE XYZ colorspace uniquely identifies colors.
Other colorspaces are defined by three chromaticity coordinates defined
in the CIE xyY colorspace. Based on those a 3x3 matrix can be
constructed that transforms CIE XYZ colors to colors in the new
colorspace.
Both the CIE XYZ and the RGB colorspace that are derived from the
specific chromaticity primaries are linear colorspaces. But neither the
eye, nor display technology is linear. Doubling the values of all
components in the linear colorspace will not be perceived as twice the
intensity of the color. So each colorspace also defines a transfer
function that takes a linear color component value and transforms it to
the non-linear component value, which is a closer match to the
non-linear performance of both the eye and displays. Linear component
values are denoted RGB, non-linear are denoted as R'G'B'. In general
colors used in graphics are all R'G'B', except in openGL which uses
linear RGB. Special care should be taken when dealing with openGL to
provide linear RGB colors or to use the built-in openGL support to apply
the inverse transfer function.
The final piece that defines a colorspace is a function that transforms
non-linear R'G'B' to non-linear Y'CbCr. This function is determined by
the so-called luma coefficients. There may be multiple possible Y'CbCr
encodings allowed for the same colorspace. Many encodings of color
prefer to use luma (Y') and chroma (CbCr) instead of R'G'B'. Since the
human eye is more sensitive to differences in luminance than in color
this encoding allows one to reduce the amount of color information
compared to the luma data. Note that the luma (Y') is unrelated to the Y
in the CIE XYZ colorspace. Also note that Y'CbCr is often called YCbCr
or YUV even though these are strictly speaking wrong.
Sometimes people confuse Y'CbCr as being a colorspace. This is not
correct, it is just an encoding of an R'G'B' color into luma and chroma
values. The underlying colorspace that is associated with the R'G'B'
color is also associated with the Y'CbCr color.
The final step is how the RGB, R'G'B' or Y'CbCr values are quantized.
The CIE XYZ colorspace where X, Y and Z are in the range [0…1] describes
all colors that humans can perceive, but the transform to another
colorspace will produce colors that are outside the [0…1] range. Once
clamped to the [0…1] range those colors can no longer be reproduced in
that colorspace. This clamping is what reduces the extent or gamut of
the colorspace. How the range of [0…1] is translated to integer values
in the range of [0…255] (or higher, depending on the color depth) is
called the quantization. This is *not* part of the colorspace
definition. In practice RGB or R'G'B' values are full range, i.e. they
use the full [0…255] range. Y'CbCr values on the other hand are limited
range with Y' using [16…235] and Cb and Cr using [16…240].
Unfortunately, in some cases limited range RGB is also used where the
components use the range [16…235]. And full range Y'CbCr also exists
using the [0…255] range.
In order to correctly interpret a color you need to know the
quantization range, whether it is R'G'B' or Y'CbCr, the used Y'CbCr
encoding and the colorspace. From that information you can calculate the
corresponding CIE XYZ color and map that again to whatever colorspace
your display device uses.
The colorspace definition itself consists of the three chromaticity
primaries, the white reference chromaticity, a transfer function and the
luma coefficients needed to transform R'G'B' to Y'CbCr. While some
colorspace standards correctly define all four, quite often the
colorspace standard only defines some, and you have to rely on other
standards for the missing pieces. The fact that colorspaces are often a
mix of different standards also led to very confusing naming conventions
where the name of a standard was used to name a colorspace when in fact
that standard was part of various other colorspaces as well.
If you want to read more about colors and colorspaces, then the
following resources are useful: :ref:`poynton` is a good practical
book for video engineers, :ref:`colimg` has a much broader scope and
describes many more aspects of color (physics, chemistry, biology,
etc.). The
`http://www.brucelindbloom.com <http://www.brucelindbloom.com>`__
website is an excellent resource, especially with respect to the
mathematics behind colorspace conversions. The wikipedia
`CIE 1931 colorspace <http://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space>`__
article is also very useful.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
색 지각과 분광 분포
1-36색은 물리학·화학·생물학이 함께 관여하는 복잡한 개념입니다. 픽셀의 빨강·초록·파랑 성분을 숫자 세 개로 갖고 있다는 사실만으로는 그 색을 정확히 표시할 수 없습니다.
색공간은 예를 들어 RGB 값 (255, 0, 0)이 완전히 보정된 환경에서 실제로 어떤 색으로 재현되어야 하는지 정의합니다. 같은 숫자라도 원색 좌표와 흰색 기준이 다르면 화면에 나타나는 색이 달라집니다.
사람의 색각은 서로 다른 세 파장 영역에 민감한 수용체를 사용하므로 삼색성입니다. 원문은 12개 파장에 민감한 갯가재라면 RGB가 아니라 열두 성분의 ABCDEFGHIJKL 색공간이 필요했을 것이라는 비유로 세 성분의 생물학적 이유를 설명합니다.
색은 빛의 물리적 속성만이 아니라 눈의 수용체 자극과 뇌의 해석으로 생깁니다. 눈에 들어오는 가시광 파장별 복사 세기를 그린 곡선이 SPD(Spectral Power Distribution)이며, 측색학은 SPD와 사람이 지각하는 색 사이의 관계를 다룹니다.
수용체가 세 종류뿐이므로 서로 다른 SPD가 같은 세 자극을 만들 수 있고, 이 경우 물리적 스펙트럼이 달라도 같은 색으로 지각됩니다. 색을 재현할 때는 SPD 자체보다 표준화된 지각 좌표가 실용적입니다.
분광 에너지가 세 수용체 자극과 색 지각으로 이어지는 과정입니다.
.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
.. _colorspaces:
***********
Colorspaces
***********
'Color' is a very complex concept and depends on physics, chemistry and
biology. Just because you have three numbers that describe the 'red',
'green' and 'blue' components of the color of a pixel does not mean that
you can accurately display that color. A colorspace defines what it
actually *means* to have an RGB value of e.g. (255, 0, 0). That is,
which color should be reproduced on the screen in a perfectly calibrated
environment.
In order to do that we first need to have a good definition of color,
i.e. some way to uniquely and unambiguously define a color so that
someone else can reproduce it. Human color vision is trichromatic since
the human eye has color receptors that are sensitive to three different
wavelengths of light. Hence the need to use three numbers to describe
color. Be glad you are not a mantis shrimp as those are sensitive to 12
different wavelengths, so instead of RGB we would be using the
ABCDEFGHIJKL colorspace...
Color exists only in the eye and brain and is the result of how strongly
color receptors are stimulated. This is based on the Spectral Power
Distribution (SPD) which is a graph showing the intensity (radiant
power) of the light at wavelengths covering the visible spectrum as it
enters the eye. The science of colorimetry is about the relationship
between the SPD and color as perceived by the human brain.
Since the human eye has only three color receptors it is perfectly
possible that different SPDs will result in the same stimulation of
those receptors and are perceived as the same color, even though the SPD
of the light is different.
CIE XYZ와 CIE xyY
37-651920년대의 색 일치 실험은 SPD와 지각 색의 관계를 측정했고, 그 결과 CIE 1931 표준이 사람의 색 지각을 모델링하는 분광 가중 함수를 정의했습니다.
이 함수들로 SPD에 대한 세 수용체 자극을 계산하고 수학적으로 변환하면 CIE XYZ 삼자극값 X, Y, Z를 얻습니다. 세 값은 [0,1] 범위에서 사람이 지각하는 색을 모호함 없이 나타냅니다.
CIE XYZ의 대문자 Y는 휘도에 해당합니다. 정규화한 CIE xyY에서는 `x=X/(X+Y+Z)`, `y=Y/(X+Y+Z)`로 색도 좌표를 만들고 휘도 Y를 별도로 유지합니다.
소문자 x와 y는 CIE xyY 색도이고, 대문자 X와 Y는 CIE XYZ 성분입니다. 특히 소문자 y 자체는 휘도가 아닙니다. 실무적으로 x와 y가 색을, 대문자 Y가 휘도를 정한다는 점을 기억하면 됩니다.
비슷한 기호가 나타내는 공간과 역할을 구분합니다.
In the 1920s experiments were devised to determine the relationship
between SPDs and the perceived color and that resulted in the CIE 1931
standard that defines spectral weighting functions that model the
perception of color. Specifically that standard defines functions that
can take an SPD and calculate the stimulus for each color receptor.
After some further mathematical transforms these stimuli are known as
the *CIE XYZ tristimulus* values and these X, Y and Z values describe a
color as perceived by a human unambiguously. These X, Y and Z values are
all in the range [0…1].
The Y value in the CIE XYZ colorspace corresponds to luminance. Often
the CIE XYZ colorspace is transformed to the normalized CIE xyY
colorspace:
x = X / (X + Y + Z)
y = Y / (X + Y + Z)
The x and y values are the chromaticity coordinates and can be used to
define a color without the luminance component Y. It is very confusing
to have such similar names for these colorspaces. Just be aware that if
colors are specified with lower case 'x' and 'y', then the CIE xyY
colorspace is used. Upper case 'X' and 'Y' refer to the CIE XYZ
colorspace. Also, y has nothing to do with luminance. Together x and y
specify a color, and Y the luminance. That is really all you need to
remember from a practical point of view. At the end of this section you
will find reading resources that go into much more detail if you are
interested.
원색, 흰색 기준과 변환 행렬
66-90모니터와 TV는 서로 다른 세 파장의 빛을 내고 그 조합으로 눈의 색 수용체를 자극합니다. 역사적으로는 디스플레이의 빨강·초록·파랑 형광체가 이 파장을 정했으며, 이 세 원색이 색공간 정의의 일부입니다.
디스플레이 기술마다 적합한 원색이 달라 여러 색공간이 생겼습니다. 색공간은 일반적으로 CIE xyY의 x,y 좌표로 세 원색을 정의하고, 세 원색을 최대 출력으로 켰을 때의 색인 흰색 기준도 함께 지정합니다.
흰색 기준은 원색 사이의 상대 출력 또는 에너지를 결정합니다. 보통 주광에 가까운 CIE D65 광원을 사용합니다.
CIE XYZ는 색을 고유하게 식별하고, 새 RGB 색공간은 세 원색의 색도 좌표와 흰색 기준으로 정의됩니다. 이 값들로 CIE XYZ와 해당 RGB 사이를 변환하는 3x3 행렬을 구성할 수 있습니다.
원색과 흰색 기준에서 변환 행렬을 얻습니다.
A monitor or TV will reproduce colors by emitting light at three
different wavelengths, the combination of which will stimulate the color
receptors in the eye and thus cause the perception of color.
Historically these wavelengths were defined by the red, green and blue
phosphors used in the displays. These *color primaries* are part of what
defines a colorspace.
Different display devices will have different primaries and some
primaries are more suitable for some display technologies than others.
This has resulted in a variety of colorspaces that are used for
different display technologies or uses. To define a colorspace you need
to define the three color primaries (these are typically defined as x, y
chromaticity coordinates from the CIE xyY colorspace) but also the white
reference: that is the color obtained when all three primaries are at
maximum power. This determines the relative power or energy of the
primaries. This is usually chosen to be close to daylight which has been
defined as the CIE D65 Illuminant.
To recapitulate: the CIE XYZ colorspace uniquely identifies colors.
Other colorspaces are defined by three chromaticity coordinates defined
in the CIE xyY colorspace. Based on those a 3x3 matrix can be
constructed that transforms CIE XYZ colors to colors in the new
colorspace.
전달 함수와 Y'CbCr 인코딩
91-120CIE XYZ와 특정 원색에서 유도한 RGB는 선형 색공간입니다. 그러나 눈과 디스플레이의 반응은 선형이 아니므로 성분 값을 두 배로 해도 두 배 밝게 지각되지 않습니다.
색공간의 전달 함수는 선형 RGB 성분을 눈과 디스플레이의 비선형 반응에 더 가까운 비선형 성분으로 바꿉니다. 선형값은 RGB, 비선형값은 프라임 기호를 붙인 R'G'B'로 표기합니다.
일반 그래픽 색은 대체로 R'G'B'이지만 OpenGL은 선형 RGB를 사용합니다. OpenGL과 데이터를 주고받을 때는 선형값을 제공하거나 내장 기능으로 역전달 함수를 적용해야 합니다.
기호와 변환 단계가 서로 다른 값을 나타냅니다.
색공간의 마지막 변환 요소는 비선형 R'G'B'를 비선형 Y'CbCr로 바꾸는 함수이며 luma 계수가 이를 결정합니다. 한 색공간에서 여러 Y'CbCr 인코딩을 허용할 수도 있습니다.
눈은 색차보다 밝기 차이에 더 민감하므로 Y'와 CbCr로 분리하면 luma보다 chroma 정보를 더 적게 저장할 수 있습니다. Y'CbCr를 YCbCr나 YUV라고 부르는 경우가 많지만 엄밀한 표기는 아닙니다.
Y'CbCr는 독립 색공간이 아니라 특정 R'G'B' 색을 luma와 chroma로 부호화한 방식입니다. 따라서 Y'CbCr 데이터에도 원래 R'G'B'와 같은 기반 색공간이 연결되어야 합니다.
색도 정의에서 저장용 luma/chroma까지의 관계입니다.
Both the CIE XYZ and the RGB colorspace that are derived from the
specific chromaticity primaries are linear colorspaces. But neither the
eye, nor display technology is linear. Doubling the values of all
components in the linear colorspace will not be perceived as twice the
intensity of the color. So each colorspace also defines a transfer
function that takes a linear color component value and transforms it to
the non-linear component value, which is a closer match to the
non-linear performance of both the eye and displays. Linear component
values are denoted RGB, non-linear are denoted as R'G'B'. In general
colors used in graphics are all R'G'B', except in openGL which uses
linear RGB. Special care should be taken when dealing with openGL to
provide linear RGB colors or to use the built-in openGL support to apply
the inverse transfer function.
The final piece that defines a colorspace is a function that transforms
non-linear R'G'B' to non-linear Y'CbCr. This function is determined by
the so-called luma coefficients. There may be multiple possible Y'CbCr
encodings allowed for the same colorspace. Many encodings of color
prefer to use luma (Y') and chroma (CbCr) instead of R'G'B'. Since the
human eye is more sensitive to differences in luminance than in color
this encoding allows one to reduce the amount of color information
compared to the luma data. Note that the luma (Y') is unrelated to the Y
in the CIE XYZ colorspace. Also note that Y'CbCr is often called YCbCr
or YUV even though these are strictly speaking wrong.
Sometimes people confuse Y'CbCr as being a colorspace. This is not
correct, it is just an encoding of an R'G'B' color into luma and chroma
values. The underlying colorspace that is associated with the R'G'B'
color is also associated with the Y'CbCr color.
양자화, gamut과 정확한 해석
121-153마지막 단계는 RGB, R'G'B' 또는 Y'CbCr의 연속값을 정수 코드로 양자화하는 것입니다. CIE XYZ의 [0,1]은 사람이 지각할 수 있는 색을 설명하지만 다른 색공간으로 변환하면 일부 성분이 [0,1] 밖으로 나갈 수 있습니다.
바깥 값을 [0,1]로 클램프하면 그 색공간에서 재현할 수 없는 색이 사라집니다. 이 클램핑 경계가 색공간의 범위, 즉 gamut을 제한합니다.
정규화 범위를 8비트 [0,255] 또는 더 높은 비트 깊이의 코드로 옮기는 규칙이 양자화입니다. 양자화는 색공간 자체의 정의에는 포함되지 않습니다.
일반적인 전체·제한 범위와 존재하는 예외입니다.
색을 올바르게 해석하려면 양자화 범위, R'G'B'인지 Y'CbCr인지, 사용한 Y'CbCr 인코딩과 기반 색공간을 모두 알아야 합니다. 이 정보로 CIE XYZ를 계산한 뒤 실제 디스플레이 색공간으로 다시 매핑할 수 있습니다.
메타데이터 네 축을 결합해 표시 색을 얻습니다.
완전한 색공간 정의는 세 원색 색도, 흰색 기준 색도, 전달 함수와 R'G'B'를 Y'CbCr로 바꾸는 luma 계수로 구성됩니다. 실제 표준은 이 네 요소 중 일부만 정의하는 일이 많아 다른 표준을 조합해야 하고, 그 결과 표준 이름과 색공간 이름이 혼동되기도 합니다.
The final step is how the RGB, R'G'B' or Y'CbCr values are quantized.
The CIE XYZ colorspace where X, Y and Z are in the range [0…1] describes
all colors that humans can perceive, but the transform to another
colorspace will produce colors that are outside the [0…1] range. Once
clamped to the [0…1] range those colors can no longer be reproduced in
that colorspace. This clamping is what reduces the extent or gamut of
the colorspace. How the range of [0…1] is translated to integer values
in the range of [0…255] (or higher, depending on the color depth) is
called the quantization. This is *not* part of the colorspace
definition. In practice RGB or R'G'B' values are full range, i.e. they
use the full [0…255] range. Y'CbCr values on the other hand are limited
range with Y' using [16…235] and Cb and Cr using [16…240].
Unfortunately, in some cases limited range RGB is also used where the
components use the range [16…235]. And full range Y'CbCr also exists
using the [0…255] range.
In order to correctly interpret a color you need to know the
quantization range, whether it is R'G'B' or Y'CbCr, the used Y'CbCr
encoding and the colorspace. From that information you can calculate the
corresponding CIE XYZ color and map that again to whatever colorspace
your display device uses.
The colorspace definition itself consists of the three chromaticity
primaries, the white reference chromaticity, a transfer function and the
luma coefficients needed to transform R'G'B' to Y'CbCr. While some
colorspace standards correctly define all four, quite often the
colorspace standard only defines some, and you have to rely on other
standards for the missing pieces. The fact that colorspaces are often a
mix of different standards also led to very confusing naming conventions
where the name of a standard was used to name a colorspace when in fact
that standard was part of various other colorspaces as well.
추가 학습 자료
154-163더 깊이 공부하려면 Poynton의 자료는 비디오 엔지니어에게 실용적이고, `colimg`는 물리학·화학·생물학을 포함한 더 넓은 색 영상 범위를 다룹니다.
Bruce Lindbloom 웹사이트는 색공간 변환 수학에 특히 유용합니다. Wikipedia의 CIE 1931 색공간 문서 중 CIE xy 색도도와 CIE xyY 절도 좋은 입문 자료입니다.
원문이 추천하는 후속 읽기입니다.
If you want to read more about colors and colorspaces, then the
following resources are useful: :ref:`poynton` is a good practical
book for video engineers, :ref:`colimg` has a much broader scope and
describes many more aspects of color (physics, chemistry, biology,
etc.). The
`http://www.brucelindbloom.com <http://www.brucelindbloom.com>`__
website is an excellent resource, especially with respect to the
mathematics behind colorspace conversions. The wikipedia
`CIE 1931 colorspace <http://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space>`__
article is also very useful.
요약·해설
colorspaces.rst:1-163V4L2의 색 메타데이터를 올바르게 이해하기 위한 측색학 입문입니다. 픽셀 숫자만으로는 색을 결정할 수 없으며 원색·흰색·전달 함수·Y'CbCr 행렬과 별도 양자화 범위를 함께 알아야 디스플레이 색으로 정확히 변환할 수 있습니다.