EECE253_05_ColorCorrection

EECE253_05_ColorCorrection - EECE/CS 253 Image Processing...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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. 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 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 2011-09-21 1999-2011 by Richard Alan Peters II red γ=2 18 Gamma Adjustment of Color Bands 2011-09-21 1999-2011 by Richard Alan Peters II original 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 2011-09-21 1999-2011 by Richard Alan Peters II original 21 Gamma Adjustment of Color Bands 2011-09-21 1999-2011 by Richard Alan Peters II green γ=2 22 Gamma Adjustment of Color Bands 2011-09-21 1999-2011 by Richard Alan Peters II original 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 2011-09-21 1999-2011 by Richard Alan Peters II original 25 Gamma Adjustment of Color Bands 2011-09-21 1999-2011 by Richard Alan Peters II blue γ=2 26 Gamma Adjustment of Color Bands 2011-09-21 1999-2011 by Richard Alan Peters II original 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 2011-09-21 a* 1999-2011 by Richard Alan Peters II b* 29 RGB to LHS: A Perceptual Transformation luminance The eye has 3 types of photoreceptors: sensitive to red, green, or blue light. hue saturation The brain transforms RGB into separate brightness and color channels (e.g., LHS). brain 2011-09-21 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 Color vector p0 ( ˆˆˆ v 0 = 1 (r0 + g 0 + b0 ) r + g + b 3 s0 = p0 − v 0 ) p0 = (r0, g0, b0) lies in plane R+G+B=(r0+g0+b0), v0 = v 0 s0 = s0 intersects R, G, & B at r0+g0+b0, and contains p0. ˆ h0 = ∠{[(r0 + g 0 + b0 ) r − v 0 ], s0 } Triangle: 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 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 Color vector p0 ( ˆˆˆ v 0 = 1 (r0 + g 0 + b0 ) r + g + b 3 s0 = p0 − v 0 ) p0 = (r0, g0, b0) lies in plane R+G+B=(r0+g0+b0), v0 = v 0 s0 = s0 intersects R, G, & B at r0+g0+b0, and contains p0. ˆ h0 = ∠{[(r0 + g 0 + b0 ) r − v 0 ], s0 } Triangle: 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 écù v 0 = 1 êê cúú , where c = r0 + g 0 + b0 . 3 êë cúû v0 = 1 c, or v0 = v 0 = 3 é r0 - 1 c ù ê g - 31 cú . s0 = p0 - v 0 = ê 0 3 ú êë b0 - 1 c úû 3 2 3 3 v0 c. p0 s0 é r0 ù p 0 = êê g 0 úú . êë b0 úû 2 2 s0 = s 0 = (r0 - 1 c) + ( g 0 - 1 c ) + (b0 - 1 c) . 3 3 3 2011-09-21 1999-2011 by Richard Alan Peters II 91 78 RGB to HSV Conversion écù b0 . v 0 = 1 êê c úú , where c = r0 + g 0 +… either def. of v c/3 is the usual value3 image intensity (the can be used, but c/3 c êëg, úû& b) … average of r, has the advantage 0 v0 = 1 c, or v0 = v 0 = 3 3 3 … c √3/3 is the length1of the 0 3 value vector… 1 0 3 1 0 3 ér - cù s0 = p 0 - v 0 = êê g - cúú . êë b - c úû 2 c. of being in the range [0 , 255]. v0 p0 s0 é r0 ù p 0 = êê g 0 úú . êë b0 úû 2 2 s0 = s 0 = (r0 - 1 c) + ( g 0 - 1 c ) + (b0 - 1 c) . 3 3 3 2011-09-21 1999-2011 by Richard Alan Peters II 79 RGB to HSV Conversion écù écù c é 2 ù x = R - v 0 = êê0úú - 1 êêcúú = êê-1úú 3 êë0úû êëcúû 3 êë-1úû x v0 é r0 - 1 c ù ê g - 31 c ú . s0 = p0 - v 0 = ê 0 3 ú êë b0 - 1 c úû 3 æ s0 ⋅ x h0 = (s0 , x) = cos ç ç çs x è0 -1 2011-09-21 p0 s0 ö ÷. ÷ ÷ ÷ ø 1999-2011 by Richard Alan Peters II 83 80 RGB to HSV Conversion In summary, v0 = 1 c, or v0 = v 0 = 3 3 3 c, x where c = r0 + g0 + b0, v0 2 2 2 s0 = (r0 - c) + ( g 0 - c) + (b0 - c) , 1 3 1 3 1 3 p0 s0 and æ s0 ⋅ x h0 = cos ç ç çs x è0 -1 2011-09-21 ö ÷. ÷ ÷ ÷ ø Usually, s0 is normalized to lie in the interval (0,1) and h0 is shifted to lie in (0,2π). 1999-2011 by Richard Alan Peters II 81 Normalizing the Saturation The scalar saturation, 2 2 2 s0 = (r0 - 1 c ) + ( g 0 - 1 c ) + (b0 - 1 c ) , 3 3 3 x 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 T T v0 p0 s0 T s max = [ 255 0 0 ] - 1 [ 255 255 255] = [170 -85 -85] , 3 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 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ù ˆ x = êê0úú , êë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 = s cos ( h) x + s sin ( h) y + 0 v . 2011-09-21 1999-2011 by Richard Alan Peters II 84 HSV to RGB Conversion If s is in the range 0 to 1, then it must be denormalized first by multiplying by smax. Given values h, s, and v, where h Î [ 0, 2p) , s Î [ 0, smax ], and v Î [ 0, 255], ˆ These are the coordinates of s with respect to ˆ , ˆ , & ˆ. xy v the saturation vector is [ s ] xyv é s cos (h)ù ê ú = ê s sin (h) ú , ê0ú ë û xyv ˆ ˆ This s unit as a linear with respectisto writtenvectors x, y, ˆy combination of vectors x, ˆ, & ˆ. v and v, in the equivalue plane. ˆ ˆ ˆ ˆ s = s cos ( h) x + s sin ( h) y + 0 v . 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. ˆ [ s ]rgb = [ r0 g 0 b0 ] ˆ ˆ ˆ ˆ T ˆ ˆ ˆ ˆ s « r0 r + g 0 g + b0 b, ˆ ˆ ˆ s « s cos ( h) x + s sin ( h) y + 0 v . 2011-09-21 We need to find r0, g0, & b0. 1999-2011 by Richard Alan Peters II 86 HSV to RGB Conversion 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. ˆ ˆ ˆ ˆ s « r0 r + g 0 g + b0 b, ˆ ˆ ˆ ˆ ˆ s « s cos ( h) x + s sin ( h) y + 0 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. ˆ ˆ ˆ T [ 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 ˆˆ ˆ 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, ˆ ˆ ˆ ˆ ˆ ˆ ˆ ˆ ˆ [ x ]rgb= A[ x ] xyv , [ y ]rgb= A[ y ] xyv , [ v ]rgb= A[ v ] xyv . ˆ ˆ Then, [ s ]rgb = A[ s ] xyv ˆ ˆ ˆ = A éêë s cos ( h)[ x ] xyv + s sin ( h)[ y ] xyv + 0 [ v ] xyv ùúû ˆ ˆ ˆ ˆ = s cos ( h) A[ x ] xyv + s sin ( h) A[ y ] xyv + 0 A[ v ] xyv ˆ ˆ ˆ = s cos ( h)[ x ]rgb + s sin ( h)[ y ]rgb + 0 [ v ]rgb . 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ù ˆ x = êê0úú , êë0úû ˆ ˆ é 0ù é 0ù ê1ú , and v = ê 0ú , ˆ ˆ êú y=ê ú êë 0úû êë1úû ˆ So that, é1ù é0ù é0ù ˆ ˆ ˆ [ x ]rgb= A ê0ú , [ y ]rgb= A ê1ú , [ v ]rgb= A ê0ú. ˆ ë0û ë0û ˆ ë1û But that implies, ˆ ˆ ˆ ˆ A = éêë [ x ]rgb [ y ]rgb [ v ]rgb ùúû . 2011-09-21 1999-2011 by Richard Alan Peters II 89 HSV to RGB Conversion ˆ 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 g ˆ ˆ and b components. y is the cross ˆ product of v ˆ with x. ˆ ˆ 6 ˆ [ x ]rgb = 6 é 2ù ê -1ú êú êë -1úû ˆ ˆ ˆ ˆ ˆ ˆ [ y ]rgb = [ v ]rgb´[ x ]rgb 2 = 2 2011-09-21 ˆ éù 3 ê1ú ˆ [ v ]rgb = ê1ú 3 ê1ú ëû é 0ù ê1ú êú ëê -1ûú 1999-2011 by Richard Alan Peters II ˆ 90 HSV to RGB Conversion Therefore, the rotation matrix is and é2 0 6 êê -1 3 A= 6 êê -1 - 3 ë 2 ùú 2ú ú 2ú û é2ù [ s ]rgb = s cos ( h) ê-1ú + s ë-1û é2ù = s 66 cos ( h) ê-1ú + s ë-1û 6 6 v0 é0ù sin ( h) ê 1 ú + 0 ë-1û é0ù 2 sin ( h) ê 1 ú. 2 ë-1û 2 2 éù êú ëû 31 31 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 2011-09-21 1999-2011 by Richard Alan Peters II original 92 Saturation Adjustment 2011-09-21 1999-2011 by Richard Alan Peters II saturation + 50% 93 Saturation Adjustment 2011-09-21 1999-2011 by Richard Alan Peters II original 94 Saturation Adjustment 2011-09-21 1999-2011 by Richard Alan Peters II saturation - 50% 95 Hue Shifting 2011-09-21 R→ Y→ G→ C→ B→ M→ R Y G C B M 1999-2011 by Richard Alan Peters II original 96 Hue Shifting 2011-09-21 R→ Y→ G→ C→ B→ M→ Y G C B M R 1999-2011 by Richard Alan Peters II hue + 60° 97 Hue Shifting 2011-09-21 R→ Y→ G→ C→ B→ M→ G C B M R Y 1999-2011 by Richard Alan Peters II hue + 120° 98 Hue Shifting 2011-09-21 R→ Y→ G→ C→ B→ M→ C B M R Y G 1999-2011 by Richard Alan Peters II hue + 180° 99 Hue Shifting 2011-09-21 R→ Y→ G→ C→ B→ M→ B M R Y G C 1999-2011 by Richard Alan Peters II hue + 240° 100 Hue Shifting 2011-09-21 R→ Y→ G→ C→ B→ M→ M R Y G C B 1999-2011 by Richard Alan Peters II hue + 300° 101 Hue Shifting 2011-09-21 R→ Y→ G→ C→ B→ M→ R Y G C B M 1999-2011 by Richard Alan Peters II hue + 360° = original 102 Hue Shifting 2011-09-21 R→ Y→ G→ C→ B→ M→ R Y G C B M 1999-2011 by Richard Alan Peters II original 103 Hue Shifting 2011-09-21 R→ Y→ G→ C→ B→ M→ Y G C B M R 1999-2011 by Richard Alan Peters II hue + 60° 104 Hue Shifting 2011-09-21 R→ Y→ G→ C→ B→ M→ G C B M R Y 1999-2011 by Richard Alan Peters II hue + 120° 105 Hue Shifting 2011-09-21 R→ Y→ G→ C→ B→ M→ C B M R Y G 1999-2011 by Richard Alan Peters II hue + 180° 106 Hue Shifting 2011-09-21 R→ Y→ G→ C→ B→ M→ B M R Y G C 1999-2011 by Richard Alan Peters II hue + 240° 107 Hue Shifting 2011-09-21 R→ Y→ G→ C→ B→ M→ M R Y G C B 1999-2011 by Richard Alan Peters II hue + 300° 108 Hue Shifting 2011-09-21 R→ Y→ G→ C→ B→ M→ R Y G C B M 1999-2011 by Richard Alan Peters II hue + 360° = original 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 J (r , c)ù é R I (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 I (r , c)úû ï ï ï ï ëI û ëJ û î þ 2011-09-21 1999-2011 by Richard Alan Peters II 110 Linear Transformation of Color green cyan yellow original blue 2011-09-21 1999-2011 by Richard Alan Peters II red magenta 111 Color Vector Space Operators Linear operators are matrix multiplications é r1 ù é a11 a12 a13 ù é r0 ù ê g ú = êa a a ú ê g ú ê 1 ú ê 21 22 23 ú ê 0 ú ëê b1 ûú ëê a31 a32 a33 ûú ëê b0 ûú é (r / 255)1/gr ù é r1 ù ê0 ê g ú = 255 ⋅ ê( g / 255)1/g g úú ê 1ú ê0 ú 1/gb êë b1 úû ê (b0 / 255) ú ë û 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 2011-09-21 125 75 175 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 2011-09-21 125 75 175 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 2011-09-21 125 75 175 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ú ê 10 0 b1/b0 úû êë b0 úû ëê b1 úû êë 0 175 150 225 2011-09-21 125 75 175 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 3×3 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 é rI ù image I (r , c) = êê g I úú and êëbI úû é 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 úû é rJ ù image J (r , c) = êê g J úú , êëbJ úû 2011-09-21 J (r , c) = AI (r , c) , or 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. ì é rJ , k ù ü n ï ï ïê ï ê g úú ï ï í J, k ý ïê ï ê bJ, k úú ï ï ïë û ïk = 1 î þ known wrong colors 2011-09-21 é 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 ì é rI , k ù ï n ü ï ïê ï ê g úú ï ï í I, k ý ïê ï ê bI, k úú ï ï ïë û ïk = 1 î þ 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 2 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 3×n matrices such that -1 Y » A X, where A is the 3×3 matrix that we want to find. 2011-09-21 1999-2011 by Richard Alan Peters II 122 Color Correction The linearly optimal solution is the least mean squared solution that is given by B = A = YX ( XX -1 T T -1 ) 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 2011-09-21 1999-2011 by Richard Alan Peters II 123 Color Correction input colors (to be changed): ù é ér ù r ù ù éê gbú êê ú úú The linearly optimal solution isg theêêégleastéër mean ùûsquared ú êê ú úú ⋅ê êê ú ê úú ê b ûù úú b úû b úû ûú ëê ëé r g êë ëê êë û solution that is given by J, 1 J, n J, 1 J, n B, 1 J, n J, 1 J, 1 J, 1 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: 2011-09-21 é é rI , 1 ù é rI , n ù ù êê ú ê úú ê ê gI , 1 ú ê gI , n ú ú êê ú ê úú êë êë bI , 1 úû êë bI , n úû úû 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 Color Correction input colors (to be changed): ù é ér ù r ù ù éê gbú êê ú úú The linearly optimal solution isg theêêégleastéër mean ùûsquared ú êê ú úú ⋅ê êê ú ê úú ê b ûù úú b úû b úû ûú ëê ëé r g êë ëê êë û solution that is given by J, 1 J, n J, 1 J, n B, 1 J, n J, 1 J, 1 J, 1 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: 2011-09-21 é é rI , 1 ù é rI , n ù ù êê ú ê úú ê ê gI , 1 ú ê gI , n ú ú êê ú ê úú êë êë bI , 1 úû êë bI , n úû úû 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 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 1999-2011 by Richard Alan Peters II 127 Color Mapping 1 17 121 171 17 122 114 Original Image 2011-09-21 “Aged” Image 1999-2011 by Richard Alan Peters II 128 Color Mapping 2 222 222 218 222 222 185 Original Image 2011-09-21 “Aged” Image 1999-2011 by Richard Alan Peters II 129 Color Mapping 3 240 171 160 240 171 103 Original Image 2011-09-21 “Aged” Image 1999-2011 by Richard Alan Peters II 130 Color Mapping 4 240 230 166 236 227 106 Original Image 2011-09-21 “Aged” Image 1999-2011 by Richard Alan Peters II 131 Color Transformations 222 222 218 17 121 171 240 171 160 222 222 185 240 230 166 17 122 114 240 171 103 236 227 106 The aging process was a transformation, Φ, that mapped: ìé 17 ù ü é 17 ù ï ï ê122ú = F ïê121ú ï íê ú ý êú ïê171ú ï êë114úû ïë û ï ï ï î þ 2011-09-21 ìé 222ù ü é 222ù ï ï ê 222ú = F ïê 222ú ï íê ý ê ú ïê 218úú ï êë185 úû ïë ï ï ûï î þ ìé 240ù ü é 240ù ï ï ê 171ú = F ïê 171ú ï íê ý ê ú ïê160 úú ï êë103 úû ïë ï ï ûï î þ 1999-2011 by Richard Alan Peters II ìé 240ù ü é 236ù ï ï ê 227ú = F ïê 230ú ï íê ý ê ú ïê166 úú ï êë106 úû ïë ï ï ûï î þ 132 Color Transformations 222 222 218 17 121 171 240 171 160 222 222 185 240 230 166 17 122 114 240 171 103 236 227 106 To undo the process we need to find, Φ-1, that maps: ìé 17 ù ü é 17 ù ï ï ê121ú = F-1 ïê122ú ï íê ú ý êú ïê114ú ï êë171úû ïë û ï ï ï î þ 2011-09-21 ì ü é 222ù ïé 222ù ï ê 222ú = F-1 ïê 222ú ï íê ý ê ú ïê185 úú ï êë 218úû ïë ï ï ûï î þ ìé 240ùü é 240ù ï ï ê 171ú = F-1 ïê171úï íê ý ê ú ïê103 úúï êë160 úû ïë ï ï ûï î þ 1999-2011 by Richard Alan Peters II ìé 236ù ü é 240ù ï ï ê 230ú = F-1 ïê 227ú ï íê ý ê ú ïê106 úú ï êë166 úû ïë ï ï ûï î þ 133 Correction Using 3 Mappings B = A-1 = YX-1 é 222 17 240ù X = êê 222 122 171úú êë185 114 103 úû 2011-09-21 é 222 17 240ù Y = êê 222 121 171úú êë 218 171 160 úû 1999-2011 by Richard Alan Peters II 134 Correction Using 3 Mappings original B = A-1 = YX-1 é 222 17 240ù X = êê 222 122 171úú êë185 114 103 úû 2011-09-21 corrected é 222 17 240ù Y = êê 222 121 171úú êë 218 171 160 úû 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 úû 2011-09-21 é 222 17 240ù Y = êê 222 121 230úú êë 218 171 166 úû 1999-2011 by Richard Alan Peters II 136 Another Correction Using 3 Mappings original B = A-1 = YX-1 é 222 17 236ù X = êê 222 122 227úú êë185 114 106 úû 2011-09-21 corrected é 222 17 240ù Y = êê 222 121 230úú êë 218 171 166 úû 1999-2011 by Richard Alan Peters II 137 Correction Using All 4 Mappings B=A -1 = YX ( XX é 222 17 236 240ù X = êê 222 122 227 171úú êë185 114 106 103 úû 2011-09-21 T T -1 ) é 222 17 240 240ù Y = êê 222 121 230 171úú êë 218 171 166 160 úû 1999-2011 by Richard Alan Peters II 138 Correction Using All 4 Mappings B=A original -1 = YX ( XX é 222 17 236 240ù X = êê 222 122 227 171úú êë185 114 106 103 úû 2011-09-21 T T -1 ) corrected é 222 17 240 240ù Y = êê 222 121 230 171úú êë 218 171 166 160 úû 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])); R = number of rows in image C = number of columns in image n = number of pixels to select >> idx = [rr;rc]; >> Y(:,1) = diag(I(rr,rc,1)); >> Y(:,2) = diag(I(rr,rc,2)); >> Y(:,3) = diag(I(rr,rc,3)); rand([1 n]) : 1 × n matrix of random numbers between 0 and 1. >> X(:,1) = diag(J(rr,rc,1)); >> X(:,2) = diag(J(rr,rc,2)); >> X(:,3) = diag(J(rr,rc,3)); 2011-09-21 diag(I(rr,rc,1)): vector from main diagonal of matrix I(rr,rc,1). 1999-2011 by Richard Alan Peters II 140 Correction Using 128 Mappings B=A -1 = YX ( XX é111 235ù X = êê103 233úú êë 22 210úû 2011-09-21 T T -1 ) é111 234ù Y = êê102 233úú êë 71 229úû 1999-2011 by Richard Alan Peters II 141 Correction Using 128 Mappings B=A -1 = YX ( XX é111 235ù X = êê103 233úú êë 22 210úû 2011-09-21 T T -1 ) é111 234ù Y = êê102 233úú êë 71 229úû 1999-2011 by Richard Alan Peters II 142 Correction Using 128 Mappings B=A original -1 = YX ( XX é111 235ù X = êê103 233úú êë 22 210úû 2011-09-21 T T -1 ) corrected é111 234ù Y = êê102 233úú êë 71 229úû 1999-2011 by Richard Alan Peters II 143 for comparison: Correction Using 4 Mappings B=A original -1 = YX ( XX é 222 17 236 240ù X = êê 222 122 227 171úú êë185 114 106 103 úû 2011-09-21 T T -1 ) corrected é 222 17 240 240ù Y = êê 222 121 230 171úú êë 218 171 166 160 úû 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 ...
View Full Document

This note was uploaded on 12/06/2011 for the course EECE 253 taught by Professor Alanpeters during the Summer '07 term at Vanderbilt.

Ask a homework question - tutors are online