Sie sind auf Seite 1von 145

EECE/CS 253 Image Processing

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

Each color corresponds to a point in a 3D vector space


2011-09-21 1999-2011 by Richard Alan Peters II 3

Color Space

for standard digital images

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

1999-2011 by Richard Alan Peters II

Color Cube: Faces (outer)

2011-09-21

1999-2011 by Richard Alan Peters II

Color Cube: Faces (inner)

2011-09-21

1999-2011 by Richard Alan Peters II

Color Cube: Faces (inner and outer)

2011-09-21

1999-2011 by Richard Alan Peters II

Color Cube: Faces (inner and outer)

2011-09-21

1999-2011 by Richard Alan Peters II

Color Cube: Faces (inner and outer)

2011-09-21

1999-2011 by Richard Alan Peters II

Color Cube: Faces (inner and outer)

2011-09-21

1999-2011 by Richard Alan Peters II

10

Color Cube: Faces (inner and outer)

2011-09-21

1999-2011 by Richard Alan Peters II

11

Color Cube: Faces (inner and outer)

2011-09-21

1999-2011 by Richard Alan Peters II

12

Color Cube: Faces (inner and outer)

2011-09-21

1999-2011 by Richard Alan Peters II

13

Different Axis Sets in Color Space

RGB axes
2011-09-21

CMY axes
1999-2011 by Richard Alan Peters II 14

Color With Respect To Different Axes

The same color has different RGB and CMY coordinates.


2011-09-21 1999-2011 by Richard Alan Peters II 15

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

1999-2011 by Richard Alan Peters II

16

Gamma Adjustment of Color Bands

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

1999-2011 by Richard Alan Peters II

17

Gamma Adjustment of Color Bands

red =2

2011-09-21

1999-2011 by Richard Alan Peters II

18

Gamma Adjustment of Color Bands

original

2011-09-21

1999-2011 by Richard Alan Peters II

19

Gamma Adjustment of Color Bands

red =0.5

reduced red = increased cyan


2011-09-21 1999-2011 by Richard Alan Peters II 20

Gamma Adjustment of Color Bands

original

2011-09-21

1999-2011 by Richard Alan Peters II

21

Gamma Adjustment of Color Bands

green =2

2011-09-21

1999-2011 by Richard Alan Peters II

22

Gamma Adjustment of Color Bands

original

2011-09-21

1999-2011 by Richard Alan Peters II

23

Gamma Adjustment of Color Bands

green =0.5

reduced green = incr. magenta


2011-09-21 1999-2011 by Richard Alan Peters II 24

Gamma Adjustment of Color Bands

original

2011-09-21

1999-2011 by Richard Alan Peters II

25

Gamma Adjustment of Color Bands

blue =2

2011-09-21

1999-2011 by Richard Alan Peters II

26

Gamma Adjustment of Color Bands

original

2011-09-21

1999-2011 by Richard Alan Peters II

27

Gamma Adjustment of Color Bands

blue =0.5

reduced blue = incr. yellow


2011-09-21 1999-2011 by Richard Alan Peters II 28

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

1999-2011 by Richard Alan Peters II

29

RGB to LHS: A Perceptual Transformation


The eye has 3 types of photoreceptors: sensitive to red, green, or blue light.
luminance 2011-09-21 hue saturation

The brain transforms RGB into separate brightness and color channels (e.g., LHS).
brain photo receptors

1999-2011 by Richard Alan Peters II

30

Brightness + Chrominance Representation


There are many different ways to encode color in terms of 1D brightness and 2D chrominance. Chrominance is usually represented in terms of hue and saturation. A given brightness measure (e.g. value or NTSC luminance) defines a planar surface in the color cube on which the brightness is constant. One point on that surface is gray. The saturation of any color with the given brightness is defined as the distance on the plane from the color to the gray point. The hue is defined as the angular deviation from red measured in the same plane.
2011-09-21 1999-2011 by Richard Alan Peters II 31

Brightness + Chrominance Representation


The HSV encoding scheme presented in this lecture is a direct implementation of the vector math. Although it is nonstandard, it demonstrates the ideas that underlie most of these representations. For a good explanation of more standard HSV and LHS representations please see:
HSL and HSV - Wikipedia, the free encyclopedia.

2011-09-21

1999-2011 by Richard Alan Peters II

32

Equivalue Color Triangle


A plane through the colors r c g = 0 , b 0 r 0 r 0 g = c , and g = 0 , b 0 b c

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

