Color Spaces and Image Adjustments
Color Spaces and Image Adjustments
Ole-Johan Skrede
08.03.2017
INF2310 - Digital Image Processing
Department of Informatics
The Faculty of Mathematics and Natural Sciences
University of Oslo
2
the color of the light from the sun
spectral exitance
The light from the sun can be modeled with the spectral exitance of a black surface (the
radiant exitance of a surface per unit wavelength)
2πhc2 1
M (λ) = { hc } .
λ5 exp λkT −1
where
∙ h ≈ 6.626 070 04 × 10−34 m2 kg s−1 is the Planck
constant.
∙ c = 299 792 458 m s−1 is the speed of light.
∙ λ [m] is the radiation wavelength.
∙ k ≈ 1.380 648 52 × 10−23 m2 kg s−2 K−1 is the
Boltzmann constant.
∙ T [K] is the surface temperature of the radiating Figure 1: Spectral exitance of a black body surface for different
body. temperatures.
4
spectral irradiance
The distance from the earth to the sun is about d ≈ 1.496 × 1011 m, and the radius of the
sun is about r ≈ 6.957 × 108 m. The radiation we measure at the top of the earth’s
atmosphere from a black body sphere is then given by the spectral irradiance
( r )2
E0 (λ) = M (λ) .
d
surface.
∙ A lot of radiation (especially in the UV
and IR wavelength ranges) are absorbed
by molecules such as H2 O and CO2 .
8
dispersion
9
light and color
∙ Achromatic light is light without color, grayscale etc. Characterized by its intensity.
∙ Chromatic light is the colors, and span a narrow band of the electromagnetic
spectrum
∙ Thre basic quantities determines chromatic light:
∙ Radiance: Total amount of energy from the light source. Measured in Watts [W]
∙ Luminance: The amount of energy an observer percieves. Measured in lumens [lm]
∙ Brightness: Analogue to the achromatic intensity. Subjective and difficult to measure.
10
the color of an object
∙ The color we percieve in an object is determined by the nature of the light reflected
by the object.
∙ Therefore, the color of an object is determined by
∙ The light hitting the object.
∙ How much light is reflected and absorbed.
∙ Or, in other words
∙ The spectral distribution of the incident light.
∙ The spectral distribution of the reflected light.
∙ The reflection properties are determined by
∙ Chemical pigments
∙ Physical surface structures
∙ Together, this determines what wavelengths are reflected, absorbed or transmitted.
∙ How we actually percieve color is complicated. Two complementary theories:
Trichromacy and Color opponency.
11
∙ Vegetation
∙ Green plants are green because of a
pigment called chlorophyll which
absorbs red and blue wavelengths.
∙ As chlorophylls degrade in the autumn,
hidden pigments of yellow xanthophylls
and orange beta-carotene are revealed.
∙ The sky (a) Absorbtion spectrum of chlorophyll
14
15
16
stage (or zone) theory
The brain combines information from each type of receptor to give rice to different color
perception. Modern theory of visual perception incorporates trichromatic theory and
opponence theory, in two stages. In summary, some percieved colours can be explained
as
∙ Blue light stimulates S more than green or red light, but M and L more weakly
∙ Blue-green light stimulates M moore than L, and S more strongly
∙ Green light stimulates M more than S and L
∙ Green-Yellow light stimulates both L and M equally strong, but S weakly
∙ Red light stimulates L much more than M, and S hardly at all
17
color description
some words and their meanings
All colors can be fully described by their ∙ The chromaticity determines both the
hue, saturation and some form of intensity, dominating wavelength and the
or brightness value. saturation of the color.
∙ Saturation: How saturated the color is ∙ For instance, different graylevels have
with white light, from a pure color (no the same chromaticity, but different
white) to fully saturated (white). intensity.
19
additive color mixing
20
subtractive color mixing
21
human color vision
22
color spaces
color models and color spaces
24
cie standard observer
X Y Z
x= ,y = ,z = ,
X +Y +Z X +Y +Z X +Y +Z
∙ Note that z = 1 − x − y
∙ This is often used to derive different color spaces.
Figure 18: The CIE 1931 xy color space chromaticity
∙ The chromaticity diagram on the left represent the diagram 1 .
∙ The straight line on the lower part is called the line of Green: 546.1 nm
purples, and have no monochromatic color equivalent. Blue: 435.8 nm
Purple and magenta do not exist in the rainbow (but
violet do).
∙ The line segment between two points contain all colors
that can be created with different mixtures of the two
colors at those points.
∙ Therefore a color space gamut is convex. E.g. a triangle if
it is built of three primary colors. Figure 19: The CIE 1931 RGB 1 .
https://commons.wikimedia.org/w/index.php?curid=7889718
27
rgb color model
Figure 21: Red, green and blue colors with different transparency (alpha). Note that when overlapping, blue is overlapping green which is overlapping red.
29
srgb color space
30
cie xyz to srgb transformation
The CIE XYZ tristimulus values must be normalized to the D65 white point (X = 0.9505,
Y = 1.0000, Z = 1.0890). Then compute a linear transform
Rlin 3.2406 −1.5372 −0.4986 X
Glin = −0.9689 1.8758 0.0415 Y
Blin 0.0557 −0.2040 1.0570 Z
Now, these values must be gamma-corrected before we get the final sRGB values
{
12.92Clinear , Clinear ≤ 0.0031308
Csrgb = 1/2.4
(1 + a)Clinear − a, Clinear > 0.0031308
where a = 0.055, for C ∈ {R, G, B}.
31
adobe rgb color space
K = 1 − max{R, G, B}
C = (1 − R − K)/(1 − K)
M = (1 − G − K)(1 − K)
Y = (1 − B − K)(1 − K)
Figure 24: 1 Collection of gamuts
https://commons.wikimedia.org/w/index.php?curid=32158329 33
device dependence
∙ RGB colors on a screen is dependent on the properties of the screen. That is, the
same image can look different on two different screens.
∙ This is also the case for CMYK: the same image printed on two different printers can
look completely different. The color is dependent on the printer, the printer ink, the
paper etc.
∙ There is not allways overlap between CMYK and RGB colors. The monitor can display
some colors that the printer cannot print, and vice versa.
∙ We say that RGB and CMYK are device dependent color models.
∙ CIEXYZ is an example of a model that is device independent.
∙ The number of stable, ”recognizable” colors on a monitor is actually quite small.
34
hue, saturation, intensity (hsi)
35
rgb to hsi
For R, G, B ∈ [0, 1]
{
θ B≤G
H=
360 − θ B>G
where1 { }
(R − G) + (R − B)
θ = arccos √ .
2 (R − G)2 + (R − G)(R − B)
Saturation is given by
3 min{R, G, B}
S =1− .
R+G+B
Intensity is given by
1
I=
(R + G + B).
3
Notice that H is not defined for R = G = B, and S is not defined when I = 0.
1 Remember to convert from radians to degrees. This also apply in the next slides.
36
hsi to rgb
H = H − 120 H = H − 240
( )
S cos H R = I(1 − S) R = 3I − (R + B)
R=I 1+ ( )
cos(60 − H) S cos H G = I(1 − S)
G=I 1+ ( )
G = 3I − (R + B) cos(60 − H) S cos H
B =I 1+
B = I(1 − S) B = 3I − (R + B) cos(60 − H)
37
hsv (hue, saturation, value and hsl (hue, saturation, lightness)
V = max{R, G, B}
1 (a) HSV cylinder
L = (max{R, G, B} + min{R, G, B})
2
∙ Saturation is also different
max{R, G, B} − min{R, G, B}
SHSV =
V
max{R, G, B} − min{R, G, B}
SHSL =
1 − |2L − 1|
Note that all values are in range [0, 1] except hue, which is in range [0, 360]
39
luminance and chrominance color model
40
yiq
∙ NTSC is the standard for TV and video in North America R, G, B, Y ∈ [0, 1],
and Japan, they use the system YIQ. I ∈ [−0.5957, 0.5957] and
∙ Y describes luminance, I and Q describes chrominance Q ∈ [−0.5226, 0.5226].
information
∙ RGB to YIQ
Y 0.299 0.587 0.114 R
I = 0.596 −0.274 −0.322 G
Q 0.211 −0.522 0.311 B
∙ YIQ to RGB
R 1 0.956 0.623 Y
G 1
= −0.272 −0.648 I
Figure 28: YIQ at Y = 0.5. Note that I and Q are
B 1 −1.105 0.705 Q scaled to [−1, 1].
41
ycbcr
42
color spaces, summary
43
digital color images
organization of color images
45
true color: component ordering
∙ Each image index consist of multiple channels, one for each color component.
∙ For RGB, one red channel, one green channel and one blue channel.
∙ If each channel is discretized into 8 bits (256 intensity values for red, green and
blue), we get (28 )3 = 224 = 16 777 216 different colors
1 Wilhelm Burger, Mark J. Burge, Principles of Digital Image Processing: Fundamental Techniques, 2010
46
example
47
red channel
48
green channel
49
blue channel
50
full example summary
52
red channel
53
green channel
54
blue channel
55
detail example summary
56
true color: packed ordering
1 Wilhelm Burger, Mark J. Burge, Principles of Digital Image Processing: Fundamental Techniques, 2010
57
packed ordering and memory layout
59
indexed color
1 Wilhelm Burger, Mark J. Burge, Principles of Digital Image Processing: Fundamental Techniques, 2010 60
color images and look up tables
∙ As we have seen, in true color, an RGB pixel can be stored in 24 bits (8 for each color).
∙ To reduce this size, we could e.g. assign 3 bits to each color.
∙ This would result in only 512 different possible colors, and a total of 9 bits ber pixel.
∙ A region with many nuances of a color would not loog good.
∙ It is certain that all 512 colors exist in the image.
∙ Alternatively, one could use 8 bits and a LUT.
∙ Each row in the table represent a 24 bit RGB color.
∙ The table consist of the 256 colors that best represent the image.
61
color quantization
62
uniform quantization algorithm
Convert each component c of the original RGB value independently and uniformly to the
new value ĉ { }
N
ĉ = floor c
N̂
Here c ∈ {r, g, b} and N is the number of intensity values in the respective
representation.
Example: 3 × 8 bit (N = 256) to a 3 : 3 : 2
Example: 3 × 12 bit (N = 212 = 4096) true packed 8 bit: 3 bits for red (N̂ = 8), 3 bits for
color image to 3 × 8 bit (N̂ = 28 = 256) value: green (N̂ = 8), and 2 bits for blue (N̂ = 4).
63
median-cut algorithm
This transforms a 24 bit true color image to 8 bit indexed color image.
1. Find the box in the RGB space that cover all colors present in the image.
2. Sort the colors in the box along the longest RGB dimension of the box. This is done
by computing the color histogram.
3. Split the box in two at the median in the sorted list.
4. Repeat step 2 and 3 for all boxes (including the new ones that you create). Repeat
until you have 256 boxes.
5. For each box, compute the mean RGB value in that box, and let this value represent
the value of the box.
6. Map each 3 × 8 bit RGB value in the original image to the index of the box which
value is the closest in the RGB space.
64
endianness and lut
A LUT is also prone to confusion in endianness. For instance, a LUT with 16 bit values and
a 5 : 6 : 5 bit packed RGB ordering, (from MSB to LSB) 1000010000010000 would be
interpreted differently. Let ”|” represent a byte delimeter, then we would have a:
Big endian interpretation Little endian interpretation
10000100 | 00010000 00010000 | 10000100
65
pseudo colors
66
how to choose the correct colormap
∙ Often, we want the colormap to be perceptually uniform: Equal steps in the data are
percieved as equal steps in the color space.
∙ The human brain percieves changes in lightness as changes in data better than
changes in hue.
∙ Up until recently, Matlab (until 2014) and Python’s Matplotlib (until 2.0 release) used
jet as the default colormap for data display1 .
∙ jet is a rainbow colormap that is not perceptually uniform.
Figure 35: A gradient of jet, and the lightness component of the CAM02-UCS colorspace.
(c) coolwarm (diverging) (d) viridis (sequential perceptual uniform) (new matplotlib default)
68
color graphics i
Figure 37: Example of global mean annual (mm/year) percipitation (notice the colormap).
(Source: https://data.giss.nasa.gov/impacts/agmipcf/)
69
fake colors
Using imaging from outside the visible spectrum and mapping it to RGB.
Example: NOAA (National Oceanic and Atmospheric Administration) satelites equipped
with a AVHRR (Advanced Very High Resolution Radiometer), an instrument sensing in the
visual and infrared part of the EM spectrum1 .
1 http://eoedu.belspo.be/en/satellites/noaa.htm
70
noaa avhrr example
1 http://www.ssd.noaa.gov/POES/COMP/
71
quantization and printing
grayscale printing
73
global threshold
74
dithering
Figure 42
75
ordered dithering
76
example of ordered dithering using d2
77
error diffusion dithering
79
color printing
81
component color histogram
82
histogram equalization in rgb
83
histogram equalization in hsi
84
histogram equalization example
85
low-pass filtering
(b) Left: RGB lowpass. Middle: Filtering I component and converting back to HSI. Right:
Difference between results.
Figure 52: Lena and RGB components.
86
laplace filtering
∙ We can make a graylevel image appear sharper by adding a scaled laplace of the
same image (previous lecture).
∙ RGB:
∙ Compute the laplace of each RGB component, and add it to the respective component.
∙ The color of each pixel is then influenced by the color of neighbouring pixels.
∙ HSI:
∙ Compute the laplace of the intensity channel, and add it to the intensity channel.
∙ The color is preserved, but the intensity near edges is changed.
87
color image thresholding
∙ For RGB, this corresponds to partition the RGB space into a boxes.
88
color image thresholding
We can do the same, but with an ellipse in RGB space in stead of a sphere.
1. Choose an arbitrary point in the multidimensional color-space as reference, e.g.
(R0 , G0 , B0 ) in RGB space.
2. Choose distance thresholds dR , dG , dB .
3. Compute the distance based on the reference point
√
(fR [x, y] − R0 ])2 (fG [x, y] − G0 ])2 (fB [x, y] − B0 ])2
d(x, y) = 2 + 2 +
dR dG d2B
∙ Transform to to HSI.
∙ Suppose that we want to segment parts
in an image
∙ with a certain hue
∙ and above some saturation threshold.
√
1
F = (gxx + gyy ) + (gxx − gyy ) cos(2θ) + 2gxx sin(2θ)
2
where ( )2 ( )2 ( )2
∂fR ∂fG ∂fB
gxx = + + ,
∂x ∂x ∂x
( )2 ( )2 ( )2
∂fR ∂fG ∂fB
gyy = + + ,
∂y ∂y ∂y
∂fR ∂fR ∂fR ∂fR ∂fR ∂fR
gxy = + + ,
∂x ∂y ∂x ∂y ∂x ∂y Figure 56: RGB edge detection. (1, 1): Original. (1, 2):
Gradient in RGB color vector space (F ). (2, 1):
and ( ) Gradients computed on per RGB component, and
1 2gxy then added. (2, 2): Difference between (1, 2) and (2, 1).
θ= arctan .
2 gxx − gyy
92
noise in color images
94