1 / 83

Introduction to Computer Vision Lecture 13

Introduction to Computer Vision Lecture 13. Roger S. Gaborski. 1. Pineapple and Orange Examples. Segmenting Objects. Histograms. A histogram is just a method for summarizing data, for example, gray level pixel values Can also summarize edge data. GRAY PIXEL VALUE HISTOGRAM.

calix
Télécharger la présentation

Introduction to Computer Vision Lecture 13

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Computer VisionLecture 13 Roger S. Gaborski 1

  2. Pineapple and Orange Examples • Segmenting Objects Roger S. Gaborski

  3. Roger S. Gaborski

  4. Histograms • A histogram is just a method for summarizing data, for example, gray level pixel values • Can also summarize edge data Roger S. Gaborski

  5. GRAY PIXEL VALUE HISTOGRAM >> imP1=double(imread('Pineapple1.jpg’)); >> figure, imshow(imP1) >> %Convert to Gray scale >> imP1gray = rgb2gray(imP1); >> figure, imshow(imP1gray) >>%Minimum and Maximum code values >> MAXcode = max(imP1gray(:)) MAXcode = 214 >> MINcode = min(imP1gray(:)) MINcode = 1 >>%Histogram of Gray Level Pixel Values Roger S. Gaborski

  6. Edges >> imP1=double(imread('Pineapple1.jpg')); >> figure, imshow(imP1) >> %Convert to Gray scale >> imP1gray = rgb2gray(imP1); >> figure, imshow(imP1gray) >> figure, hist(imP1gray(:)) >> >> w=[1 1 1;0 0 0; -1 -1 -1] w = 1 1 1 0 0 0 -1 -1 -1 >> imP1edge = imfilter(imP1gray,w); >> figure, imshow(imP1edge, [ ]) Roger S. Gaborski

  7. >> figure, imshow(imP1edge,[ ]) >>figure, imshow(abs(imP1edge),[ ]) Roger S. Gaborski

  8. Edge Histogram Edge histogram Absolute Edge Histogram Roger S. Gaborski

  9. Edge Image Thresholds >> figure, imshow(abs(imP1edge)>1.0),title('Threshold 1.0') Roger S. Gaborski

  10. >> w=[1 1 1;0 0 0; -1 -1 -1]' w = 1 0 -1 1 0 -1 1 0 -1 >> imP1edge2 = imfilter(imP1gray,w); >> figure, imshow(imP1edge2,[ ]) >> figure, imshow(abs(imP1edge2,[ ])) Roger S. Gaborski

  11. >> w=[1 1 1;0 0 0; -1 -1 -1] w = 1 1 1 0 0 0 -1 -1 -1 >> w=[1 1 1;0 0 0; -1 -1 -1]' w = 1 0 -1 1 0 -1 1 0 -1 Roger S. Gaborski

  12. [BW,thresh,gv,gh] = edge(imP1gray,'prewitt'); >> [BW,thresh,gv,gh] = Edge(imP1grayNor,'prewitt'); >> figure, imshow(gv, [ ]), title(‘gv’) >> figure, imshow(gh, [ ]), title(‘gh’) >> figure, imshow(BW) >> thresh thresh = 0.0675 Roger S. Gaborski

  13. [BW,thresh,gv,gh] = edge(imP1gray,'sobel'); >> [BW,thresh,gv,gh] = edge(imP1grayNor,'sobel'); >> figure, imshow(gv,[ ]),title('gv') >> figure, imshow(gh,[ ]),title('gh') >> figure, imshow(BW),title('BW') >> thresh thresh = 0.0695 Roger S. Gaborski

  14. BW = edge(imP1grayNor,'canny',THRESH,SIGMA); >> BW = edge(imP1gray,'canny',.1); >> figure, imshow(BW), title(‘Threshold = .1’) Roger S. Gaborski

  15. Orange1 - Canny Roger S. Gaborski

  16. Color Segmentation Roger S. Gaborski

  17. RGB Color Image M x N x 3 array of color pixels The three planes correspond to red, green and blue values. Each pixel location is actually a triplet, (r, g, b) Each plane drives the respective red, green and blue inputs of a color monitor Data classes: Double  [0,1] Uint8  [ 0 255] Color Image Processing Roger S. Gaborski Roger S. Gaborski 17

  18. ZR ZG ZB Blue component Green component Red component Roger S. Gaborski

  19. Roger S. Gaborski

  20. Row of Data (red, green and blue) Roger S. Gaborski 20

  21. Roger S. Gaborski 21

  22. Extract individual color planes: fRed = rgb_image(:,:,1); fGreen = rgb_image(:,:,2); fBlue = rgb_image(:,:,3); Combine individual frames rgb_image = cat(3, fRed, fGreen, fBlue); Roger S. Gaborski Roger S. Gaborski 22

  23. RGB color space rgbcube(vx, vy, vz) Roger S. Gaborski Roger S. Gaborski 23

  24. HSV color space hsv_image = rgb2hsv(rgb_image); rgb_image = hsv2rgb(hsv_image); Roger S. Gaborski Roger S. Gaborski 24

  25. SegmentationNot Well Defined Definition – divide an image in to non-overlapping regions based on properties of image, such as, Gray level Color Texture Motion Depth perception Etc. Roger S. Gaborski Roger S. Gaborski 25

  26. Image segmentation in RGB Partition image into regions Color-based segmentation Obtain a sample of color pixels that match region we wish to segment Estimate the mean of the three colors Store color values in column vector m Classify each pixel in image as having a color specified by m Roger S. Gaborski Roger S. Gaborski 26

  27. Classify pixels- Euclidean distance We need a measure of similarity to classify pixels – how ‘close’ is a given pixel to m? Let z denote arbitrary pixel in the image z is similar to m if the distance between them is less than some threshold, T Euclidean distance: D(z,m) = ||z-m|| where ||x|| is the norm of x Roger S. Gaborski Roger S. Gaborski 27

  28. Euclidean Distance D(m,z) = [ (z-m)T (z-m) ]1/2 = [(zR-mR)2 + (zG-mG)2 + (zB-mB)2]1/2 D(m,z)  T is a solid sphere of radius T. Points within, or on the surface are defined as being part of the segmented region But, how can you include the information that the red pixels vary over a wide range, but green and blue pixels don’t? Roger S. Gaborski Roger S. Gaborski 28

  29. RECALL: Standard deviation A measure of the spread of the data Calculation: average distance from the mean of the data set to a point Denominator of n-1: samples n: entire population Roger S. Gaborski Roger S. Gaborski 29

  30. Variance Another measure of the spread of the data in a data set Calculation: Variance: original statistical measure of spread of data. unit: square term. e.g. cm2 SD: square root of variance, the same unit with original data Roger S. Gaborski Roger S. Gaborski 30

  31. Covariance Variance – measure of the deviation from the mean for points in one dimension e.g. heights Covariance as a measure of how much each of the dimensions vary from the mean with respect to each other. Covariance is measured between 2 dimensions to see if there is a relationship between the 2 dimensions e.g. number of hours studied & grades obtained. The covariance between one dimension and itself is the variance Roger S. Gaborski Roger S. Gaborski 31

  32. Covariance variance (x) = covariance (x, y) = For 3-dimensional data set (x,y, z): covariance (x, y), covariance (x, z), covariance (y, z) covariance (x, x) = variance (x) , covariance (y, y) = variance (y) covariance (z, z) = variance (z) Roger S. Gaborski Roger S. Gaborski 32

  33. Covariance matrix Representing Covariance between dimensions as a matrix. e.g. for 3 dimensions: cov(x,x) cov(x,y) cov(x,z) C = cov(y,x) cov(y,y) cov(y,z) cov(z,x) cov(z,y) cov(z,z) Diagonal is the variances of x, y and z cov(x,y) = cov(y,x) hence C matrix is symmetrical along the diagonal N-dimensional data will result in nxn covariance matrix Roger S. Gaborski Roger S. Gaborski 33

  34. Interpretation Exact value is not as important as it’s sign. A positive value of covariance indicates both dimensions increase or decrease together. e.g. number of hours studied vs. the grade for that subject A negative value indicates while one increases the other decreases, or vice-versa. e.g. active social life at RIT vs. performance in CS dept. Covariance is zero: the two dimensions are independent of each other. e.g. heights of students vs. the grades for a subject Roger S. Gaborski Roger S. Gaborski 34

  35. Covariance MATLAB: cov Diagonal: variances Matrix is symmetric Roger S. Gaborski Roger S. Gaborski 35

  36. MahalanobisDistance • Generalization D(z,m) = [ (z-m)T C-1 (z-m) ]1/2 where C is the covariance matrix of the sample data • D(z,m)  T is a solid 3-D elliptical body • The principal axes are orientation in direction of maximum data spread • If C = I, the Mahalanobis reduces to the Euclidean distance Roger S. Gaborski Roger S. Gaborski 36

  37. Covariance For 3-dimensional data set (x,y,z): cov(x,y), cov(x,z), cov(y,z) cov(x,x) = var(x) , cov(y,y) = var(y), cov(z,z) = var(z) Roger S. Gaborski Roger S. Gaborski 37

  38. CALCULATING COVARIANCE MATRIX Data = [ 1 2 3; 5 7 9; 4 5 6] Mean = 3.3 4.6 6.0 (red, green, blue ) Subtract mean from each color Data value dataM = -2.3333 -2.6667 -3.0000 1.6667 2.3333 3.0000 0.6667 0.3333 0

  39. C11 = sum(dataM(:,1) .* dataM(:,1))/2 (divideby n-1 = 3-1 = 2) C11 = 4.3333 >> C12 = sum(dataM(:,1) .*dataM(:,2))/2 C12 = 5.1667 Etc.

  40. NUMERICAL EXAMPLES Roger S. Gaborski Roger S. Gaborski 40

  41. NUMERICAL EXAMPLE: Euclidean Distance D(z,m) T is a solid sphere of radius T. Points within, or on the surface are defined as being part of the segmented region Roger S. Gaborski Roger S. Gaborski 41

  42. Euclidean Distance dEuc(P,M) =SQRT { (P-M)’ (P-M) } M = [5; 7; 6], P = [7; 6; 1] M are the means of the samples, P is a specific pixel M and P are 3x1 vectors P-M is a 3x1 vector Need to transpose first vector

  43. (P-M)’ = [ 2 -1 -5] (P-M)’ (P-M) = 30 dEuc(P,M) =SQRT { (P-M)’ (P-M) } = SQRT(30) = 5.47

  44. Mahalanobis distance • Generalization where C is the covariance matrix of the sample data • D(z,m) T is a solid 3-D elliptical body • The principal axes are orientation in direction of maximum data spread • If C=I, the Mahalanobis reduces to the Euclidean distance Roger S. Gaborski Roger S. Gaborski 44

  45. Assume inverse of covariance matrix: 1 0 0 0 1 0 0 0 .5 Roger S. Gaborski

  46. Mahalanobis distance dMah(P,M) =SQRT { (P-M)’ C-1 (P-M) } = [ 2 -1 -5]* C-1 = [2 -1 -5] 1 0 0 0 1 0 0 0 .5 = [2 -1 -2.5 ] (P-M)

  47. [2 -1 -2.5 ] (P-M) = • [2 -1 -2.5 ] 2 • -1 = 17.5 • -5 • But we still need to take square root; • Sqrt(17.5) = 4.18

  48. Examples of segmentation using color information Roger S. Gaborski

  49. Segment an orange based on color samples – No covariance • What steps do we • take? • 1. • 2. • 3. Roger S. Gaborski Roger S. Gaborski 49

  50. Segment an orange based on color samples • What steps do we take? • Sample orange pixels • calculate means of r, g, b • 2. ? • 3. ? Roger S. Gaborski Roger S. Gaborski 50

More Related