chapter 2 transformations
TRANSCRIPT
-
7/30/2019 Chapter 2 Transformations
1/34
24
Chapter 2 Colour Spaces and Transformation
Algorithms
Colour Spaces and Transformation Algorithms
2.1 Introduction
In this chapter the Red-Green-Blue (RGB) colour space will be presented and the
transformation algorithms to alternative colour spaces will be described. Colour spaces can be
grouped into their applications and can be categorised as follows:
For display technology, a model suited to display a diversity of colour based onmixtures of light intensities to produce a range, orgamut, of hues.
For printed matter where pigments are combined together to generate a diversity of
colours.
For television technology where the priority is minimising the bandwidth and
maintaining backward compatibility with black and white (B&W) TV sets.
For artists who derive the way mind processes colour into perceptual colour models
where the elements of colour (hue, saturation and lightness) can be separated.
In industry that needs to standardise colour in order to be uniform when describing or
matching colour.
2.2 The RGB colour cube
The RGB colour model is primarily used in colour Cathode Ray Tube (CRT) monitors, raster
graphics devices and colour cameras. It is by far the most common used technology for
-
7/30/2019 Chapter 2 Transformations
2/34
25
computer monitors. The RGB primaries are additive, which means that individual contributions
of each primary are added for the creation of a new colour via the modulation of intensities of
light. The model is based on the tristimulus theory of vision and is a hardware-oriented model.This model employs a Cartesian coordinate system to give the location of every colour
combination. It can be represented using a normalised colour cube as depicted in Figure 2.1b.
Achromatic pixels lie on the line that extends from Black (0,0,0) to White (1,1,1), which is
known as the grey-scale line. Equal contributions ofR, G and B ( BGR == ) will always
produce an achromatic, or colourless, pixel. Any pixels falling out of the grey-scale line are
known as chromatic, or coloured, pixels. The six coloured corners of the cube in Figure 2.1b
show the primary colours Red (1,0,0), Green (0,1,0) and Blue (0,0,1), whilst the complementary
colours are Yellow (1,1,0), Cyan (0,1,1) and Magenta (1,0,1). Figure 2.1b also contains an
inner cube, 50% smaller than the external, which shows how colours get darker as they are
mixed with equal amounts of black and white and move towards point (0,0,0). Figures 2.1a and
2.1c illustrate what the outer cover or skin of each individual cube would look like. These
covers are also projected and rotated as viewed from point (1,1,1) towards (0,0,0). It is useful to
see that a hexagon has been generated which is the basis of the perceptually oriented colour
systems described in Section 2.3.3.
Figure 2.1: The RGB colour cube including its surrounding skins for the outer shell a) and
inner shell c) cubes shown in b)
Cyan (0,1,1)
Green (0,1,0)
Yellow (1,1,0)
Blue (0,0,1)
Red (1,0,0)
White
(1,1,1)
Black
(0,0,0)
Magenta (1,0,1)
a) b) c)
-
7/30/2019 Chapter 2 Transformations
3/34
26
2.3 Conversions from RGB to alternative colour spaces
Before introducing the conversion from RGB to alternative colour spaces or models, the
terminology that will be used throughout the rest of the chapter to describe the individual
components of colour will be described [Poy99].
Hue: The apparent colour of light, which is determined by the dominant wavelength as
perceived by the observer. It represents the redness, greenness and blueness,
depending on the relative mixtures and it is given as an angle 0 to 360.
Saturation: Is the purity of the colour or the proportion of white contained in the colour. Lightness: Is the amount of energy an observer perceives from a light source (self-
luminous objects).
Value/Brightness: Is the amount of black contained in a colour. The colour with the
highest intensity determines the amount of black. 100% would therefore be the
brightest colour containing no black, 0% would be black (reflecting objects).
Intensity: The total light across all frequencies, that is a measure over some interval of
the electromagnetic spectrum of the flow of power that is radiated from, or incident on
a surface.
Luminance: According to CIE [CIE86] it is a radiant power weighted by a spectral
sensitivity function that is characteristic of human vision.
2.3.1 RGB to television colour spaces
These colour spaces are widely used for the broadcast of TV signals throughout the world.When colour TV was first introduced, reduction of bandwidth and backward compatibility with
B&W TV sets was a very significant consideration. The human eye is far more insensitive to
colour changes than changes in luminance [Hea94], this enables the chrominance bandwidth to
be significantly smaller than that for the luminance. There are 3 colour spaces employed in TV:
YIQ, YUV and YCrCb. The Ycomponent is the luminance that is used in B&W television sets.
Also, two chrominance components are contained based on colour difference signals: R-G (i.e.
Red Green) and B-Y (i.e. Blue Yellow), which are two of three colour difference signals
existing, the third can be derived from the other two. TV colour spaces present advantages in
-
7/30/2019 Chapter 2 Transformations
4/34
27
the sense that the transformation needed to obtain them are simple and a separation of
luminance and colour can therefore be obtained and used without being correlated.
2.3.1.1 RGB to YIQ
This colour space is the basis of the National Television System Committee (NTSC) colour
broadcasting TV signal coding system used in countries such as Canada, US, Mexico and
Japan. It decouples the luminance channel Y from the chrominance channels Iand Q, which
convey the required information on hue and saturation of the colours. I is known as the In-
Phase signal and operates in the orange/cyan region whilst Q, the Quadrature operates in the
green/magenta region. The steps involved making a transformation from RGB to YIQ is as
described next [Wu96].
The Luminance component Yis obtained giving individual weights toR, G andB based on how
they are perceived by a human observer and is given by:
BGRY 1144.05866.02989.0 ++= (2.1)
In order not to overload the transmitter with the modulated colour difference signals when they
are added to the luminance signal, an amplitude reduction is done and labelled Uand Vsignals
(i.e. weighted colour difference signals):
)(493.0 YBU = (2.2)
)(877.0 YRV = (2.3)
To minimise the bandwidths of the quadrature-modulated signals, U and V are not directly
modulated on to the blue and red sub-carrier phases. Instead they are advanced by 33 and two
further signals are obtained,Iand Q:
= 33sin33cos UVI (2.4)
+= 33cos33sin UVQ (2.5)
-
7/30/2019 Chapter 2 Transformations
5/34
28
By directly combining Equations (2.1) to (2.5) the following results will be obtained:
BGRYBYRI 3218.02741.05959.0)(27.0)(74.0 == (2.6)BGRYBYRQ 3113.05227.02113.0)(41.0)(48.0 +=+= (2.7)
Placing Y,Iand Q in a matrix form, yields [Ber87]:
=
B
G
R
Q
I
Y
*
311.0523.0211.0
313.0274.0596.0
114.0587.0299.0
(2.8)
YIQ can be transformed into an IHS (see Section 2.3.3.1) or analogous spaces for diverse
colour image processing applications [Yan96] obtaining Hue (H) and Saturation (S). This is
done by using the next cartesian to polar conversion equations:
)/arctan( IQHIQ = (2.9)
22 QISIQ += (2.10)
2.3.1.2 RGB to YUV
YUV is the basic colour space used for Phase Alternating Line (PAL) and Sequential Colours
with Memory (SECAM) TV broadcasting in countries such as United Kingdom, Germany,
Brazil, France, etc [Rob97]. Yis the luminance channel and is obtained as in equation (2.1). U
and Vare the chrominance components calculated from the colour difference signals (B-Y) and(R-Y) and are the same as for YIQ that were obtained using Equations (2.2) and (2.3):
BGRYBU 437.0289.0147.0)(493.0 +== (2.11)
BGRYRV 100.0515.0615.0)(877.0 == (2.12)
Rearranging and defining Y, Uand Vin a matrix form yields:
-
7/30/2019 Chapter 2 Transformations
6/34
29
=
B
G
R
V
U
Y
*
100.0515.0615.0
437.0289.0147.0
114.0587.0299.0
(2.13)
As with YIQ, YUV can be transformed into a pseudo-IHS colour space obtaining Hue Hand
Saturation Sby using the following cartesian to polar conversion equations [For98]:
)/arctan( UVHUV = (2.14)
22 VUSUV += (2.15)
2.3.1.3 RGB to YCrCb
This is an independent coding system, which is appropriate for digital coding TV images. It
contains three components, the luminance Y that is obtained using equation (2.1), and the
chromatic information divided in Colour-Red Cr and Colour-Blue Cb are obtained using the
following equations [Kas92]:
)(564.0 YBCb = (2.16)
)(713.0 YRCr = (2.17)
Using equation (2.1) with equations (2.16) and (2.17) gives:
GGRCr 0816.04182.05.0 = (2.18)
BGRCb 5.03308.01686.0 += (2.19)
Defining the results for YCrCb in a matrix form yields:
=
B
G
R
C
C
Y
b
r *
5.0331.0169.0
082.0418.05.0
114.0587.0299.0
(2.20)
-
7/30/2019 Chapter 2 Transformations
7/34
30
An alternative implementation used by Altera [Alt97] uses slightly different matrix values
when converting gamma-corrected RGB data to YCrCb. This new set of constants is used to
provide a more natural image suited for the new TV sets with new phosphors coatings on theCRT. This variation is also considered in our design and is the following (including the
conversion to polar coordinates):
+
=
128
128
16
*
439.0291.0148.0
071.0368.0439.0
098.0504.0257.0
B
G
R
C
C
Y
b
r (2.21)
)/arctan( rbCrCb CCH = (2.21a)
22
brCrCb CCS += (2.21b)
2.3.2 RGB to hardcopy oriented colour spaces
Here colour spaces used for the creation of colour hardcopy or printed matter is considered.
Applications for this colour model include colour printers (ink-jet and lasers.), newspapers,
magazines, books, etc.
2.3.2.1 RGB to CMY
Cyan C, Magenta Mand Yellow Yare the complements of Red, Green and Blue respectively.
They are considered to be subtractive colours as they remove colour from white light, instead of
adding to brightness. Mixing equal proportions of pigments will give the following colours:
yellow and cyan will produce green, cyan and magenta will produce blue, magenta and yellow
will produce red and all mixed together will give black. One main application is for hardcopy
devices that deposit coloured pigments on paper.
The simplest matrix representation for this colour space is [For98]:
-
7/30/2019 Chapter 2 Transformations
8/34
31
=
B
G
R
Y
M
C
1
1
1
(2.22)
A variant of this colour model includes blackKand is known as the Cyan-Magenta-Yellow-
Black CMYK colour space that is widely used by many colour printers. The reason for
including black is to provide a rich dark black that otherwise cannot be obtained by mixing
equal amounts ofC,Mand Yon their own.
2.3.3 RGB to perceptually oriented colour models
The perceptually oriented colour models are basically used in computer graphics [Fol90] and
therefore are also known as computer graphics colour spaces or computer generated colour
models. These separate colour information from the luminance obtaining three parameters,
namely hue, saturation and value. An advantage of these colour spaces is that they closely
relate on how humans perceive colours and this is demonstrated in Figure 2.2. When colours
have a value V=1 and saturation S=1 they are said to be pure. When a pure colour is mixed
with white alone its saturation is decreased and a tint of that particular colour is obtained (e.g.
pink is an unsaturated red). If the colour is mixed with black only, it makes it darker and a
shade is created. Equal proportions of black and white (grey) mixed with a pure colour produce
a tone shown in the middle of the triangle on Figure 2.2.
Figure 2.2: Artist visualisation of colours (red cross-section)
Black
White
VVALUE
SSATURATION
Shad
es
Tints
Pure Hue point,
with no contents
of black or white.
S=1, V=1
Tones
-
7/30/2019 Chapter 2 Transformations
9/34
32
For the use in computer graphics and colour image processing applications the individual
components of these colour models can be visualised in Figure 2.3. Saturation S gives an
indication of the purity of the colour. The further out from the centre, the more pure (saturated)the colour will be. To describe colour, Hue His described as an angle from 0 to 360, where
Red is represented by 0, Green by 120 and Blue by 240. Moving the circle upwards would
make the hues lighter and moving the circle downwards darker. This component is shown in
Figure 2.3 and is given different names depending on the colour space employed, e.g.
LuminanceL, Value V, BrightnessB or IntensityI.
Figure 2.3: Perceptually oriented colour models
2.3.3.1 RGB to IHS
Known as the Intensity I, Hue H, Saturation Scolour model. It was seen in Section 2.2 thatRGB is defined with respect to a colour cube. The IHS model is defined with respect to a
colour triangle, as seen in Figure 2.4. The vectorOPis related to the intensity, equivalent to the
grey-scale line of the RGB colour cube. The triangle with vertices atR, G andB axes are known
as the Maxwell triangle [Wys00]. The intersection point p with the OPvector determines the
Hue Hand Saturation S. Hue is derived in them same way for all perceptually colour spaces
and is the most computational demanding operation of all.
Saturation Luminance (L), Value (V),
Brightness (B), Intensity (I)
Hue
Dark
Light
-
7/30/2019 Chapter 2 Transformations
10/34
33
Several solutions on obtaining H will be presented next based on the results published by
diverse authors. Each of these were carefully analysed and evaluated in order to pick the one
best suited for hardware realisation.
Figure 2.4: The IHS colour model and the Maxwell triangle
It can be shown [Str87] [Led90] that one of the first derivations ofHfor perceptually oriented
colour models can be represented by:
-
7/30/2019 Chapter 2 Transformations
11/34
34
existent when one of the values ofR, G orB are unequal. Therefore, a pixel having BGR ==
would contain no hue value and would be considered achromatic.
Figure 2.5: Procedure to obtain Hue for perceptually oriented colour spaces using
trigonometric functions
Bajon [Baj86] proposed a method to obtain Hwithout the use of trigonometric functions. If a
pixel is chromatic, the minimum of the RGB components is obtained. This minimum will give
an indication as to where Hlies and three outcomes are possible (refer to the colour circle in
Figure 2.3):
1. If B=min the resulting colour is between magenta and yellow or between 300 and
60 in the colour circle.
2. If R=min the resulting colour is between yellow and cyan or between 60 and 180 in
the colour circle.
3. If G=min the resulting colour is between cyan and magenta or between 180 and 300
in the colour circle.
Start R=G=B ?
G>=B andR>B ?
H5
3tan
13
R B( )
R G( ) B G( )+
+:=
G>R ?
Is B minimum?
Is R minimum?
G is minimum
His undefined(achromatic pixel)
NextPixel
N
Y
Y
Y
N
N
H
3tan
13
G R( )G B( ) R B( )+
+:=
H tan1
3B G( )
B R( ) G R( )+
+:=
-
7/30/2019 Chapter 2 Transformations
12/34
35
The procedure to obtain Hue without using trigonometric functions is illustrated in Figure 2.6.
Figure 2.6: Procedure to obtain Hue for perceptually oriented colour spaces without the
use of trigonometric functions
The value forIis obtained averaging the individual contributions ofR, G andB as shown:
BGRI3
1
3
1
3
1 ++= (2.24)
And finally, the saturation component is obtained as follows:
BGR
BGRminS
++= ),,(31 (2.25)
2.3.3.2 RGB to HSV
This is the Hue (H), Saturation (S) and Value (V) colour model. It is also known as the single
cone colour model or as Smiths [Smi78] HSV model. Sometimes this model is also known as
Start R=G=B ?
min(R,G,B)=B ?
min(R,G,B)
=R ?
Is B minimum?
Is R minimum?
G is minimum
His undefined(achromatic pixel)
NextPixel
Y
Y
Y
HG B( )
3 R G+ 2B( ):=
HB R( )
3 G B+ 2R( )
1
3+:=
HR G( )
3 R B+ 2 G( )
2
3+:=
N
N
N
-
7/30/2019 Chapter 2 Transformations
13/34
36
the HSB, with B for brightness instead of using V. The set of coordinates for this colour model
is cylindrical, and a hexcone is defined within this space as observed in Figure 2.7.
Figure 2.7: The HSV hexcone colour model
Value runs from black (bottom) to white (top) along the centre of the hexcone, this is similar to
the diametrical grey-scale line for the RGB colour cube. Hue is measured as an angle ranging
from 0 to 360 with red at 0, yellow at 60, green at 120, cyan at 180, blue at 240 and
magenta at 300. Saturation is a ratio ranging from 0 (Vaxis) to 1. The top of the HSV hexcone
can be seen as a projection along the principal diagonal of the RGB cube looking from white to
black (see Figure 2.1a). Achromatic colour is defined as having S= 0 and undefinedH.
Hue can be calculated as described in Section 2.3.3.1. A more generalised and simpler method
of obtaining H for perceptually oriented colour models was proposed by Levkowitz et al.
[Lev92] [Lev93] and will be described next. It divides the colour into 6 sectors (see Equation2.26) each labelled k, ranging for 0 to 5 according to the dominant wavelength of the Hue. It
then obtains the Hue fraction sector offset )(cf (see Equation 2.27) depending on whether the
colour is primary (when )(ck is even) or complementary (when )(ck is odd). It should be
observed that is necessary at this point to sort the RGB values to obtain min, mid and max
respectively. Finally, Hue is scaled (Equation 2.28) so it can give a value between 0 and 360.
Value
S
H
black (0)
white (1)
0o
60o120o
180o
240o 300o
-
7/30/2019 Chapter 2 Transformations
14/34
37
>>>>
>>
=
GreenlowestGBRif
BluehighestGRBif
RedlowestRGBifGreenhighestRBGif
BluelowestBRGif
RedhighestBGRif
ck
5
4
32
1
0
)( (2.26)
=
oddisckifcc
cc
evenisckifcc
cc
cf
)()min()max(
)mid(-)max(
)()min()max(
)min()(mid
)( (2.27)
))()((*60)( cfckcHue += (2.28)
Value Vfor HSV is obtained as follows:
},,min{min BGR= , },,max{max BGR= (2.29)
max=V (2.30)
Saturation Sfor HSV will be obtained for chromatic pixels [Bur 89] as shown in Figure 2.8.
Figure 2.8: Obtaining Saturation for HSV
k=0
k=1k=2
k=3
k=4 k=5
0
60120
180
240 300
Start max = min ?
(achromatic pixel)
His undefined
S= 0
Finish
Y
Smax min
max:=
N
-
7/30/2019 Chapter 2 Transformations
15/34
38
2.3.3.3 RGB to HLS
Gerald Murch at Tektronix [Tek90] developed the Hue (H), Luminance (L) and Saturation (S)
colour space. An advantage of this colour model is that it decouples the colour information
from the Luminance permitting individual processing of the channels. Hue, Luminance and
Saturation are defined by a double-hexcone obtained by rotating and projecting the RGB colour
cube as shown in Figure 2.9.
Figure 2.9: The HLS double-hexcone colour model
Hue is an angle going from 0 to 360 as for the HSV model. Luminance extends from 0
(black) to 1 (white), where the centre line in the double-hexcone is the grey-scale line.
Saturation is also a ratio of how much white is contained in a colour. Grey-levels in this model
have S= 0, and fully saturated Hues can be found at S= 1 andL = 0.5. For this colour model,
the Hue is also calculated as described in the previous two sections. In order to obtain L the
average of the minimum and maximum values is obtained [Gla90] [Gol97]:
},,min{min BGR= , },,max{max BGR=
S
H
L
black (0)
white (1)
-
7/30/2019 Chapter 2 Transformations
16/34
39
2
minmax+=L (2.31)
To obtain S, first it has to be determined whether the pixel is achromatic or not. If the pixel is
coloured, it is then established if it belongs to the bottom or top half of the double-hexcone.
This is illustrated in Figure 2.10.
Figure 2.10: Obtaining Saturation for HLS
A major drawback of this model is that two colours of equal perceived brightness will have
different values ofL [San98].
2.3.4 RGB to uniform distributed colour models
These colour models are the basis of industrial colorimetry where a way of defining
colours based on coordinates is desired. In order to define a perceptually uniform colour
space based on the results of human colour matching, the Commission Internationale de
LEclairage (CIE) was created in 1931 [CIE86]. Since then, various revisions have
occurred in 1964, 1976, etc. Basically two spaces were defined whose spaces are
defined in terms of CIE tristimulus values with respect to a reference white point. The
Start max = min ?
(achromatic pixel)
His undefined
S= 0
Finish
Y
L
-
7/30/2019 Chapter 2 Transformations
17/34
40
CIELa*b* coordinate system recommended for the use under reflected light conditions,
and the CIELu*v* coordinate system recommended in additive light source conditions.
They are based on the idea of having a colour space in which perceived colour
differences would be recognised as equal by the human eye and will correspond to equal
Euclidean distances [Taj83].
To further illustrate this, a representation of the Hue, Saturation and Lightness
(explained in Section 2.3.3) within a 3-D perceptual colour space is shown in Figure
2.11. Were (a*, b*) correspond to coordinates of the CIEL*a*b* colour space and (u*, v*)
to CIEL*u*v*. Luminance L* is equal for both [Rob 88]. The bottom section of Figure
2.11 defines a colour using Cartesian coordinates and the top defines colours using polar
coordinates.
Figure 2.11: Hue, Saturation and Lightness representation within a 3D Euclidean
perceptual colour space
The CIE also defined 3 special supersaturated primaries, X, YandZ. They do not correspond
to real colours, but they do have the property that all real colours can be represented as positive
combinations of them. The CIEXYZ colour system was created based on these three primaries
to describe any colour. The Y component is the description of colour as a luminance
component. TheXandZgive the spectral weighting curves that have been standardised by CIE,
based on statistics from experiments involving human observers [Jac94]. The magnitudes of
these components are proportional to physical energy, but their spectral composition
a*/u*
b*/v*
L*
HS
Lightness
-
7/30/2019 Chapter 2 Transformations
18/34
41
corresponds to the colour matching characteristics of human vision. These values are obtained
by the matrix multiplication shown in Equation 2.32 [Wys00]:
=
B
G
R
Z
Y
X
*
950227.0119193.0019334.0
072169.0715160.0212671.0
180423.0357580.0412453.0
(2.32)
The American Society for Testing and Materials (ASTM) [ASTM96] standardises values ofX,
Y and Z for computing the colour of objects using the CIE system for several illuminant
conditions (e.g. Cis used for average daylight). Some of these values are shown in Table 2.1.
The value ofYhas been normalised to 100 for every case.
Illuminant Tristimulus Values
X Y Z
A 109.85 100.00 35.58
WF35 103.81 100.00 49.94
D50 96.45 100.00 82.49
D65 95.04 100.00 108.89
D93 89.74 100.00 130.77
C 98.07 100.00 118.23
Table 2.1: Tristimulus values ofX, Yand Zdepending on the illuminant for a white
reference point
2.3.4.1 RGB to CIExyY
This colour model is used to normalise the values ofXand Ydescribed in Section 2.3.4 giving
( )ZYXXx ++= and ( )ZYXYy ++= with Y as luminance. Sometimes to make the
diagram of the model easier to comprehend, it is useful to describe pure colour in the absence
of brightness. This gives a plane with pure colours with the values ofx and y acting as
coordinates generating point (x,y) in the chromaticity diagram shown in Figure 2.12.
The CIE chromaticity diagram of Figure 2.12 has several interesting properties that will be
mentioned next:
Any colour along P1 to P2 can be obtained by mixing appropriate amounts of P1 and
P2.
-
7/30/2019 Chapter 2 Transformations
19/34
42
Appropriate combinations of P3, P4 and P5 can generate any colour within the triangle
defined by P3, P4 and P5. Therefore P3, P4 and P5 could be R, G andB respectively to
have the RGB set of colours, also known as thegamut.
Proper combinations of P6 and P7 can generate white as long as the line crosses the
point defined as white in the chart.
By extending P6, which is the complement of P7 to the edge of the diagram, gives the
dominant wavelength of the colour (i.e. 480nm).
The line running from red to blue is known as the purple line. The colours along this
line are non-existent and therefore have no associated wavelengths.
Figure 2.12: The CIExyY chromaticity diagram properties
There is a drawback, however, usingx andy coordinates, which is of being non-uniform. Equal
geometric steps result in different perceptual steps in different regions of the space. To alleviate
this problem the new coordinates u and v were introduced. This produced a five fold
-
7/30/2019 Chapter 2 Transformations
20/34
43
improvement in uniformity [San98] and resulted in the CIEuvY chromaticity diagram.
Equations 2.34 and 2.35 are used to obtain uand v, respectively by normalising and weighting
the tristimulus valuesX, YandZ.
ZYX
Xu
315
4'
++= (2.34)
ZYX
Yv
315
9'
++= (2.35)
2.3.4.2 RGB to CIEL*a
*b
*
This colour model was specified in 1976 by CIE [CIE86]. For the CIEL*a
*b
*uniform colour
space,L* represents Lightness, whilst a
* and b* are the coordinates in the chromaticity diagram.
The value ofL*
is orthogonal to the (**
,ba ) plane described in Figure 2.11 and is based on the
cube root of the Luminance. This model is defined directly in terms of the XYZ tristimulus
(Equation 2.32). To obtain the values L*, a
* and b* the following equations are used [Pra91]
[Con97]:
16*1160
*
=
Y
YfL (2.36)
=
00
* 500Y
Yf
X
Xfa (2.37)
=
00
* 200Z
Zf
Y
Yfb (2.38)
Where,
=
008856.0116
16292.903008856.0
)(
3/1
xifx
xifxxf (2.40)
Here,X0, Y0 andZ0 are the coordinates of the white reference point, which varies depending on
the illuminant shown in Table 2.1; a*
denotes relative redness-greenness and b*
yellowness-
-
7/30/2019 Chapter 2 Transformations
21/34
44
blueness. If the colour difference of two sets ofL*a
*b
* coordinates (L*
0, a*
0, b*0) and (L
*1, a
*1,
b*1) is desired it can be obtained using Equation 2.40 and is known as the deltaEunits:
( ) ( ) ( )2*0*12*
0*1
2*0
*1
* bbaaLLELab ++= (2.40)
The polar forms of Hue H and Chroma C* are useful for some applications, they are compiled
as follows [Gon95]:
=
*
*
arctana
bH (2.41)
( ) ( )2*2** baC += (2.42)
2.3.4.3 RGB to CIEL*u
*v
*
CIEL*u
*v
*is used primarily for industries considering additive mixing for applications such as
colour displays, TV and lighting. The Lightness value L*
is again obtained as in Equation 2.36,
where the u* and v* coordinates are defined as follows [Rob86] [Str90]:
( )''13 0* uuLu = (2.43)
( )''13 0* vvLv = (2.44)
Where uand v are obtained as expressed in Equations 2.34 and 2.35, respectively and '0u and
'0v are the coordinates of the reference white point.
The equation to determine the perceptual colour difference between two luminous sources in
CIEL*u
*v
*, with points at (L
*0, u
*0, v
*0) and (L
*1, u
*1, v
*1) is:
( ) ( ) ( )2*0*12*
0*1
2*0
*1
* vvuuLLELab ++= (2.45)
The following equations are used to obtain polar coordinates (i.e. HueH and Chroma C*):
-
7/30/2019 Chapter 2 Transformations
22/34
45
=
*
*
arctanu
vH (2.46)
( ) ( )2*2** vuC += (2.47)
2.4 Generalisation of a conversion algorithm from RGB to an
alternative colour space
This generalisation contemplates the implementation in hardware where a structured and
uniform approach is desired. After carefully analysing all colour models transformations, a
series ofstages have been identified that cover all transformations described so far and are not
restricted to future implementations of other colour spaces. Each of these three stages contains
several scenarios, which are called cases and depending on the case, the operation is modified
to achieve the desired result. A brief description of the stages and cases for each transformation
are given in Table 2.2.
Stage 1 Stage 2 Stage 3Matrix Multiplication Functional Mapping Final Representation
Cases:
1. Weighted coefficient
matrix multiplication with
RGB.
2. Weighted coefficient
matrix multiplication with
sorted RGB, obtaining the
colour sextant k.
3. Weighted coefficient
matrix multiplication with
RGB and gamma
correction.
Cases:
1. Final expression is
obtained directly.
2. Conditional arithmetic
and intermediate variable
generation (e.g. ,, ).
3. Equation partitioning
(start solving an
expression, leaving the
remaining for Stage 3,Case 1).
Cases:
1. Equation partitioning
(finish solving the
partially generated
expression in Stage 2,
Case 3).
2. Obtaining further results
from final expressions in
Stage 2 (i.e. obtaining
polar coordinates).
Table 2.2: Generalisation stages for the universal colour transformation functions
The subsequent sections will detail 12 different representations, namely YIQ, YUV, YC rCb,
CMY, IHS, HSV, HLS, CIEXYZ, CIExyY, CIEuvY, CIEL*a*b* and CIEL*u*v*. The initial
aim of the work was to determine a generalised processing structure for all.
-
7/30/2019 Chapter 2 Transformations
23/34
46
Stage 1
This stage is known as the Matrix Multiplication (MM) stage. For the majority of thetransformations, a coefficient matrix multiplication is needed to give weighted values forR, G
andB. For those conversions that do not implicitly require a matrix multiplication (e.g. CMY
and HSV), one was provided in order to have a uniform structure for Stage 1. In this way by
only changing the values of the coefficients in the matrix all transformations can be included.
Second, a variation for transformations to perceptually oriented colour models where a matrix
multiplication with sorted values ofR, G andB to obtain a min, midand max is required and is
also considered in this first stage. Finally, for perceptually oriented colour models, a colour
sextant khas to be identified and included as described in Equation 2.24. In summary, Stage 1
consists of scalar multiplier with weighted values, an RGB sorter and a means of obtaining the
value for the colour sextant k. The following three cases have been identified for Stage 1:
1. A floating-point matrix multiplication to produce weighted values forR, G andB. The
size of the matrix is always 33 and the range of its coefficients has been found to be
0.10.1 abc , where cab is the weighted coefficient at row a, column b.
2. A 33 sorted matrix multiplication with coefficients also in the range 0.10.1 abc is used. For this case, a multiplication will be realised on the sorted values ofR, G, and
B, i.e. },,min{ BGRmin = , },,{mid BGRmid= and },,max{ BGRmax = . A value for
the colour sextant k, 50 k , will be obtained from the sorted values of RGB. These
sorted values will also be used in Stage 2.
3. After the 33 matrix multiplication has been performed with R, G and B, adding an
integer offset to the result is desired for gamma correction in colour spaces like YCrCb.
Stage 2
This stage is known as the Functional Mapping (FM) section. Its primary function is to simplify
whenever possible the transformations by means of reducing the number of bits needed to
generate a partial or full result. This is achieved by analysing the equations or algorithms
involved in the process of making the colour transformations. During this stage, non-
computational demanding operations like addition, subtraction, basic multiplication and
division will be performed. In addition, decision trees will be included for those colour
-
7/30/2019 Chapter 2 Transformations
24/34
47
transformations that require them, e.g. HSV and HLS. This stage sometimes works in
conjunction with Stage 3 to partition expressions in order to simplify the operations required to
obtain a result. The following 3 cases were identified for Stage 2:
1. In some cases, the colour transformation from RGB to an alternative colour model can
be determined by the matrix multiplication alone, thus final expressions will be
generated directly without further simplification.
2. Conditional arithmetic is a special case needed for some transformations, namely the
perceptually oriented colour models that use an if-then-else structure to generate
results. This decision is made based on the outcome of certain results obtained from
Stage 1. For instance, to obtain the Saturation S for the HLS colour model it is
important to know in which half of the double-hexcone the Luminance L lies (see
Figure 2.10).L is obtained from the matrix multiplication and by considering its most
significant bit is will give an indication on which half of the hexcone it lies on. In this
way the if-then-else (conditional arithmetic statement) can be implemented as follows:
if 07 =L then // if bit 7 ofL is zero, then 128
-
7/30/2019 Chapter 2 Transformations
25/34
48
Stage 2 generating a temporary result. Stage 3 will be waiting for the partial result
generated from Stage 2 to produce a final expression. As an example, suppose we wish
to obtain the Hue for a perceptually oriented colour model using equations 2.26 to 2.28when the dominant wavelength is green, i.e. 2=k . The equation that would therefore
be required is:
+=minmax
minmid60 kHue
Where min, mid and max are the sorted values for RGB respectively. This equation
could be split into two separate operations by introducing an intermediate variable
Htemp:
minmax
minmid
=tempH
Now, Stage 2 can solve Htemp and then pass this partial result to Stage 3, which will
obtain the final result )(60 tempHkHue += .
Stage 3
Stage 3 is called the Final Representation (FR) stage. This stage can act as an auxiliary section
to finish solving elaborate algorithms that have been partitioned in the previous stage. Also, it
can be used to implement functions that generate values based on the results generated in Stage
2. An example would be obtaining Hue oH and Chroma *C from a*
and b*
for the CIEL*a
*b
*
colour space. Three cases were identified for Stage 3 to cope will all transformations, these are:
1. Splitting or breaking up complex equations or algorithms which were partially solved
in Stage 2 generating a partial solution that will then be used by this stage to produce a
final result. To illustrate this, Hue (H) will be obtained for the HSV single-cone model
and the following pseudo-code will indicate the operations performed by each stage.
/* Stage 2: Partitioning the algorithm to obtainHtemp */
if even (k) then // check if primary wavelength is red, green or blue
-
7/30/2019 Chapter 2 Transformations
26/34
49
Htemp = (midmin) / (max min);
else // colour is yellow, cyan or magenta
Htemp = (max mid) / (max min)
/* Stage 3 UsingHtemp and kto finalise calculations, obtainingH*/H= 60 * (k+Htemp);
2. Obtaining further results from the ones obtained in Stage 2. This case is best suited to
obtain polar coordinates from rectangular coordinates for several colour models, e.g.
Hue (H) and Saturation (S) for YIQ can be obtained as shown in Equations 2.9 and
2.10.
Based on this analysis and considering Table 2.2, we will define the transformations from RGB
to 12 alternative colour spaces in Sections 2.4.1 to 2.4.12. The generalisation used is presentedas a table showing each of the three stages and the cases considered for each.X1, Y1 andZ1 are
used as identifiers in Stage 1 to avoid confusion withX, YandZused for the CIE-based colour
spaces.
2.4.1 RGB to YIQ generalised transformation
Stage 1Case 1
=
B
G
R
ccc
ccc
ccc
Z1
Y1
X1
333231
232221
131211
(Eq. 2.8)
Stage 2Case 1
Z1Q
Y1I
X1Y
===
(Eq. 2.8)
c11 = 0.299 c12 = 0.587 c13 = 0.114
c21 = 0.596 c22 = 0.274 c23 = 0.322
c31 = 0.211 c32 = 0.523 c33 = 0.312
Stage 3
Case 2
22
1)/(tan
QISaturation
IQHue
+=
= (Eqs. 2.9 & 2.10)
Observations: YIQ is an example of a straightforward implementation of the generalisation
procedure. First, in Stage 1, the valuesX1, Y1 and Z1 are obtained by multiplying each RGB
pixel by the weighted values c11 to c33. Second, in Stage 2, the final values are obtained directly
from the matrix multiplication alone. Last, in Stage 3, the polar coordinates are obtained from
the results obtained in Stage 2.
-
7/30/2019 Chapter 2 Transformations
27/34
50
2.4.2 RGB to YUV generalised transformation
Stage 1Case 1
=
B
G
R
ccc
ccc
ccc
Z1
Y1
X1
333231
232221
131211
(Eq. 2.13)
Stage 2Case 1
Z1V
Y1U
X1Y
===
(Eq. 2.13)
c11 = 0.299 c12 = 0.587 c13 = 0.114
c21 = 0.147 c22 = 0.289 c23 = 0.437
c31 = 0.615 c32 = 0.515 c33 = 0.100
Stage 3
Case 2
22
1)/(tan
VUSaturation
UVHue
+==
(Eqs. 2.14 & 2.15)
Observations: As for YIQ, this is a straightforward implementation of the generalisation
procedure. First, in Stage 1, the valuesX1, Y1 and Z1 are obtained by multiplying each RGB
pixel by the weighted values c11 to c33. Second, in Stage 2, the final values are obtained directly
from the matrix multiplication alone. Last, in Stage 3, the polar coordinates are obtained from
the results obtained in Stage 2.
2.4.3 RGB to YCrCb generalised transformation
Stage 1
Case 3
+
=
128
128
16
333231
232221
131211
B
G
R
ccc
ccc
ccc
Z1
Y1
X1
(Eq. 2.21)
Stage 2
Case 1
Z1C
Y1C
X1Y
b
r
==
=(Eq. 2.21)
c11 = 0.257 c12 = 0.504 c13 = 0.098
c21 = 0.439 c22 = 0.368 c23 = 0.071
c31 = 0.148 c32 = 0.291 c33 = 0.439
Stage 3
Case 2
22
1 )/(tan
br
rb
CCSaturation
CCHue
+=
=
(Eqs. 2.21a & 2.21b)
Observations: Of all the transformations considered, this is the only case were a gamma
correction is used in Stage 1. After the weighted values R, G and B are obtained, the gamma
correction values are added. The rest of the methodology is identical to the one described for
YIQ.
-
7/30/2019 Chapter 2 Transformations
28/34
51
2.4.4 RGB to CMY generalised transformation
Stage 1Case 1
=
B
G
R
ccc
ccc
ccc
Z1
Y1
X1
333231
232221
131211
(Eq. 2.22)
Stage 2Case 1
Z1Y
Y1M
X1C
==
=
255
255
255
(Eq. 2.22)
c11 = 1.0 c12 = 0.0 c13 = 0.0
c21 = 0.0 c22 = 1.0 c23 = 0.0
c31 = 0.0 c32 = 0.0 c33 = 1.0
Stage 3
Not Needed
Observations: Although a matrix multiplication is not needed for Stage 1, an identity matrix is
used to provide consistency with the generalisation procedure. Also, not all colour
transformations require Stage 3, as can be observed here.
2.4.5 RGB to IHS generalised transformation
Stage 1
Case 2
=
B
G
R
sort
max
mid
min
, Obtaining k(Eq. 2.26)
=
max
mid
min
ccc
ccc
ccc
Z1
Y1
X1
333231
232221
131211
(Eq. 2.24)
Stage 2
Case 2
maxmidmin
minmax
kmidmaxkminmid
++==
=
oddisif
evenisif
(Eqs. 2.27 & 2.25)
Case 1
25531
=
=
minS
X1I
(Eqs. 2.24 & 2.25)
Case 3
=tempH
c11 = 1 / 3 c12 = 1 / 3 c13 = 1 / 3
c21 = 0.0 c22 = 0.0 c23 = 0.0
c31 = 0.0 c32 = 0.0 c33 = 0.0
Stage 3
Case 1
60+= tempHkH (Eq. 2.28)
Observations: In Stage 1, a sorter is used on the individual RGB values to obtain the minimum
(min), medium (med) and maximum (max) values that will then be used to obtain X1, Y1 and
Z1. The values given for c11 to c33 are to obtain intensity Ifor Equation 2.24. This stage also
obtains the colour sextant kdescribed in Equation 2.26. Variables with Greek letters (e.g. ,
-
7/30/2019 Chapter 2 Transformations
29/34
52
and ) are introduced to indicate temporary variables used for simplifications in Stage 2. Hue is
obtained using Equations 2.26 to 2.28. To obtain , a conditional statement is implemented and
is based on the outcome of the colour sextant k(Equation 2.27). Since HueHis rather elaborate
to obtain, it has been partitioned into Stages 2 and 3. Case 3 of Stage 2 will be generating a
partial calculation ofH, namedHtemp, which will then be used by Stage 3 to get the final value
forH.
2.4.6 RGB to HSV(B) generalised transformation
Stage 1Case 2
=
B
G
R
sort
max
mid
min
, Obtaining k(Eq. 2.26)
=
max
mid
min
ccc
ccc
ccc
Z1
Y1
X1
333231
232221
131211
(Eq. 2.30)
Stage 2Cases 2
minmax
kmidmax
kminmid
=
=
oddisif
evenisif
(Eq. 2.27)
Case 1
255=
=
maxS
Z1V
(Eq. 2.30 & Fig. 2.8)
Case 3
=tempH
c11 = 0.0 c12 = 0.0 c13 = 0.0
c21 = 0.0 c22 = 0.0 c23 = 0.0
c31 = 0.0 c32 = 0.0 c33 = 1.0
Stage 3
Case 1
60*tempHkH += (Eq. 2.28)
Observations: The same observations made for the IHS generalisation in Section 2.4.5 also
apply here. The values given for c11 to c33 are for obtaining value Vfor Equation 2.30.
-
7/30/2019 Chapter 2 Transformations
30/34
53
2.4.7 RGB to HLS generalised transformation
Stage 1Case 2
=
B
G
R
sort
max
mid
min
, Obtaining k(Eq. 2.26)
=
max
mid
min
ccc
ccc
ccc
Z1
Y1
X1
333231
232221
131211
(Eq. 2.31)
Stage 2Case 2
-
7/30/2019 Chapter 2 Transformations
31/34
54
2.4.9 RGB to CIExyY generalised transformation
Stage 1Case 1
=
B
G
R
ccc
ccc
ccc
Z1
Y1
X1
333231
232221
131211
(Eq. 2.32)
Stage 2Case 2
Z1Y1X1 ++= (Sec. 2.3.4.1)Case 1
255
255
=
=
=
Y1y
X1x
Y1Y
(Sec. 2.3.4.1)
c11 = .412453 c12 = .35758 c13 = .180423
c21 = .212671 c22 = .71516 c23 = .072169c31 = .019334 c32 = .119193 c33 = .950227
Stage 3
Not Needed
Observations: The values ofx andy in Stage 2 are multiplied by 255 to generate values ranging
from 0 to 255. The multiplication could be ignored if normalised values from 0 to 1 were
desired.
2.4.10 RGB to CIEuv
Y generalised transformation
Stage 1
Case 1
=
B
G
R
ccc
ccc
ccc
Z1
Y1
X1
*
333231
232221
131211
(Eq. 2.32)
Stage 2
Case 2
Z1Y1X1
Y1
X1
315
9
4
++===
(Eqs. 2.34 & 2.35)
Case 1
255*'
255*'
=
=
=
v
u
Y1Y
(Eqs. 2.34 & 2.35)
c11 = .412453 c12 = .35758 c13 = .180423
c21 = .212671 c22 = .71516 c23 = .072169
c31 = .019334 c32 = .119193 c33 = .950227
Stage 3
Not Needed
Observations: Values 'u and 'v in Stage 2 are multiplied by 255 to span their range from 0 to
255. This multiplication could be ignored if normalised values from 0 to 1 were desired.
-
7/30/2019 Chapter 2 Transformations
32/34
55
2.4.11 RGB to CIEL*a
*b
*generalised transformation
Stage 1
Case 1
=
B
G
R
ccc
ccc
ccc
Z1
Y1
X1
*
333231
232221
131211
(Eq. 2.32)
Stage 2
Case 1
=
=
=
3/13/1
*
3/13/1
*
3/1
*
200
500
16116
nn
nn
n
Z
Z1
Y
Y1b
Y
Y1
X
X1a
Y
Y1L
(Eqs. 2.36 to 2.38)
c11 = .412453 c12 = .35758 c13 = .180423
c21 = .212671 c22 = .71516 c23 = .072169c31 = .019334 c32 = .119193 c33 = .950227
Stage 3
( )( ) ( )2*2*
**1
/tan
baChroma
abHue
+==
(Eqs. 2.41 & 2.42)
Observations: It should be noted that in Stage 2 only X1, Y1 and Z1 are variables originated
from Stage 1, while Xn, Yn andZn are constants and are the values for the white reference point
given in Table 2.1.
2.4.12 RGB to CIEL*
u*
v*
generalised transformation
Stage 1
Case 1
=
B
G
R
ccc
ccc
ccc
Z1
Y1
X1
*
333231
232221
131211
(Eq. 2.32)
Stage 2
Case 2
Z1Y1X1
Y1
X1
315
9
4
++===
(Eqs. 2.34 & 2.35)
Case 1
16116
3/1
*
=
nY
Y1L (Eq. 2.36)
Case 3
=
=
'0
*
'0
*
vv
uu
temp
temp
(Eqs. 2.43 & 2.44)
c11 = .412453 c12 = .35758 c13 = .180423
c21 = .212671 c22 = .71516 c23 = .072169
c31 = .019334 c32 = .119193 c33 = .950227
Stage 3
Case 1
***
***
13
13
temp
temp
vLv
uLu
=
=(Eqs. 2.43 & 2.44)
-
7/30/2019 Chapter 2 Transformations
33/34
56
Observations: The values of '0u and'0v in Stage 2 are the coordinates of the white reference
point for CIEuv
Y.
2.5 Maximum and minimum values for alternative colour spaces
It is important to know the range of values that each and every variable can take during the
transformation to alternative colour spaces. R, G andB are integers with values from 0 to 255
(8-bit). Testing every possible combination for RGB gives a total of 224
or 16.7 million colour
representations. With the speed of computers these days, it is now possible to check everycombination ofR, G andB to obtain the ranges that should be considered when designing the
hardware.
A program included in the CD-ROM was used to convert RGB values to all 12 alternative
colour spaces. It tests all possible combinations for RGB, whilst it monitors maximum and
minimum values for all variables. At the end, it obtains all the results presented in Table 2.3.
A series of considerations were made for obtaining these minimum and maximum values,
which are described here. An achromatic pixel contains no colour information and occurs only
when BGR == , or for perceptually oriented colour spaces when maxmin = . These pixels do
not contain hue or saturation information, i.e. 0,0 == SH . Several ranges of values are fixed
for all colour models, which are:
2550and2550,2550 BGR // RGB are always 8-bit values
2551and2550,2540 maxmidmin // If 255=min or 0=max anachromatic pixel is obtained 50 k // Colour sextant
Table 2.3 is colour coded and includes all variables needed for the generalisation described in
Sections 2.4.1 through 2.4.12 for the colour transformation procedure with their minimum and
maximum values. The coloured identifier in the first column reflects the final parameter to be
obtained. Every transformation obtains three parameters. These are generated either in Stage 2
or Stage 3, hence the colour in these two stages correspond to ranges of the desired parameter
-
7/30/2019 Chapter 2 Transformations
34/34
(i.e. The minimum and maximum values for parameterUin the YUV colour model will be
111.2 and 111.2 respectively). Whenever an X appears in the table, it indicates that particular
variable is not` utilised.
2.6 Conclusions
This chapter first looked at the conventional method of performing transformations from RGB
to alternative 12 colour models that form part of a colour system. These will be implemented in
hardware in Chapter 3 and include:
Hardware oriented systems based on TV: YIQ, YUV, and YCrCb.
Hardware oriented systems based on printing: CMY.
Perceptual user oriented systems: IHS, HSV, and HLS.
Perceptually oriented systems: CIEXYZ, CIExyY, CIEuvY. CIEL*a*b*, CIEL*u*v*.
Next a generalisation method was proposed based on a uniform structure that could handle the
diversity of transformation procedures and methodologies. It was finally determined that this
could be achieved by dividing the problem into 3 parts called stages. Each stage handles the
requirements to transform RGB into an alternative colour space using cases. Later, the
generalisation is presented as a series of tables indicating the operations that will be carried out
by every stage and case.
Finally this chapter gives the ranges of values (from minimum to maximum) that every
parameter and intermediate variable used in the generalisation will take.