Equivalue Color Triangle


c=255, v=85

On the g = 0 face of the cube the triangle traces the line, r + b = 255.

2011-09-21

1999-2011 by Richard Alan Peters II

34

Equivalue Color Hexagon


A plane through the colors r c g = 0 , b 0 r 0 r 0 g = c , and g = 0 , b 0 b c

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

Equivalue Color Hexagon


c=383, v=128

On the g = 0 face of the cube the hexagon traces the line, r + b = 383.

2011-09-21

1999-2011 by Richard Alan Peters II

36

Color Cube: Equivalue Triangle

2011-09-21

1999-2011 by Richard Alan Peters II

37

Color Cube: Equivalue Triangle

2011-09-21

1999-2011 by Richard Alan Peters II

38

Color Cube: Equivalue Triangle

2011-09-21

1999-2011 by Richard Alan Peters II

39

Color Cube: Equivalue Triangle

2011-09-21

1999-2011 by Richard Alan Peters II

40

HSV Color Representation


+ marks the spot where R=G=B= (r0+g0+b0)/3

+g +b (r + g0 + b0 ) r v0 = 1 3 0 s0 = p0 v 0

Color vector p0

p0 = (r0, g0, b0)

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

1999-2011 by Richard Alan Peters II

Color Point on Equivalue Triangle

2011-09-21

1999-2011 by Richard Alan Peters II

42

Color Vector Associated with Point

2011-09-21

1999-2011 by Richard Alan Peters II

43

Color Coordinates and Component Vectors

2011-09-21

1999-2011 by Richard Alan Peters II

44

Color Cube, Equivalue Triangle, & Gray Line

2011-09-21

1999-2011 by Richard Alan Peters II

45

Color Point and Gray Line

2011-09-21

1999-2011 by Richard Alan Peters II

46

Saturation Component of Color Vector

2011-09-21

1999-2011 by Richard Alan Peters II

47

Saturation and Value Components of Color Vector

2011-09-21

1999-2011 by Richard Alan Peters II

48

Hue, Saturation and Value

2011-09-21

1999-2011 by Richard Alan Peters II

49

Hue and Saturation on Equivalue Plane

2011-09-21

1999-2011 by Richard Alan Peters II

50

Hue, Saturation and Value with Gray Line

2011-09-21

1999-2011 by Richard Alan Peters II

51

HSV Color Representation


+ marks the spot where R=G=B= (r0+g0+b0)/3

+g +b (r + g0 + b0 ) r v0 = 1 3 0 s0 = p0 v 0

Color vector p0

p0 = (r0, g0, b0)

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

1999-2011 by Richard Alan Peters II

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

53

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

54

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

55

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

56

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

57

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

58

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

59

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

60

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

61

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

62

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

63

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

64

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

65

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

66

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

67

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

68

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

69

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

70

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

71

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

72

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

73

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

74

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

75

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

76

Equivalue Plane Intersecting Color Cube

2011-09-21

1999-2011 by Richard Alan Peters II

77

RGB to HSV Conversion


c v0 = 1 3 c , where c = r0 + g 0 + b0 . c

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

1999-2011 by Richard Alan Peters II

91 78

RGB to HSV Conversion


c 1 = , where c = r0 + g 0 + beither v c/3 is the usual def. of v 0 0. 3 c valueimage intensity (the can be used, but c/3 c average of r, g, & b) has the advantage
0

v0 = 1 3 c, or v0 = v 0 = r - c s0 = p 0 - v 0 = g - c . b - c
2

3 3

c.

of being in the range [0 , 255]. p0 s0

v0

c 3/3 is the length1of the 0 3 value vector 1 0 3 1 0 3

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

1999-2011 by Richard Alan Peters II

79

RGB to HSV Conversion


c c c 2 -1 x = R - v 0 = 0 - 1 3 c = 3 0 c -1
r0 - 1 3c . s0 = p 0 - v 0 = g 0 - 1 c 3 1 b0 - 3 c
s0 x h0 = (s0 , x) = cos s0 x
-1

v0 p0 s0

.
83 80

2011-09-21

1999-2011 by Richard Alan Peters II

RGB to HSV Conversion


In summary,

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

1999-2011 by Richard Alan Peters II

81

Normalizing the Saturation


The scalar saturation,
1 1 s0 = (r0 - 1 c + g c + b ) ( ) ( 0 0 3 3 3 c) , 2 2 2

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

