EECE253_03_PointProcessing

EECE253_03_PointProcessing - 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: Lecture Notes: The Point Processing of Images 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. Point Processing of Images 2011-09-06 2011-09-06 In a digital image, point = pixel. Point processing transforms a pixel’s value as function of its value alone; it does not depend on the values of the pixel’s neighbors. 2000-2011 Richard Alan Peters II 2 Point Processing of Images 2011-09-06 2011-09-06 Brightness and contrast adjustment Gamma correction Histogram equalization Histogram matching Color correction. 2000-2011 Richard Alan Peters II 3 Point Processing - gamma - brightness original + brightness + gamma histogram mod - contrast original + contrast histogram EQ 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 4 The Histogram of a Grayscale Image Let I be a 1-band (grayscale) image. I(r,c) is an 8-bit integer between 0 and 255. Histogram, hI, of I: – – – 2011-09-06 2011-09-06 a 256-element array, hI hI(g), for g = 1, 2, 3, …, 256, is an integer hI(g) = number of pixels in I that have value g-1. 2000-2011 Richard Alan Peters II 5 2011-09-06 2011-09-06 lower RHC: number of pixels with intensity g 16-level (4-bit) image 2000-2011 Richard Alan Peters II black marks pixels with intensity g The Histogram of a Grayscale Image 6 The Histogram of a Grayscale Image Black marks pixels with intensity g Plot of histogram: number of pixels with intensity g 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 7 The Histogram of a Grayscale Image Black marks pixels with intensity g Plot of histogram: number of pixels with intensity g 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 8 The Histogram of a Grayscale Image Luminosity 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 9 The Histogram of a Color Image If I is a 3-band image (truecolor, 24-bit) then I(r,c,b) is an integer between 0 and 255. Either I has 3 histograms: – – – or 1 vector-valued histogram, h(g,1,b) where – – – 2011-09-06 2011-09-06 hR( g +1) = # of pixels in I(:,:,1) with intensity value g hG( g +1) = # of pixels in I(:,:,2) with intensity value g hB( g +1) = # of pixels in I(:,:,3) with intensity value g h( g +1,1,1) = # of pixels in I with red intensity value g h( g +1,1,2) = # of pixels in I with green intensity value g h( g +1,1,3) = # of pixels in I with blue intensity value g 2000-2011 Richard Alan Peters II 10 The Histogram of a Color Image Luminosity There is one histogram per color band R, G, & B. Luminosity histogram is from 1 band = (R+G+B)/3 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 11 The Histogram of a Color Image 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 12 Value or Luminance Histograms The value histogram of a 3-band (truecolor) image, I, is the histogram of the value image, 1 V (r , c) = [ R (r , c) + G (r , c) + B (r , c)] 3 Where R, G, and B are the red, green, and blue bands of I. The luminance histogram of I is the histogram of the luminance image, L (r , c) = 0.299 ⋅ R (r , c) + 0.587 ⋅ G (r , c) + 0.114 ⋅ B (r , c) 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 13 Value Histogram Value image, V. 2011-09-06 2011-09-06 Histogram of the value image. 2000-2011 Richard Alan Peters II 14 Luminance Histogram Luminance image, L. 2011-09-06 2011-09-06 Histogram of the luminance image. 2000-2011 Richard Alan Peters II 15 Value Histogram vs. Average of R,G,&B Histograms R,G,B,&V histograms 2011-09-06 2011-09-06 V & avg. of R,G,&B histograms 2000-2011 Richard Alan Peters II 16 Multi-Band Histogram Calculator in Matlab % Multi-band histogram calculator function h=histogram(I) [R C B]=size(I); % allocate the histogram h=zeros(256,1,B); % range through the intensity values for g=0:255 h(g+1,1,:) = sum(sum(I==g)); % accumulate end return; 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 17 Multi-Band Histogram Calculator in Matlab % Multi-band histogram calculator Loop through all intensity levels (0-255) function h=histogram(I) Tag the elements that have value g. The result is an RxCxB logical array that [R C B]=size(I); has a 1 wherever I(r,c,b) = g and 0’s everywhere else. Compute the number of ones in each band of % allocate the histogram the image for intensity g. h=zeros(256,1,B); Store that value in the 256x1xB histogram at values % range through the intensity h(g+1,1,b). for g=0:255 h(g+1,1,:) = sum(sum(I==g)); % accumulate end If B==3, then h(g+1,1,:) contains return; the number of pixels in 3 numbers: bands 1, 2, & 3 that have intensity g. 2011-09-06 2011-09-06 sum(sum(I==g)) computes one number for each band in the image. 2000-2011 Richard Alan Peters II 18 Point Ops via Functional Mappings Image: I Φ, point operator Input Pixel: I(r,c) J J = F[ I ] Output function, f J(r,c) If I (r , c) = g and f ( g ) = k The transformation of image I into image J is then J (r , c) = k . accomplished by replacing each input intensity, g, with a specific output intensity, k, at every location (r,c) where I(r,c) = g. The rule that associates k with g is usually specified with a function, f, so that f (g) = k. 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 19 Point Ops via Functional Mappings One-band Image Three-band Image 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 20 Point Ops via Functional Mappings One-band Image Either all 3 bands are mapped through the same function, f, or … Three-band Image … each band is mapped through a separate function, fb. 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 21 Point Operations using Look-up Tables … then the LUT that implements f is a 256x1 array whose (g +1)th value is k = f (g). A look-up table (LUT) implements a functional mapping. If k = f ( g ), for g = 0,, 255, and if k takes on values in {0,, 255}, 2011-09-06 2011-09-06 To remap a 1-band image, I, to J : 2000-2011 Richard Alan Peters II 22 Point Operations using Look-up Tables If I is 3-band, then a) each band is mapped separately using the same LUT for each band or b) each band is mapped using different LUTs – one for each band. 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 23 0 output value 127 255 Point Operations = Look-up Table Ops 0 2011-09-06 2011-09-06 127 input value 255 E.g.: index value ... ... 64 101 68 102 103 69 70 104 105 70 106 71 ... ... 2000-2011 Richard Alan Peters II input output 24 Look-Up Tables 2011-09-06 2011-09-06 cell index .0 . . 32 . . . 128 . . . 255 a pixel with this value .0 . . 64 . . . 128 . . . output 255 192 . . . 224 . . . contents input 2000-2011 Richard Alan Peters II is mapped to this value 25 How to Generate a Look-Up Table For example: Let a = 2. Let x ∈{0,,255} σ (x ; a ) = 255 1 + e − a ( x −127 ) / 32 Or in Matlab: a = 2; x = 0:255; LUT = 255 ./ (1+exp(-a*(x-127)/32)); 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II This is just one example. 26 Point Processes: Original Image Kinkaku-ji (金閣寺 Temple of the Golden Pavilion), also known as Rokuon-ji (鹿苑寺 Deer Garden Temple), is a Zen Buddhist temple in Kyoto, Japan. Luminance Histogram Photo by Richard Alan Peters II, August 1993. 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 27 127 255 Point Processes: Increase Brightness { I (r , c, b) + g , if I (r , c, b) + g < 256 if I (r , c, b) + g > 255 255, g saturation point 0 J ( r , c , b) = g ³ 0 and b Î { 1, 2,3 } is the band index. 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 0 127 255 transform mapping 28 255 Point Processes: Decrease Brightness zero point 127 255-g { if I (r , c, b) - g < 0 0, I (r , c, b) - g , if I (r , c, b) - g > 0 0 J ( r , c , b) = g ³ 0 and b Î { 1, 2,3 } is the band index. 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 0 127 255 transform mapping 29 255 Point Processes: Decrease Contrast s is the where 0 £ a < 1.0, center of s Î {0,1, 2, , 255} , and the contrast function. b Î { 1, 2,3 } . 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 0 T( r , c , b ) = a [ I ( r , c , b) - s ] + s , 127 Here, s = 127 0 127 255 transform mapping 30 255 Point Processes: Increase Contrast zero point ì0, ï ï J (r , c, b) = íT ( r , c, b) , ï255, ï ï î a > 1, s Î {0,, 255} , 2011-09-06 2011-09-06 if T (r , c, b) < 0, if 0 £ T (r , c, b) £ 255, if T (r , c, b) > 255. b Î { 1, 2 ,3 } 2000-2011 Richard Alan Peters II sat. point 0 T ( r , c , b ) = a [ I ( r , c , b) - s ] + s 127 Here, s = 127 0 127 255 transform mapping 31 zero point 127 MJ 255 Point Processes: Contrast Stretch Let mI = min [I (r , c)] , M I = max [I (r , c)], center point Then, J (r , c) = ( M J - mJ ) 2011-09-06 2011-09-06 I (r , c) - mI + mJ . M I - mI 2000-2011 Richard Alan Peters II mJ 0 mJ = min [ J (r , c)] , M J = max [ J (r , c)]. sat. point 0 127 mI MI 255 transform mapping 32 histograms Information Loss from Contrast Adjustment orig lo-c hi-c 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 33 Information Loss from Contrast Adjustment orig lo-c hi-c orig lo-c abbreviations: original low-contrast high-contrast restored difference lo-c rest orig diff hi-c hi-c rest 2011-09-06 2011-09-06 difference between original and restored low-contrast diff 2000-2011 Richard Alan Peters II difference between original and restored high-contrast 34 127 255 Point Processes: Increased Gamma é I ( r , c) ù g ú J ( r , c) = 255 ⋅ ê for g > 1.0 êë 255 úû 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 0 1 0 127 255 transform mapping 35 127 255 Point Processes: Decreased Gamma é I ( r , c) ù g ú J ( r , c) = 255 ⋅ ê for g < 1.0 êë 255 úû 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 0 1 0 127 m M 255 transform mapping 36 Gamma Correction: Effect on Histogram 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 37 The Probability Density Function of an Image pdf [lower case] 255 Let A = å hI k ( g + 1) . g =0 Note that since hI k ( g + 1) is the number of pixels in I k (the kth color band of image I ) with value g , A is the number of pixels in I. That is if I is R rows by C columns then A = R ´C. Then, pIk ( g + 1) = 1 hIk ( g + 1) A This is the probability that an arbitrary pixel from Ik has value g. is the graylevel probability density function of I k . 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 38 The Probability Density Function of an Image • pband(g+1) is the fraction of pixels in (a specific band of) an image that have intensity value g. • pband(g+1) is the probability that a pixel randomly selected from the given band has intensity value g. • Whereas the sum of the histogram hband(g+1) over all g from 1 to 256 is equal to the number of pixels in the image, the sum of pband(g+1) over all g is 1. • pband is the normalized histogram of the band. 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 39 The Probability Distribution Function of an Image Let q = [q1 q2 q3] = I(r,c) be the value of a randomly selected pixel from I. Let g be a specific graylevel. The probability that qk ≤ g is given by PDF [upper case] g g 1g PI k ( g + 1) = å pIk (g + 1) = å hI (g +1) = A g =0 k g =0 åh g =0 255 åh g =0 where hIk(γ +1) is the histogram of the kth band of I. 2011-09-06 2011-09-06 Ik Ik (g + 1) , (g + 1) This is the probability that any given pixel from Ik has value less than or equal to g. 2000-2011 Richard Alan Peters II 40 The Probability Distribution Function of an Image Let q = [q1 q2 q3] = I(r,c) be the value of a randomly selected pixel from I. Let g be a specific graylevel. The probability that qk g is given by Also called CDF for “Cumulative Distribution Function”. g g 1g PI k ( g + 1) = å pIk (g + 1) = å hI (g +1) = A g =0 k g =0 åh g =0 255 åh g =0 where hIk(γ +1) is the histogram of the kth band of I. 2011-09-06 2011-09-06 Ik Ik (g + 1) , (g + 1) This is the probability that any given pixel from Ik has value less than or equal to g. 2000-2011 Richard Alan Peters II 41 A.k.a. Cumulative Distribution Function. The Probability Distribution Function of an Image • Pband(g+1) is the fraction of pixels in (a specific band of) an image that have intensity values less than or equal to g. • Pband(g+1) is the probability that a pixel randomly selected from the given band has an intensity value less than or equal to g. • Pband(g+1) is the cumulative (or running) sum of pband(g+1) from 0 through g inclusive. • Pband(1) = pband(1) and Pband(256) = 1; Pband(g+1) is nondecreasing. Note: the Probability Distribution Function (PDF, capital letters) and the Cumulative Distribution Function (CDF) are exactly the same things. Both PDF and CDF will refer to it. However, pdf (small letters) is the density function. 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 42 Point Processes: Histogram Equalization Task: remap image I so that its histogram is as close to constant as possible Let PI (g + 1) be the cumulative (probability) distribution function of I. Then J has, as closely as possible, the correct histogram if J (r , c, b) = 255 ⋅ PI [I (r , c, b) + 1]. The CDF itself is used as the LUT. 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II all bands processed similarly 43 Point Processes: Histogram Equalization Luminosity before J (r , c, b) = 255⋅ PI ( g + 1) , g = I (r , c, b) , b Î {1, 2,3} . 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II after 44 Histogram EQ The CDF (cummulative distribution) is the pdf LUT for remapping. CDF 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 45 Histogram EQ The CDF (cummulative distribution) is the pdf LUT for remapping. LUT 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 46 Histogram EQ The CDF (cummulative distribution) is the pdf LUT for remapping. LUT 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 47 Histogram EQ 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 48 Point Processes: Histogram Equalization Task: remap image I with min = mI and max = MI so that its histogram is as close to constant as possible and has min = mJ and max = MJ . Let PI (g + 1) be the cumulative (probability) distribution function of I. Then J has, as closely as possible, the correct histogram if Using intensity extrema 2011-09-06 2011-09-06 PI [I (r , c) + 1]- PI (mI + 1) J (r , c) = ( M J - mJ ) + mJ . PI ( M I + 1) - PI (mI + 1) 2000-2011 Richard Alan Peters II 49 Point Processes: Histogram Matching Task: remap image I so that it has, as closely as possible, the same histogram as image J. Because the images are digital it is not, in general, possible to make hI ≡ hJ . Therefore, pI ≡ pJ . Q: How, then, can the matching be done? A: By matching percentiles. 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 50 Matching Percentiles … assuming a 1-band image or a single band of a color image. Recall: • The CDF of image I is such that 0 ≤ PI ( gI ) ≤ 1. • PI ( gI +1) = c means that c is the fraction of pixels in I that have a value less than or equal to gI . • 100c is the percentile of pixels in I that are less than or equal to gI . To match percentiles, replace all occurrences of value gI in image I with the value, gJ, from image J whose percentile in J most closely matches the percentile of gI in image I. 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 51 … assuming a 1-band image or a single band of a color image. Matching Percentiles So, to create an image, K, from image I such that K has nearly the same CDF as image J do the following: If I(r,c) = gI then let K(r,c) = gJ where gJ is such that PJ ( gJ ) PI ( gI ) PI (gI) > PJ (gJ -1) AND PI (gI) ≤ PJ (gJ). gI 2011-09-06 2011-09-06 Example: I(r,c) = 5 PI (5) = 0.65 PJ (9) = 0.56 PJ (10) = 0.67 K(r,c) = 10 2000-2011 Richard Alan Peters II gJ 52 Histogram Matching Algorithm This directly matches image I to image J. [R,C] = size(I); K = zeros(R,C); gJ = mJ; for gI = mI to MI while g J < 255 AND PI ( gI + 1) < 1 AND PJ ( g J + 1) < PI ( g I + 1) g J = g J + 1; end K = K + [ g J ⋅ ( I == g I )] end 2011-09-06 2011-09-06 … assuming a 1-band image or a single band of a color image. 2000-2011 Richard Alan Peters II PI ( g I + 1) : CDF of I PJ ( g J + 1) : CDF of J. mJ = min J, M J = max J, mI = min I, M I = max I. Better to use a LUT. See slide 58. 53 Example: Histogram Matching Image pdf Image with 16 intensity values g 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 54 Example: Histogram Matching CDFI(g) Image CDF * g *a.k.a Cumulative Distribution Function, CDFI. 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 55 Example: Histogram Matching Target pdf Target with 16 intensity values g 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 56 Example: Histogram Matching CDFI(g) Target CDF * g *a.k.a Cumulative Distribution Function, CDFJ. 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 57 Histogram Matching with a Lookup Table The algorithm on slide 53 matches one image to another directly. Often it is faster or more versatile to use a lookup table (LUT). Rather than remapping each pixel in the image separately, one can create a table that indicates to which target value each input value should be mapped. Then K = LUT[I+1] In Matlab if the LUT is a 256 × 1 matrix with values from 0 to 255 and if image I is of type uint8, it can be remapped with the following code: K = uint8(LUT(I+1)); 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 58 LUT Creation Image CDF Target CDF LUT 10 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 59 Look Up Table for Histogram Matching LUT = zeros(256,1); gJ = 0; This creates a look-up table which can then be used to remap the image. for gI = 0 to 255 while PJ ( g J + 1) < PI ( g I + 1) AND g J < 255 g J = g J + 1; end LUT ( g I + 1) = g J ; end 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 60 PJ ( g ) PI ( g ) Input & Target CDFs, LUT and Resultant CDF Input Target LUT g PK ( g ) LUT ( g ) g g 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II Result g 61 Example: Histogram Matching original 2011-09-06 2011-09-06 target 2000-2011 Richard Alan Peters II remapped 62 Probability Density Functions of a Color Image Atlas-Mercury 2011-09-06 2011-09-06 red pdf green pdf 2000-2011 Richard Alan Peters II blue pdf luminosity pdf 63 Cumulative Distribution Functions (CDF) red CDF green CDF 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II blue CDF luminosity CDF 64 Probability Density Functions of a Color Image TechnoTrousers 2011-09-06 2011-09-06 red pdf green pdf 2000-2011 Richard Alan Peters II blue pdf luminosity pdf 65 Cumulative Distribution Functions (CDF) red CDF green CDF 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II blue CDF luminosity CDF 66 Remap an Image to have the Lum. CDF of Another original 2011-09-06 2011-09-06 target 2000-2011 Richard Alan Peters II luminosity remapped 67 CDFs and the LUT Atlas-Mercury Luminosity CDF TechnoTrousers Luminosity CDF LUT (Luminosity) Atlas-Mercury to TechnoTrousers Atlas-Mercury Remapped Luminosity CDF 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 68 Effects of Luminance Remapping on pdfs Before 2011-09-06 2011-09-06 After 2000-2011 Richard Alan Peters II 69 Effects of Luminance Remapping on CDFs Before 2011-09-06 2011-09-06 After 2000-2011 Richard Alan Peters II 70 Remap an Image to have the rgb CDF of Another original 2011-09-06 2011-09-06 target 2000-2011 Richard Alan Peters II R, G, & B remapped 71 CDFs and the LUTs Atlas-Mercury Red PDF Atlas-Mercury Green PDF Atlas-Mercury Blue PDF TechnoTrousers Red PDF TechnoTrousers Green PDF TechnoTrousers Blue PDF LUT (Red) Atlas-Mercury to TechnoTrousers LUT (Green) Atlas-Mercury to TechnoTrousers LUT (Blue) Atlas-Mercury to TechnoTrousers Atlas-Mercury RGB Remapped Red PDF Atlas-Mercury RGB Remapped Green PDF Atlas-Mercury RGB Remapped Blue PDF 2011-09-06 2011-09-06 2000-2011 Richard Alan Peters II 72 Effects of RGB Remapping on pdfs Before 2011-09-06 2011-09-06 After 2000-2011 Richard Alan Peters II 73 Effects of RGB Remapping on CDFs Before 2011-09-06 2011-09-06 After 2000-2011 Richard Alan Peters II 74 Remap an Image: original 2011-09-06 2011-09-06 G&B R To Have Two of its Color pdfs Match the Third B&R 2000-2011 Richard Alan Peters II G R&G B 75 ...
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