Date post: | 27-May-2017 |
Category: |
Documents |
Upload: | ashoka-vanjare |
View: | 213 times |
Download: | 0 times |
EECE/CS 253 Image Processing
Richard Alan Peters IIDepartment of Electrical Engineering and
Computer ScienceFall Semester 2011
Lecture Notes: Color Correction
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.
2011-09-21 1999-2011 by Richard Alan Peters II 2
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 4
Color Cube: Faces (outer)
2011-09-21 1999-2011 by Richard Alan Peters II 5
Color Cube: Faces (inner)
2011-09-21 1999-2011 by Richard Alan Peters II 6
Color Cube: Faces (inner and outer)
2011-09-21 1999-2011 by Richard Alan Peters II 7
Color Cube: Faces (inner and outer)
2011-09-21 1999-2011 by Richard Alan Peters II 8
Color Cube: Faces (inner and outer)
2011-09-21 1999-2011 by Richard Alan Peters II 9
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 CMY axes
2011-09-21 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
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).
original
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
R G B
L a* b*
are represented by three bands (not uniquely) e.g., R, G, & B or L, a*, & b*.
Red
Green
Blue
Luminance
a*-chroma
b*-chroma
2011-09-21 1999-2011 by Richard Alan Peters II 29
RGB to LHS: A Perceptual Transformation
luminance
huesaturation
photo receptorsbrain
The eye has 3 types of photoreceptors: sensitive to red, green, or blue light.
The brain transforms RGB into separate brightness and color channels (e.g., LHS).
2011-09-21 1999-2011 by Richard Alan Peters II 30
Brightness + Chrominance Representation
2011-09-21 1999-2011 by Richard Alan Peters II 31
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.
Brightness + Chrominance Representation
2011-09-21 1999-2011 by Richard Alan Peters II 32
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.
Equivalue Color Triangle
2011-09-21 1999-2011 by Richard Alan Peters II 33
A plane through the colors
0 00 , , and 0 ,0 0
r c r rg g c gb b 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.
c=255, v=85
2011-09-21 1999-2011 by Richard Alan Peters II 34
On the g = 0 face of the cube the triangle traces the line, r + b = 255.
Equivalue Color Triangle
c=255, v=85
Equivalue Color Hexagon
2011-09-21 1999-2011 by Richard Alan Peters II 35
A plane through the colors
0 00 , , and 0 ,0 0
r c r rg g c gb b 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.
c=384, v=128
2011-09-21 1999-2011 by Richard Alan Peters II 36
On the g = 0 face of the cube the hexagon traces the line, r + b = 383.
c=383, v=128
Equivalue Color Hexagon
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
Color vector p0
+ marks the spot where
R=G=B= (r0+g0+b0)/3
( )( )000
00031
0ˆˆˆ
vpsbgrv
−=++++= bgr
( )[ ]{ }000000 ,ˆ svr −++∠= bgrh
00 s=s
00 v=v
intersects R, G, & B at r0+g0+b0, and contains p0.
lies in plane R+G+B=(r0+g0+b0),
Triangle:
p0 = (r0, g0, b0)
2011-09-21 1999-2011 by Richard Alan Peters II 41
Color Point on Equivalue Triangle
2011-09-21 1999-2011 by Richard Alan Peters II 42
2011-09-21 1999-2011 by Richard Alan Peters II 43
Color Vector Associated with Point
2011-09-21 1999-2011 by Richard Alan Peters II 44
Color Coordinates and Component Vectors
2011-09-21 1999-2011 by Richard Alan Peters II 45
Color Cube, Equivalue Triangle, & Gray Line
2011-09-21 1999-2011 by Richard Alan Peters II 46
Color Point and Gray Line
2011-09-21 1999-2011 by Richard Alan Peters II 47
Saturation Component of Color Vector
2011-09-21 1999-2011 by Richard Alan Peters II 48
Saturation and Value Components of Color Vector
2011-09-21 1999-2011 by Richard Alan Peters II 49
Hue, Saturation and Value
2011-09-21 1999-2011 by Richard Alan Peters II 50
Hue and Saturation on Equivalue Plane
2011-09-21 1999-2011 by Richard Alan Peters II 51
Hue, Saturation and Value with Gray Line
HSV Color Representation
Color vector p0
+ marks the spot where
R=G=B= (r0+g0+b0)/3
( )( )000
00031
0ˆˆˆ
vpsbgrv
−=++++= bgr
( )[ ]{ }000000 ,ˆ svr −++∠= bgrh
00 s=s
00 v=v
intersects R, G, & B at r0+g0+b0, and contains p0.
lies in plane R+G+B=(r0+g0+b0),
Triangle:
p0 = (r0, g0, b0)
2011-09-21 1999-2011 by Richard Alan Peters II 52
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
10 0 0 03 , where .
cc c r g bc
é ùê ú= = + +ê úê úë û
v
310 0 03 3, or .v c v c= = =v
0
0 0
0
.rgb
é ùê ú= ê úê úë û
p1
0 31
0 0 0 0 31
0 3
.r cg cb c
é ù-ê ú= - = -ê úê ú-ë û
s p v
( ) ( ) ( )2 2 21 1 10 0 0 0 03 3 3 .s r c g c b c= = - + - + -s
91
p0
v0
s0
2011-09-21 1999-2011 by Richard Alan Peters II 78
10 0 0 03 , where .
cc c r g bc
é ùê ú= = + +ê úê úë û
v
310 0 03 3, or .v c v c= = =v
0
0 0
0
.rgb
é ùê ú= ê úê úë û
p1
0 31
0 0 0 0 31
0 3
.r cg cb c
é ù-ê ú= - = -ê úê ú-ë û
s p v
( ) ( ) ( )2 2 21 1 10 0 0 0 03 3 3 .s r c g c b c= = - + - + -s
p0
v0
s0
RGB to HSV Conversion
c/3 is the usual value-image intensity (the average of r, g, & b) …
… c √3/3 is the length of the value vector…
… either def. of v0can be used, but c/3 has the advantage of being in the range [0 , 255].
2011-09-21 1999-2011 by Richard Alan Peters II 79
RGB to HSV Conversion
( ) 1 00 0
0
, cos .h -æ ö⋅ ÷ç ÷= = ç ÷ç ÷çè ø
s xs xs x
10 3
20 1
30 1
c c ccc
é ù é ù é ùê ú ê ú ê ú= - = - = -ê ú ê ú ê ú
-ê ú ê ú ê úë û ë û ë ûx R v
10 3
10 0 0 0 3
10 3
.r cg cb c
é ù-ê ú= - = -ê úê ú-ë û
s p vp0
v0
s0
x
832011-09-21 1999-2011 by Richard Alan Peters II 80
p0
v0
s0
x
RGB to HSV Conversion
1 00
0
cos .h -æ ö⋅ ÷ç ÷= ç ÷ç ÷çè ø
s xs x
310 0 03 3, or ,v c v c= = =v
( ) ( ) ( )2 2 21 1 10 0 0 03 3 3 ,s r c g c b c= - + - + -
In summary,
where c = r0 + g0 + b0,
and
Usually, s0 is normalized to lie in the interval (0,1) and h0is shifted to lie in (0,2π).
2011-09-21 1999-2011 by Richard Alan Peters II 81
p0
v0
s0
x
which has length
Normalizing the Saturation
( ) ( ) ( )2 2 21 1 10 0 0 03 3 3 ,s r c g c b c= - + - + -
The scalar saturation,
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
208.2066.maxmax ≈= ss
[ ] [ ] [ ]1max 3255 0 0 255 255 255 170 85 85 ,= - = - -s T T T
Therefore, s0 is replaced by . max0 ss
2011-09-21 1999-2011 by Richard Alan Peters II 82
ˆ
ˆ
ˆ
HSV to RGB Conversion
form an orthonormal basis with respect to the equivalue plane.
1 0 0ˆ ˆ ˆ0 , 1 , and 0 ,
0 0 1
é ù é ù é ùê ú ê ú ê ú= = =ê ú ê ú ê úê ú ê ú ê úë û ë û ë û
x y v
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
2011-09-21 1999-2011 by Richard Alan Peters II 83
ˆ
ˆ
ˆ
HSV to RGB ConversionGiven values h, s, and v, where
[ ) [ ] [ ]max0,2 , 0, , and 0, 255 ,h s s vpÎ Î Î
the saturation vector is
( ) ( )ˆ ˆ ˆcos sin 0 .s h s h= + +s x y v
[ ]( )( )
cossin ,
0
s hs h
é ùê ú= ê úê úë û
xyv
xyv
s
with respect to unit vectors x, y, and v, in the equivalue plane.
ˆ ˆˆ
2011-09-21 1999-2011 by Richard Alan Peters II 84
ˆ
ˆ
ˆ
( ) ( )ˆ ˆ ˆcos sin 0 .s h s h= + +s x y v
[ ]( )( )
cossin ,
0
s hs h
é ùê ú= ê úê úë û
xyv
xyv
s
[ ) [ ] [ ]max0,2 , 0 , , and 0, 255 ,h s s vpÎ Î Î
HSV to RGB ConversionGiven values h, s, and v, where
the saturation vector is
with respect to unit vectors x, y, and v, in the equivalue plane.ˆ
These are the coordinates of s with respect to x, y, & v.ˆ ˆ ˆ
This is s written as a linear combination of vectors x, y, & v.ˆ ˆ ˆ
If s is in the range 0 to 1, then it must be denormalized first by multiplying by smax.
2011-09-21 1999-2011 by Richard Alan Peters II 85
ˆ
ˆ
ˆ
ˆ
ˆ
ˆ
HSV to RGB Conversion
[ ] [ ]
( ) ( )
0 0 0
0 0 0ˆˆ ˆ ,
ˆ ˆ ˆcos sin 0 .
r g b
r g bs h s h
=
« + +
« + +
rgbs
s r g bs x y v
T
We need to find r0, g0, & b0.
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.
ˆ ˆ ˆ
ˆ ˆ ˆ
ˆˆ ˆ
2011-09-21 1999-2011 by Richard Alan Peters II 86
ˆ
ˆ
ˆ
ˆ
ˆ
ˆ
HSV to RGB Conversion
[ ] [ ]
[ ] ( ) ( )[ ]
0 0 0
cos sin 0
r g b
s h s h
=
=
rgb
xyz
s
s
T
T
( ) ( )0 0 0
ˆˆ ˆ ,ˆ ˆ ˆcos sin 0 .
r g bs h s h
« + +
« + +
s r g bs x y v
The specific numbers in [s]rgb and in [s]xyv (that represent the point w.r.t. the two coordinate systems) are, however, different.
[ ] [ ]¹rgb xyzs sbut
and
Vector s written as a linear combination of vectors, r, g, and b, and s written as a linear combination of vectors, x, y, and v both refer to the same point on the equivalue plane.
ˆ ˆˆ ˆ ˆˆ
2011-09-21 1999-2011 by Richard Alan Peters II 87
ˆ
ˆ
ˆ
ˆ
ˆ
ˆ
HSV to RGB Conversion
Then,[ ] [ ]
( )[ ] ( )[ ] [ ]
( ) [ ] ( ) [ ] [ ]
( )[ ] ( )[ ] [ ]
ˆ ˆ ˆcos sin 0
ˆ ˆ ˆcos sin 0
ˆ ˆ ˆcos sin 0 .
A
A s h s h
s h A s h A A
s h s h
=
é ù= + +ê úë û= + +
= + +
rgb xyv
xyv xyv xyv
xyv xyv xyv
rgb rgb rgb
s s
x y v
x y v
x y v
We can find r0, g0, and b0, from h0, s0, and v0, if we know how the unit vectors x, y, and v, are expressed with respect to r, g, and b. That relationship is in the form of a rotation matrix, A, such that,
ˆ ˆ ˆˆ ˆ ˆ
2011-09-21 1999-2011 by Richard Alan Peters II 88
[ ] [ ] [ ] [ ] [ ] [ ]ˆ ˆ ˆ ˆ ˆ ˆ, , .A A A= = =rgb xyv rgb xyv rgb xyvx x y y v v
ˆ
ˆ
ˆ
ˆ
ˆ
ˆ
HSV to RGB ConversionWhen written w.r.t the xyzcoordinate system we have
[ ] [ ] [ ]ˆ ˆ ˆ .A é ù= ê úë ûrgb rgb rgbx y v
1 0 0ˆ ˆ ˆ0 , 1 , and 0 ,
0 0 1
é ù é ù é ùê ú ê ú ê ú= = =ê ú ê ú ê úê ú ê ú ê úë û ë û ë û
x y v
[ ] [ ] [ ]1 0 00 1 00 0 1
ˆ ˆ ˆ, , .A A Aé ù é ù é ù= = =ê ú ê ú ê úë û ë û ë ûrgb rgb rgbx y v
So that,
But that implies,
2011-09-21 1999-2011 by Richard Alan Peters II 89
ˆ
ˆ ˆ
ˆ
ˆ
ˆ
HSV to RGB Conversion
[ ]13ˆ 1
3 1
é ùê ú= ê úê úë û
rgbv
[ ]26ˆ 1
6 1
é ùê ú= -ê úê ú-ë û
rgbx
[ ] [ ] [ ]ˆ ˆ ˆ
02 12 1
= ´
é ùê ú= ê úê ú-ë û
rgb rgb rgby v x
v is the unit vector in the direction [1 1 1]T
when written w.r.t rgb coordinates.
ˆ
x is perpendicular to v and has equal gand b components.
ˆˆ ˆ
ˆ
y is the cross product of vwith x.
ˆˆ
ˆ
2011-09-21 1999-2011 by Richard Alan Peters II 90
p0
v0
s0
HSV to RGB ConversionTherefore, the rotation matrix is
2 0 26 1 3 2
6 1 3 2A
é ùê úê ú= -ê úê ú- -ë û
and
[ ] ( ) ( )
( ) ( )
2 0 16 321 1 16 2 31 1 1
2 06 21 16 21 1
cos sin 0
cos sin .
s h s h
s h s h
-- -
-- -
é ù é ù é ù= + +ê ú ê ú ê úë û ë û ë ûé ù é ù= +ê ú ê úë û ë û
rgbs
Finally, [s]rgb must be shifted to the value vector to obtain the rgb color of p0:
[ ] [ ] [ ]0 ,= = +rgb rgb rgbp p s v 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 original→→→→→→
RYGCBM
RYGCBM
2011-09-21 1999-2011 by Richard Alan Peters II 96
Hue Shifting hue + 60°→→→→→→
RYGCBM
YGCBMR
2011-09-21 1999-2011 by Richard Alan Peters II 97
Hue Shifting hue + 120°→→→→→→
RYGCBM
GCBMRY
2011-09-21 1999-2011 by Richard Alan Peters II 98
Hue Shifting hue + 180°→→→→→→
RYGCBM
CBMRYG
2011-09-21 1999-2011 by Richard Alan Peters II 99
Hue Shifting hue + 240°→→→→→→
RYGCBM
BMRYGC
2011-09-21 1999-2011 by Richard Alan Peters II 100
Hue Shifting hue + 300°→→→→→→
RYGCBM
MRYGCB
2011-09-21 1999-2011 by Richard Alan Peters II 101
Hue Shifting hue + 360° = original
→→→→→→
RYGCBM
RYGCBM
2011-09-21 1999-2011 by Richard Alan Peters II 102
Hue Shifting original→→→→→→
RYGCBM
RYGCBM
2011-09-21 1999-2011 by Richard Alan Peters II 103
Hue Shifting hue + 60°→→→→→→
RYGCBM
YGCBMR
2011-09-21 1999-2011 by Richard Alan Peters II 104
Hue Shifting hue + 120°→→→→→→
RYGCBM
GCBMRY
2011-09-21 1999-2011 by Richard Alan Peters II 105
Hue Shifting hue + 180°→→→→→→
RYGCBM
CBMRYG
2011-09-21 1999-2011 by Richard Alan Peters II 106
Hue Shifting hue + 240°→→→→→→
RYGCBM
BMRYGC
2011-09-21 1999-2011 by Richard Alan Peters II 107
Hue Shifting hue + 300°→→→→→→
RYGCBM
MRYGCB
2011-09-21 1999-2011 by Richard Alan Peters II 108
Hue Shifting hue + 360° = original
→→→→→→
RYGCBM
RYGCBM
2011-09-21 1999-2011 by Richard Alan Peters II 109
Color Correction Via Transformationis a point process; the transformation is applied to each pixel as a function of its color alone.
( ) ( )[ ] ( ) ( ), , , , supp .r c r c r c= F " ÎJ I I
Each pixel is vector valued, therefore the transformation is a vector space operator.
( )( )( )( )
,, , ,
,
r cr c r c
r c
é ùê ú= ê úê úë û
I
I
I
RI G
B( )
( )( )( )
( ){ }( )( )( )
, ,, , , , .
, ,
r c r cr c r c r c r c
r c r c
ì üé ù é ùï ïï ïê ú ê úï ï= = F = Fí ýê ú ê úï ïê ú ê úï ïï ïë û ë ûî þ
J I
J I
J I
R RJ G I G
B B
2011-09-21 1999-2011 by Richard Alan Peters II 110
Linear Transformation of Color
green yellow
blue magenta
cyan redoriginal
2011-09-21 1999-2011 by Richard Alan Peters II 111
Color Vector Space Operators
11 12 13 01
1 21 22 23 0
1 31 32 33 0
a a a rrg a a a gb a a a b
é ù é ùé ùê ú ê úê ú = ê ú ê úê úê ú ê úê úë û ë û ë û
( )( )( )
1/01 1/
1 01/
1 0
/ 255255 / 255
/ 255
r
g
b
rrg gb b
g
g
g
é ùé ù ê úê ú ê ú= ⋅ê ú ê úê ú ê úë û ë û
Linear operators are matrix multiplications
Example of a nonlinear operator: gamma correction
2011-09-21 1999-2011 by Richard Alan Peters II 112
Linear Transformation of Color
1 0 01
0 0
0 0
/ 0 00 1 00 0 1
r r rrg gb b
é ù é ù é ùê ú ê ú ê ú=ê ú ê ú ê úê ú ê ú ê úë û ë û ë û
12575
175
17575
175
2011-09-21 1999-2011 by Richard Alan Peters II 113
Linear Transformation of Color
0 0
1 1 0 0
0 0
1 0 00 / 00 0 1
r rg g g gb b
é ù é ùé ùê ú ê úê ú=ê ú ê úê úê ú ê úê úë ûë û ë û
12575
175
125150175
2011-09-21 1999-2011 by Richard Alan Peters II 114
Linear Transformation of Color
0 0
0 0
1 01 0
1 0 00 1 00 0 /
r rg g
b bb b
é ù é ùé ùê ú ê úê ú=ê ú ê úê úê ú ê úê úë ûë û ë û
12575
175
12575
225
2011-09-21 1999-2011 by Richard Alan Peters II 115
Linear Transformation of Color
1 0 01
1 1 0 0
1 1 0 0
/ 0 00 / 00 0 /
r r rrg g g gb b b b
é ù é ùé ùê ú ê úê ú = ê ú ê úê úê ú ê úê úë û ë û ë û
12575
175
175150225
2011-09-21 1999-2011 by Richard Alan Peters II 116
Color TransformationAssume J is a discolored version of image I such that J = Φ[ I ]. If Φ is linear then it is represented by a 3×3 matrix, A:
11 12 13
21 22 23
31 32 33
.a a aa a aa a a
é ùê ú= ê úê úë û
A
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
11 12 13
21 22 23
31 32 33
11 12 13
21 22 23
31 32 33
.
a a aa a aa a aa a aa a aa a a
r rg g
bb
r g br g br g b
é ù é ù é ùê ú ê ú ê ú=ê ú ê ú ê úê ú ê ú ê úë ûë û ë û
é ù+ +ê ú= + +ê úê ú+ +ë û
J I
J I
IJ
I I I
I I I
I I I
( ) ( )then , , , orr c r c=J AI( )If at pixel location , ,r c
( )image , and r crgb
é ùê ú= ê úê úë û
I
I
I
I
( )image , ,r crgb
é ùê ú= ê úê úë û
J
J
J
J
2011-09-21 1999-2011 by Richard Alan Peters II 118
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:
[]
111 22 33 11 23 32 12 21 33
112 23 31 13 21 32 13 22 31
22 33 23 32 13 32 12 33 12 23 13 22
23 31 21 33 11 33 13 31 13 21 11 23
21 32 22 31 12 31 11 32 11 22 1
a a a a a a a a aa a a a a a a a aa a a a a a a a a a a aa a a a a a a a a a a aa a a a a a a a a a a
-
-= - - +
+ -- - -- - -- - -
A
2 21
.a
é ùê úê úê úë û
2011-09-21 1999-2011 by Richard Alan Peters II 119
Color Transformation
,
,
, 1
nk
k
k k
rgb
=
ì üé ùï ïï ïê úï ïê úí ýï ïê úï ïê úï ïë ûî þ
I
I
I
,
,
, 1
nk
k
k k
rgb
=
ì üé ùï ïï ïê úï ïê úí ýï ïê úï ïê úï ïë ûî þ
J
J
J
, ,
, ,
, ,
k k
k k
k k
r rg gb b
é ù é ùê ú ê úê ú ê ú«ê ú ê úê ú ê úë û ë û
J I
J I
J I
for 1, , .k n=
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.
known wrong colors
known correct colors
known correspondence
Color Correction
2011-09-21 1999-2011 by Richard Alan Peters II 120
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
2, ,
12, ,
1, ,
k knk k
kk k
r rg geb b
-
=
é ù é ùê ú ê ú
= ê ú ê ú-åê ú ê úê ú ê úë û ë û
I J
I J
I J
A
Color Correction
2011-09-21 1999-2011 by Richard Alan Peters II 121
To find the solution of this problem, let
, 1 ,
, 1 ,
, 1 ,
,n
n
n
r rg gb b
é ùé ù é ùê úê ú ê úê úê ú ê ú=ê úê ú ê úê úê ú ê úë û ë ûë û
I I
I I
I I
Y and, 1 ,
, 1 ,
, 1 ,
.n
n
n
r rg gb b
é ùé ù é ùê úê ú ê úê úê ú ê ú=ê úê ú ê úê úê ú ê úë û ë ûë û
J J
J J
J J
X
Then X and Y are known 3×n matrices such that
1 ,-»Y A X
where A is the 3×3 matrix that we want to find.
Color Correction
2011-09-21 1999-2011 by Richard Alan Peters II 122
The linearly optimal solution is the least mean squared solution that is given by
where X T represents the transpose of matrix X.
( ) 11 --= =B A YX XXT T
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.
Color Correction
2011-09-21 1999-2011 by Richard Alan Peters II 123
important
where X T represents the transpose of matrix X.
( ) 11 --= =B A YX XXT T
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.
The linearly optimal solution is the least mean squared solution that is given by
Color Correction
2011-09-21 1999-2011 by Richard Alan Peters II 124
input colors (to be changed):
, 1 , , 1 , 1 , 1, 1 ,
, , ,, 1 ,
n
n
n n nB n
r r r g bg g
r g bb b
é ùé ùé ù é ù é ùê úê úê ú ê ú ë ûê úê úê ú ê ú ⋅ê úê úê ú ê ú é ùê úê úê ú ê ú ë ûë û ë ûë û ë û
J J J J JJ J
J J JJ
output colors (wanted):
, 1 ,
, 1 ,
, 1 ,
n
n
n
r rg gb b
é ùé ù é ùê úê ú ê úê úê ú ê úê úê ú ê úê úê ú ê úë û ë ûë û
I I
I I
I I
where X T represents the transpose of matrix X.
( ) 11 --= =B A YX XXT T
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.
The linearly optimal solution is the least mean squared solution that is given by
Color Correction
2011-09-21 1999-2011 by Richard Alan Peters II 125
input colors (to be changed):
, 1 , , 1 , 1 , 1, 1 ,
, , ,, 1 ,
n
n
n n nB n
r r r g bg g
r g bb b
é ùé ùé ù é ù é ùê úê úê ú ê ú ë ûê úê úê ú ê ú ⋅ê úê úê ú ê ú é ùê úê úê ú ê ú ë ûë û ë ûë û ë û
J J J J JJ J
J J JJ
output colors (wanted):
, 1 ,
, 1 ,
, 1 ,
n
n
n
r rg gb b
é ùé ù é ùê úê ú ê úê úê ú ê úê úê ú ê úê úê ú ê úë û ë ûë û
I I
I I
I I
Then the image is color corrected by performing
I = reshape(((B*(reshape(J,R*C,3))')'),R,C,3);
( ) ( ) ( ) ( ), , , for all , supp .r c r c r c= ÎI B J J
In Matlab this is easily performed by
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.
Color Correction
2011-09-21 1999-2011 by Richard Alan Peters II 126
Linear Color Correction
Original Image “Aged” Image
NASA Summer Faculty Fellows at Ellington Air Force Base, Houston, TX, July 2002. Airplane is a T-38.
2011-09-21 1999-2011 by Richard Alan Peters II 127
17112117
11412217
Color Mapping 1
Original Image “Aged” Image
2011-09-21 1999-2011 by Richard Alan Peters II 128
185222222
218222222
Color Mapping 2
Original Image “Aged” Image
2011-09-21 1999-2011 by Richard Alan Peters II 129
Color Mapping 3
160171240
103171240
Original Image “Aged” Image
2011-09-21 1999-2011 by Richard Alan Peters II 130
Color Mapping 4
166230240
106227236
Original Image “Aged” Image
2011-09-21 1999-2011 by Richard Alan Peters II 131
Color Transformations
218222222
185222222
11412217
106227236
103171240
160171240
17112117
166230240
17 17122 121114 171
ì üé ù é ùï ïï ïê ú ê úï ï= Fí ýê ú ê úï ïê ú ê úï ïï ïë û ë ûî þ
222 222222 222185 218
ì üé ù é ùï ïï ïê ú ê úï ï= Fí ýê ú ê úï ïê ú ê úï ïï ïë û ë ûî þ
240 240171 171103 160
ì üé ù é ùï ïï ïê ú ê úï ï= Fí ýê ú ê úï ïê ú ê úï ïï ïë û ë ûî þ
236 240227 230106 166
ì üé ù é ùï ïï ïê ú ê úï ï= Fí ýê ú ê úï ïê ú ê úï ïï ïë û ë ûî þ
The aging process was a transformation, Φ, that mapped:
2011-09-21 1999-2011 by Richard Alan Peters II 132
Color Transformations
218222222
185222222
11412217
106227236
103171240
160171240
17112117
166230240
117 17121 122171 114
-ì üé ù é ùï ïï ïê ú ê úï ï= F í ýê ú ê úï ïê ú ê úï ïï ïë û ë ûî þ
1222 222222 222218 185
-ì üé ù é ùï ïï ïê ú ê úï ï= F í ýê ú ê úï ïê ú ê úï ïï ïë û ë ûî þ
1240 240171 171160 103
-ì üé ù é ùï ïï ïê ú ê úï ï= F í ýê ú ê úï ïê ú ê úï ïï ïë û ë ûî þ
1240 236230 227166 106
-ì üé ù é ùï ïï ïê ú ê úï ï= F í ýê ú ê úï ïê ú ê úï ïï ïë û ë ûî þ
To undo the process we need to find, Φ-1, that maps:
2011-09-21 1999-2011 by Richard Alan Peters II 133
Correction Using 3 Mappings
222 17 240222 122 171185 114 103
é ùê ú= ê úê úë û
X222 17 240222 121 171218 171 160
é ùê ú= ê úê úë û
Y
1 1- -= =B A YX
2011-09-21 1999-2011 by Richard Alan Peters II 134
222 17 240222 122 171185 114 103
é ùê ú= ê úê úë û
X222 17 240222 121 171218 171 160
é ùê ú= ê úê úë û
Y
original corrected
2011-09-21 1999-2011 by Richard Alan Peters II 135
1 1- -= =B A YX
Correction Using 3 Mappings
222 17 236222 122 227185 114 106
é ùê ú= ê úê úë û
X222 17 240222 121 230218 171 166
é ùê ú= ê úê úë û
Y
Another Correction Using 3 Mappings
2011-09-21 1999-2011 by Richard Alan Peters II 136
1 1- -= =B A YX
original corrected
2011-09-21 1999-2011 by Richard Alan Peters II 137
1 1- -= =B A YX
222 17 236222 122 227185 114 106
é ùê ú= ê úê úë û
X222 17 240222 121 230218 171 166
é ùê ú= ê úê úë û
Y
Another Correction Using 3 Mappings
( ) 11 --= =B A YX XXT T
222 17 236 240222 122 227 171185 114 106 103
é ùê ú= ê úê úë û
X222 17 240 240222 121 230 171218 171 166 160
é ùê ú= ê úê úë û
Y
Correction Using All 4 Mappings
2011-09-21 1999-2011 by Richard Alan Peters II 138
( ) 11 --= =B A YX XXT T
original corrected
2011-09-21 1999-2011 by Richard Alan Peters II 139
222 17 236 240222 122 227 171185 114 106 103
é ùê ú= ê úê úë û
X222 17 240 240222 121 230 171218 171 166 160
é ùê ú= ê úê úë û
Y
Correction Using All 4 Mappings
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));
R = number of rows in imageC = number of columns in imagen = number of pixels to select
rand([1 n]) : 1 × n matrix of random numbers between 0 and 1.
diag(I(rr,rc,1)): vector from main diagonal of matrix I(rr,rc,1).
2011-09-21 1999-2011 by Richard Alan Peters II 140
( ) 11 --= =B A YX XXT T
111 235103 23322 210
é ùê ú= ê úê úë û
X 111 234102 23371 229
é ùê ú= ê úê úë û
Y
Correction Using 128 Mappings
2011-09-21 1999-2011 by Richard Alan Peters II 141
111 234102 23371 229
é ùê ú= ê úê úë û
Y 111 235103 23322 210
é ùê ú= ê úê úë û
X
( ) 11 --= =B A YX XXT T
2011-09-21 1999-2011 by Richard Alan Peters II 142
Correction Using 128 Mappings
( ) 11 --= =B A YX XXT T
111 235103 23322 210
é ùê ú= ê úê úë û
X 111 234102 23371 229
é ùê ú= ê úê úë û
Y
original corrected
2011-09-21 1999-2011 by Richard Alan Peters II 143
Correction Using 128 Mappings
( ) 11 --= =B A YX XXT T
original corrected
2011-09-21 1999-2011 by Richard Alan Peters II 144
Correction Using 4 Mappings
222 17 236 240222 122 227 171185 114 106 103
é ùê ú= ê úê úë û
X222 17 240 240222 121 230 171218 171 166 160
é ùê ú= ê úê úë û
Y
for comparison:
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