HSV to RGB Conversion


The equivalue plane is perpendicular to the value vector, v. The plane contains vector x defined on slide 80. Therefore, v is perpendicular to x and y = v x is also in the plane. If we keep the directions but ignore the magnitudes, the unit vectors
1 = 0 , x 0 0 0 = 1 , and v = 0 , y 0 1

form an orthonormal basis with respect to the equivalue plane.


2011-09-21 1999-2011 by Richard Alan Peters II 83

HSV to RGB Conversion


Given values h, s, and v, where
h [ 0, 2p) , s [ 0, smax ], and v [ 0, 255],

the saturation vector is

[ s ] xyv

s cos (h) = s sin (h) , 0 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

HSV to RGB Conversion


Given values h, s, and v, where

If s is in the range 0 to 1, then it must be denormalized first by multiplying by smax.

h [ 0, 2p) , s [ 0, smax ], and v [ 0, 255],

the saturation vector is

These are the coordinates of s with respect to x, y, & v.

[ s ] xyv

s cos (h) = s sin (h) , 0 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

1999-2011 by Richard Alan Peters II

85

HSV to RGB Conversion


x , y , and v , are not in the same directions as the red, green, and . blue unit vectors, r , g , and b Therefore, [s]xyv which we know is not equal to [s]rgb which we need in order to find the color, p0, with respect to r , . g , and b


We need to find r0, g0, & b0.
86

[ s ]rgb = [ r0 g 0 b0 ]

, + g0 g + b0 b s r0 r + s sin ( h) y +0v . s s cos ( h) x


2011-09-21

1999-2011 by Richard Alan Peters II

HSV to RGB Conversion


Vector s written as a linear combination of vectors, r , g , and , and s written as a linear combination of vectors, x , y b , and v both refer to the same point on the equivalue plane.

, + g0 g + b0 b s r0 r + s sin ( h) y +0v . s s cos ( h) x


The specific numbers in [s]rgb and in [s]xyv (that represent the point w.r.t. the two coordinate systems) are, however, different.

