Professional Documents
Culture Documents
EECE253 05 ColorCorrection
EECE253 05 ColorCorrection
EECE253 05 ColorCorrection
Lecture Notes: Color Correction Richard Alan Peters II Department of Electrical Engineering and Computer Science Fall Semester 2011
. . . . . . . . .
This work is licensed under the Creative Commons Attribution-Noncommercial 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.
Color Images
Are constructed from three overlaid intensity maps. Each map represents the intensity of a different primary color. The actual hues of the primaries do not matter as long as they are distinct. The primaries are 3 vectors (or axes) that form a basis of the color space.
1999-2011 by Richard Alan Peters II 2
2011-09-21
Vector-Valued Pixels
Color Space
primary image colors red, green, and blue correspond to R,G, and B axes in color space. 8-bits of intensity resolution per color correspond to integers 0 through 255 on axes. no negative values color space is a cube in the first octant of 3-space. color space is discrete 2563 possible colors = 16,777,216 elements in cube.
2011-09-21
2011-09-21
2011-09-21
2011-09-21
2011-09-21
2011-09-21
2011-09-21
10
2011-09-21
11
2011-09-21
12
2011-09-21
13
RGB axes
2011-09-21
CMY axes
1999-2011 by Richard Alan Peters II 14
Color Correction
Global changes in the coloration of an image to alter its tint, its hues or the saturation of its colors with minimal changes to its luminant features
2011-09-21
16
original
David Peters, producer, and representatives of the IA, The International Alliance of Theatrical Stage Employees, Moving Picture Technicians, Artists and Allied Crafts, on the set of Frozen Impact (PorchLight Entertainment, 2003).
2011-09-21
17
red =2
2011-09-21
18
original
2011-09-21
19
red =0.5
original
2011-09-21
21
green =2
2011-09-21
22
original
2011-09-21
23
green =0.5
original
2011-09-21
25
blue =2
2011-09-21
26
original
2011-09-21
27
blue =0.5
Color Images
are represented by three bands (not uniquely) e.g., R, G, & B or L, a*, & b*.
Red Green Blue R G B Luminance a*-chroma b*-chroma L a* b*
2011-09-21
29
The brain transforms RGB into separate brightness and color channels (e.g., LHS).
brain photo receptors
30
2011-09-21
32
forms a triangle inside the color cube if c 255 or c 510, or a hexagon if 255 < c < 510. Every color on the planar surface is such that r + g + b = c. Therefore its value is c/3. It is on this equivalue plane that hue and saturation are computed.
2011-09-21 1999-2011 by Richard Alan Peters II
c=255, v=85
33
On the g = 0 face of the cube the triangle traces the line, r + b = 255.
2011-09-21
34
forms a triangle inside the color cube if c 255 or c 510, or a hexagon if 255 < c < 510. Every color on the planar surface is such that r + g + b = c. Therefore its value is c/3. It is on this equivalue plane that hue and saturation are computed.
2011-09-21 1999-2011 by Richard Alan Peters II
c=384, v=128
35
On the g = 0 face of the cube the hexagon traces the line, r + b = 383.
2011-09-21
36
2011-09-21
37
2011-09-21
38
2011-09-21
39
2011-09-21
40
+g +b (r + g0 + b0 ) r v0 = 1 3 0 s0 = p0 v 0
Color vector p0
Triangle: lies in plane R+G+B=(r0+g0+b0), intersects R, G, & B at r0+g0+b0, and contains p0.
v0 = v 0 s0 = s0
v 0 ], s0 } h0 = {[(r0 + g 0 + b0 ) r
41
2011-09-21
2011-09-21
42
2011-09-21
43
2011-09-21
44
2011-09-21
45
2011-09-21
46
2011-09-21
47
2011-09-21
48
2011-09-21
49
2011-09-21
50
2011-09-21
51
+g +b (r + g0 + b0 ) r v0 = 1 3 0 s0 = p0 v 0
Color vector p0
Triangle: lies in plane R+G+B=(r0+g0+b0), intersects R, G, & B at r0+g0+b0, and contains p0.
v0 = v 0 s0 = s0 v 0 ], s0 } h0 = {[(r0 + g 0 + b0 ) r
52
2011-09-21
2011-09-21
53
2011-09-21
54
2011-09-21
55
2011-09-21
56
2011-09-21
57
2011-09-21
58
2011-09-21
59
2011-09-21
60
2011-09-21
61
2011-09-21
62
2011-09-21
63
2011-09-21
64
2011-09-21
65
2011-09-21
66
2011-09-21
67
2011-09-21
68
2011-09-21
69
2011-09-21
70
2011-09-21
71
2011-09-21
72
2011-09-21
73
2011-09-21
74
2011-09-21
75
2011-09-21
76
2011-09-21
77
v0 = 1 3 c, or v0 = v 0 =
3 3
c.
p0
v0 s0
r0 - 1 3c . s0 = p 0 - v 0 = g 0 - 1 c 3 1 b0 - 3 c
2
r0 p 0 = g 0 . b0
2 2
1 1 s0 = s 0 = (r0 - 1 c + g c + b ) ( ) ( 0 0 3 3 3 c) .
2011-09-21
91 78
v0 = 1 3 c, or v0 = v 0 = r - c s0 = p 0 - v 0 = g - c . b - c
2
3 3
c.
v0
r0 p 0 = g 0 . b0
2 2
1 1 s0 = s 0 = (r0 - 1 c + g c + b ) ( ) ( 0 0 3 3 3 c) .
2011-09-21
79
v0 p0 s0
.
83 80
2011-09-21
v0 = 1 3 c, or v0 = v 0 =
where c = r0 + g0 + b0,
2
3 3
c,
v0
1 3 2 1 3 2
s0 = (r0 - c) + ( g 0 - c) + (b0 - c) ,
1 3
p0
s0
and
s0 x h0 = cos s0 x
-1
Usually, s0 is normalized to lie in the interval (0,1) and h0 is shifted to lie in (0,2).
2011-09-21
81
usually is normalized to lie between 0 and 1. The scale factor is the largest possible length of a saturation vector in the color cube. That vector lies in the triangle with vertices [r g b]T = [255 0 0] T, [0 255 0] T, and [0 0 255] T. There are 3 such vectors. One is s max = [ 255 0 0 ] - 1 3 [ 255 255 255 ] = [170 -85 -85 ] , which has length smax = s max 208.2066. Therefore, s0 is replaced by s0 smax.
2011-09-21 1999-2011 by Richard Alan Peters II
T T T
v0 p0 s0
82
[ s ] xyv
with respect to unit vectors x , y , and v , in the equivalue plane. + s sin ( h) y +0v . s = s cos ( h) x
2011-09-21 1999-2011 by Richard Alan Peters II 84
[ s ] xyv
This is s written as a linear x, y, with respect to unit vectors , combination of vectors x y, & v. and v , in the equivalue plane. + s sin ( h) y +0v . s = s cos ( h) x
2011-09-21
85
We need to find r0, g0, & b0.
86
[ s ]rgb = [ r0 g 0 b0 ]
[ s ]rgb = [ r0 g 0 b0 ] and
T [ s ] xyz = [ s cos ( h) s sin ( h) 0] but [ s ]rgb [ s ] xyz
2011-09-21
87
Then,
[ s ]rgb = A[ s ] xyv
] xyv + s sin ( h)[ y ] xyv + 0 [ v ] xyv = A s cos ( h)[ x ] xyv + s sin ( h) A[ y ] xyv + 0 A[ v ] xyv = s cos ( h) A[ x ]rgb + s sin ( h)[ y ]rgb + 0 [ v ]rgb . = s cos ( h)[ x
2011-09-21 1999-2011 by Richard Alan Peters II
88
So that,
1 0 0 ]rgb= A 0 , [ y ]rgb= A 1 , [ v ]rgb= A 0. [x
89
3 1 ]rgb = 1 [v 3 1
6 ]rgb = [x 6 2 -1 -1
2011-09-21
90
and
2 2 2
2 2
v0
0 sin ( h) 1 + 0 -1 0 2 sin h 1 . ( ) 2 1
3 1 3 1 1
p0
s0
Finally, [s]rgb must be shifted to the value vector to obtain the rgb color of p0: p 0 = [ p ]rgb=[ s ]rgb + [ v ]rgb , where s0 = [s]rgb and [v]rgb= v0 as def d. on slide 78.
2011-09-21 1999-2011 by Richard Alan Peters II 91
Saturation Adjustment
original
2011-09-21
92
Saturation Adjustment
saturation + 50%
2011-09-21
93
Saturation Adjustment
original
2011-09-21
94
Saturation Adjustment
saturation - 50%
2011-09-21
95
Hue Shifting
R Y G C B M
R Y G C B M
original
2011-09-21
96
Hue Shifting
R Y G C B M
Y G C B M R
hue + 60
2011-09-21
97
Hue Shifting
R Y G C B M
G C B M R Y
hue + 120
2011-09-21
98
Hue Shifting
R Y G C B M
C B M R Y G
hue + 180
2011-09-21
99
Hue Shifting
R Y G C B M
B M R Y G C
hue + 240
2011-09-21
100
Hue Shifting
R Y G C B M
M R Y G C B
hue + 300
2011-09-21
101
Hue Shifting
R Y G C B M
R Y G C B M
2011-09-21
102
Hue Shifting
R Y G C B M
R Y G C B M
original
2011-09-21
103
Hue Shifting
R Y G C B M
Y G C B M R
hue + 60
2011-09-21
104
Hue Shifting
R Y G C B M
G C B M R Y
hue + 120
2011-09-21
105
Hue Shifting
R Y G C B M
C B M R Y G
hue + 180
2011-09-21
106
Hue Shifting
R Y G C B M
B M R Y G C
hue + 240
2011-09-21
107
Hue Shifting
R Y G C B M
M R Y G C B
hue + 300
2011-09-21
108
Hue Shifting
R Y G C B M
R Y G C B M
2011-09-21
109
cyan
original
red
blue
magenta
2011-09-21
111
2011-09-21
112
2011-09-21
113
2011-09-21
114
2011-09-21
115
2011-09-21
116
Color Transformation
Assume J is a discolored version of image I such that J = [ I ]. If is linear then it is represented by a 33 matrix, A:
a11 a12 a13 A = a21 a22 a23 . a31 a32 a33
Then J = AI or, more accurately, J(r,c) = AI(r,c) for all pixel locations (r,c) in image I.
2011-09-21 1999-2011 by Richard Alan Peters II 117
Color Transformation
If at pixel location (r , c) , then J (r , c) = AI (r , c) , or
rJ a11 a12 a13 rI g = a a a g J 21 22 23 I bJ a31 a32 a33 bI a11rI + a12 g I + a13bI = a21rI + a22 g I + a23bI . a31rI + a32 g I + a33bI
2011-09-21
118
Color Transformation
The inverse transform -1 (if it exists) maps the discolored image, J, back into the correctly colored version, I, i.e., I = -1[ J ]. If is linear then it is represented by the inverse of matrix A:
A-1 = [ a11a22 a33 - a11a23 a32 - a12 a21a33 + -1 a12 a23 a31 + a13 a21a32 - a13 a22 a31 ] a22 a33- a23 a32 a13 a32- a12 a33 a12 a23- a13 a22 a a -a a a a -a a a a -a a . 23 31 21 33 11 33 13 31 13 21 11 23 a21a32- a22 a31 a12 a31- a11a32 a11a22- a12 a21
2011-09-21 1999-2011 by Richard Alan Peters II 119
Color Correction
Assume we know n colors in the discolored image, J, that correspond to another set of n colors (that we also know) in the original image, I.
n rJ , k g J, k bJ, k k = 1
rJ , k rI , k gJ , k gI, k bJ , k bI , k
for k = 1, , n.
known correspondence
1999-2011 by Richard Alan Peters II
n rI , k g I, k bI, k k = 1
Color Correction
To remap the discolored image so that the result matches the original image in a linearly optimal way, we need to find the matrix, A, that minimizes
rI , k rJ , k n -1 2= g I, k -A g J, k e k =1 bI, k bJ, k
2011-09-21 1999-2011 by Richard Alan Peters II
121
Color Correction
To find the solution of this problem, let
rI , 1 rJ , 1 rI , n rJ , n Y = g I , 1 g I , n , and X = g J , 1 g J , n . bJ , 1 bI , 1 bJ , n bI , n
Y A X,
where A is the 33 matrix that we want to find.
2011-09-21 1999-2011 by Richard Alan Peters II 122
-1
Color Correction
The linearly optimal solution is the least mean squared solution that is given by
T -1
B = A = YX ( XX
-1 T
where X T represents the transpose of matrix X. Notes: 1. n, the number of color pairs, must be 3, 2. XX T must be invertible, i.e., rank(XX T ) = 3, 3. If n=3, then X T(XX T)-1 = X -1.
important
1999-2011 by Richard Alan Peters II 123
2011-09-21
Color Correction
input colors (to be changed):
r r r g b the least mean squared The linearly optimal solution is g g r g b b b solution that is given by
J, 1 J, n J, 1 J, 1 J, 1 J, 1 J, n B, 1 J, n J, n J, n J, n
B = A = YX ( XX
-1 T
T -1
Notes:
1. n, the number of color pairs, must be 3, 2. XX T must be invertible, i.e., rank(XX T ) = 3, 3. If n=3, then X T(XX T)-1 = X -1.
1999-2011 by Richard Alan Peters II 124
rI , 1 rI , n gI , 1 gI , n bI , 1 bI , n
2011-09-21
Color Correction
input colors (to be changed):
r r r g b the least mean squared The linearly optimal solution is g g r g b b b solution that is given by
J, 1 J, n J, 1 J, 1 J, 1 J, 1 J, n B, 1 J, n J, n J, n J, n
B = A = YX ( XX
-1 T
T -1
Notes:
1. n, the number of color pairs, must be 3, 2. XX T must be invertible, i.e., rank(XX T ) = 3, 3. If n=3, then X T(XX T)-1 = X -1.
1999-2011 by Richard Alan Peters II 125
rI , 1 rI , n gI , 1 gI , n bI , 1 bI , n
2011-09-21
Color Correction
Then the image is color corrected by performing
where B=A-1 is computed directly through the LMS formula on the previous page, and R & C are the number of rows and columns in the image.
2011-09-21 1999-2011 by Richard Alan Peters II 126
Original Image
2011-09-21
Aged Image
127
Color Mapping 1
17 121 171 17 122 114
Original Image
2011-09-21
Aged Image
128
Color Mapping 2
222 222 218 222 222 185
Original Image
2011-09-21
Aged Image
129
Color Mapping 3
240 171 160 240 171 103
Original Image
2011-09-21
Aged Image
130
Color Mapping 4
240 230 166 236 227 106
Original Image
2011-09-21
Aged Image
131
Color Transformations
222 222 218 17 121 171 240 171 160 240 230 166 17 122 114 240 171 103 222 222 185 236 227 106
2011-09-21
132
Color Transformations
222 222 218 17 121 171 240 171 160 240 230 166 17 122 114 240 171 103 222 222 185 236 227 106
2011-09-21
133
2011-09-21
134
B = A-1 = YX-1
corrected
2011-09-21
135
2011-09-21
136
B = A-1 = YX-1
corrected
2011-09-21
137
= YX ( XX
T
T -1
222 17 236 240 X = 222 122 227 171 185 114 106 103
222 17 240 240 Y = 222 121 230 171 218 171 166 160
2011-09-21
138
B=A
-1
= YX ( XX
T
T -1
corrected
222 17 236 240 X = 222 122 227 171 185 114 106 103
222 17 240 240 Y = 222 121 230 171 218 171 166 160
2011-09-21
139
2011-09-21
140
= YX ( XX
T
T -1
2011-09-21
141
= YX ( XX
T
T -1
2011-09-21
142
B=A
-1
= YX ( XX
T
T -1
corrected
2011-09-21
143
for comparison:
B=A
-1
= YX ( XX
T
T -1
corrected
222 17 236 240 X = 222 122 227 171 185 114 106 103
222 17 240 240 Y = 222 121 230 171 218 171 166 160
2011-09-21
144
2011-09-21
145