[ 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

1999-2011 by Richard Alan Peters II

87

HSV to RGB Conversion


We can find r0, g0, and b0, from h0, s0, and v0, if we know how the unit vectors , y , and v , are expressed with respect x That relationship is in , g , and b. to r the form of a rotation matrix, A, such that,
]rgb= A[ x ] xyv , [ y ]rgb= A[ y ] xyv , [ v ]rgb= A[ v ] xyv . [x

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

HSV to RGB Conversion


When written w.r.t the xyz coordinate system we have
1 = 0 , x 0 0 0 = 1 , and v = 0 , y 0 1

So that,
1 0 0 ]rgb= A 0 , [ y ]rgb= A 1 , [ v ]rgb= A 0. [x

But that implies,


]rgb [ y ]rgb [ v ]rgb . A = [ x
2011-09-21 1999-2011 by Richard Alan Peters II

89

HSV to RGB Conversion


is the unit vector in v the direction [1 1 1]T when written w.r.t rgb coordinates. is perpendicular to x and has equal g v components. and b y is the cross product of v with x.

3 1 ]rgb = 1 [v 3 1

6 ]rgb = [x 6 2 -1 -1

]rgb = [ v ]rgb[ x ]rgb [y 2 = 2 0 1 -1

2011-09-21

1999-2011 by Richard Alan Peters II

90

HSV to RGB Conversion


Therefore, the rotation matrix is
2 0 6 -1 3 A= 6 -1 - 3
6 6

and

2 2 2
2 2

v0

2 [ s ]rgb = s cos ( h) -1 + s -1 2 = s 66 cos ( h) -1 + s -1

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

1999-2011 by Richard Alan Peters II

92

Saturation Adjustment

saturation + 50%

2011-09-21

1999-2011 by Richard Alan Peters II

93

Saturation Adjustment

original

2011-09-21

1999-2011 by Richard Alan Peters II

94

Saturation Adjustment

saturation - 50%

2011-09-21

1999-2011 by Richard Alan Peters II

95

Hue Shifting

R Y G C B M

R Y G C B M

original

2011-09-21

1999-2011 by Richard Alan Peters II

96

Hue Shifting

R Y G C B M

Y G C B M R

hue + 60

2011-09-21

1999-2011 by Richard Alan Peters II

97

Hue Shifting

R Y G C B M

G C B M R Y

hue + 120

2011-09-21

1999-2011 by Richard Alan Peters II

98

Hue Shifting

R Y G C B M

C B M R Y G

hue + 180

2011-09-21

1999-2011 by Richard Alan Peters II

99

Hue Shifting

R Y G C B M

B M R Y G C

hue + 240

2011-09-21

1999-2011 by Richard Alan Peters II

100

Hue Shifting

R Y G C B M

M R Y G C B

hue + 300

2011-09-21

1999-2011 by Richard Alan Peters II

101

Hue Shifting

R Y G C B M

R Y G C B M

hue + 360 = original

2011-09-21

1999-2011 by Richard Alan Peters II

102

Hue Shifting

R Y G C B M

R Y G C B M

original

2011-09-21

1999-2011 by Richard Alan Peters II

103

Hue Shifting

R Y G C B M

Y G C B M R

hue + 60

2011-09-21

1999-2011 by Richard Alan Peters II

104

Hue Shifting

R Y G C B M

G C B M R Y

hue + 120

2011-09-21

1999-2011 by Richard Alan Peters II

105

Hue Shifting

R Y G C B M

C B M R Y G

hue + 180

2011-09-21

1999-2011 by Richard Alan Peters II

106

Hue Shifting

R Y G C B M

B M R Y G C

hue + 240

2011-09-21

1999-2011 by Richard Alan Peters II

107

Hue Shifting

R Y G C B M

M R Y G C B

hue + 300

2011-09-21

1999-2011 by Richard Alan Peters II

108

Hue Shifting

R Y G C B M

R Y G C B M

hue + 360 = original

2011-09-21

1999-2011 by Richard Alan Peters II

109

Color Correction Via Transformation


is a point process; the transformation is applied to each pixel as a function of its color alone.

J (r , c) = F [I ( r , c)], " (r , c ) supp (I ).


Each pixel is vector valued, therefore the transformation is a vector space operator.
R I (r , c) R J (r , c) R I (r , c) I (r , c) = G I (r , c) , J (r , c) = G J (r , c) = F {I (r , c)} = F G I (r , c) . B ( r , c) B ( r , c) B ( r , c) I J I
2011-09-21 1999-2011 by Richard Alan Peters II 110

Linear Transformation of Color green yellow

cyan

original

red

blue

magenta

2011-09-21

1999-2011 by Richard Alan Peters II

111

Color Vector Space Operators


Linear operators are matrix multiplications
1/g r r / 255 ( ) r1 0 g = 255 ( g / 255)1/g g 0 1 1/gb b1 (b0 / 255)

r1 a11 a12 a13 r0 g = a a a g 1 21 22 23 0 b1 a31 a32 a33 b0

Example of a nonlinear operator: gamma correction

2011-09-21

1999-2011 by Richard Alan Peters II

112

Linear Transformation of Color


r1 r1/r0 0 0 r0 g = 0 1 0 g 0 0 b0 0 0 1 b0
175 75 175 125 75 175

2011-09-21

1999-2011 by Richard Alan Peters II

113

Linear Transformation of Color


r0 1 0 0 r0 g = 0 g / g 0 g 1 1 0 0 b0 0 0 1 b0
125 150 175 125 75 175

2011-09-21

1999-2011 by Richard Alan Peters II

114

Linear Transformation of Color


r0 1 0 0 r0 g = 0 1 0 g 0 0 b1 0 0 b1/b0 b0
125 75 225 125 75 175

2011-09-21

1999-2011 by Richard Alan Peters II

115

Linear Transformation of Color


r1 r1/r0 0 0 r g = 0 g / g 0 g0 0 1 1 0 0 b1/b0 b0 b1 0
175 150 225 125 75 175

2011-09-21

1999-2011 by Richard Alan Peters II

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

rI image I (r , c) = g I and bI rJ image J (r , c) = g J , bJ

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

1999-2011 by Richard Alan Peters II

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

known wrong colors


2011-09-21

known correct colors


120

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

Then X and Y are known 3n matrices such that

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

output colors (wanted): 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.
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

output colors (wanted): 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.
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

I (r , c) = B J (r , c) , for all (r , c) supp (J ).


In Matlab this is easily performed by
I = reshape(((B*(reshape(J,R*C,3))')'),R,C,3);

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

Linear Color Correction


NASA Summer Faculty Fellows at Ellington Air Force Base, Houston, TX, July 2002. Airplane is a T-38.

Original Image
2011-09-21

Aged Image
127

1999-2011 by Richard Alan Peters II

Color Mapping 1
17 121 171 17 122 114

Original Image
2011-09-21

Aged Image
128

1999-2011 by Richard Alan Peters II

Color Mapping 2
222 222 218 222 222 185

Original Image
2011-09-21

Aged Image
129

1999-2011 by Richard Alan Peters II

Color Mapping 3
240 171 160 240 171 103

Original Image
2011-09-21

Aged Image
130

1999-2011 by Richard Alan Peters II

Color Mapping 4
240 230 166 236 227 106

Original Image
2011-09-21

Aged Image
131

1999-2011 by Richard Alan Peters II

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

The aging process was a transformation, , that mapped:


17 17 122 = F 121 114 171 222 222 222 = F 222 185 218 240 240 171 = F 171 103 160 236 240 227 = F 230 106 166

2011-09-21

1999-2011 by Richard Alan Peters II

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

To undo the process we need to find, -1, that maps:


17 17 121 = F-1 122 171 114 222 222 222 = F-1 222 218 185 240 240 171 = F-1 171 160 103 240 236 230 = F-1 227 166 106

2011-09-21

1999-2011 by Richard Alan Peters II

133

Correction Using 3 Mappings


B = A-1 = YX-1

222 17 240 X = 222 122 171 185 114 103

222 17 240 Y = 222 121 171 218 171 160

2011-09-21

1999-2011 by Richard Alan Peters II

134

Correction Using 3 Mappings


original

B = A-1 = YX-1

corrected

222 17 240 X = 222 122 171 185 114 103

222 17 240 Y = 222 121 171 218 171 160

2011-09-21

1999-2011 by Richard Alan Peters II

135

Another Correction Using 3 Mappings


B = A-1 = YX-1

222 17 236 X = 222 122 227 185 114 106

222 17 240 Y = 222 121 230 218 171 166

2011-09-21

1999-2011 by Richard Alan Peters II

136

Another Correction Using 3 Mappings


original

B = A-1 = YX-1

corrected

222 17 236 X = 222 122 227 185 114 106

222 17 240 Y = 222 121 230 218 171 166

2011-09-21

1999-2011 by Richard Alan Peters II

137

Correction Using All 4 Mappings


B=A
-1

= 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

1999-2011 by Richard Alan Peters II

138

Correction Using All 4 Mappings


original

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

1999-2011 by Richard Alan Peters II

139

Random Sampling of Color Values


>> rr = round(R*rand([1 n])); >> rc = round(C*rand([1 n])); >> idx = [rr;rc]; >> Y(:,1) = diag(I(rr,rc,1)); >> Y(:,2) = diag(I(rr,rc,2)); >> Y(:,3) = diag(I(rr,rc,3)); >> X(:,1) = diag(J(rr,rc,1)); >> X(:,2) = diag(J(rr,rc,2)); >> X(:,3) = diag(J(rr,rc,3));
diag(I(rr,rc,1)): vector from main diagonal of matrix I(rr,rc,1). rand([1 n]) : 1 n matrix of random numbers between 0 and 1. R = number of rows in image C = number of columns in image n = number of pixels to select

2011-09-21

1999-2011 by Richard Alan Peters II

140

Correction Using 128 Mappings


B=A
-1

= YX ( XX
T

T -1

111 235 X = 103 233 22 210

111 234 Y = 102 233 71 229

2011-09-21

1999-2011 by Richard Alan Peters II

141

Correction Using 128 Mappings


B=A
-1

= YX ( XX
T

T -1

111 235 X = 103 233 22 210

111 234 Y = 102 233 71 229

2011-09-21

1999-2011 by Richard Alan Peters II

142

Correction Using 128 Mappings


original

B=A

-1

= YX ( XX
T

T -1

corrected

111 235 X = 103 233 22 210

111 234 Y = 102 233 71 229

2011-09-21

1999-2011 by Richard Alan Peters II

143

for comparison:

Correction Using 4 Mappings


original

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

1999-2011 by Richard Alan Peters II

144

Linear Color Transformation Program


function J = LinTrans(I,A) [R C B] = size(I); I = double(I); J = reshape(((A*(reshape(I,R*C,3))')'),R,C,3); J = uint8(J); return;

2011-09-21

1999-2011 by Richard Alan Peters II

145

Das könnte Ihnen auch gefallen