1 / 85

Introduction to Computer Vision

Lecture 06 Roger S. Gaborski. Introduction to Computer Vision. 8 :00-8:15: In class exercise – histogram equalization 8:15 – 8:50 Lecture 8:50 - 9:15 Quiz #2. Simple Histogram Equalization In Class Exercise. Solution For In Class Histogram Equalization Exercise. In class exercise.

lester
Download Presentation

Introduction to Computer Vision

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. Lecture 06 Roger S. Gaborski Introduction to Computer Vision Roger S. Gaborski

  2. 8:00-8:15: In class exercise – histogram equalization • 8:15 – 8:50 Lecture • 8:50 - 9:15 Quiz #2

  3. Simple Histogram Equalization In Class Exercise Roger S. Gaborski

  4. Solution For In Class Histogram Equalization Exercise Roger S. Gaborski

  5. In class exercise • Histogram PDF  CDF Equalized Image Roger S. Gaborski

  6. Histogram Equalization • Consider an image with the following gray level values: • Construct the pdf • Construct the cdf • Equalize the image using the cdf (not histeq) Roger S. Gaborski

  7. Histogram Equalization • Consider an image with the following gray level values: • Construct the pdf 1/9 2/9 3/9 4/9 5/9 .1 .2 .3 .4 .5 Roger S. Gaborski

  8. pdf cdf 1/9 2/9 3/9 4/9 5/9 .1 .2 .3 .4 .5 Histogram Equalization Look Up Table 1/9 2/9 3/9 4/9 5/9 6/9 7/9 8/9 1 cdf probability .1 .2 .3 .4 .5 Gray level value Gray level value Roger S. Gaborski

  9. Histogram Equalization • Consider an image with the following gray level values: • Construct the pdf • Construct the cdf • Equalize the image using the cdf (not histeq) Roger S. Gaborski

  10. Create a ‘color image’ First create three color planes of data >> red = rand(5) red = 0.0294 0.0193 0.3662 0.7202 0.0302 0.7845 0.3955 0.2206 0.4711 0.2949 0.7529 0.1159 0.6078 0.9778 0.5959 0.1586 0.1674 0.5524 0.9295 0.1066 0.7643 0.6908 0.3261 0.5889 0.1359 >> green = rand(5) green = 0.2269 0.5605 0.6191 0.0493 0.1666 0.0706 0.4051 0.3297 0.7513 0.6484 0.9421 0.0034 0.8243 0.7023 0.8097 0.8079 0.5757 0.6696 0.9658 0.8976 0.0143 0.3176 0.6564 0.1361 0.0754 >> blue = rand(5) blue = 0.6518 0.0803 0.8697 0.6260 0.9642 0.5554 0.2037 0.8774 0.5705 0.6043 0.8113 0.8481 0.5199 0.0962 0.8689 0.5952 0.2817 0.6278 0.7716 0.8588 0.5810 0.9290 0.2000 0.1248 0.7606 Roger S. Gaborski

  11. colorIm(:,:,1) = 0.0294 0.0193 0.3662 0.7202 0.0302 0.7845 0.3955 0.2206 0.4711 0.2949 0.7529 0.1159 0.6078 0.9778 0.5959 0.1586 0.1674 0.5524 0.9295 0.1066 0.7643 0.6908 0.3261 0.5889 0.1359 colorIm(:,:,2) = 0.2269 0.5605 0.6191 0.0493 0.1666 0.0706 0.4051 0.3297 0.7513 0.6484 0.9421 0.0034 0.8243 0.7023 0.8097 0.8079 0.5757 0.6696 0.9658 0.8976 0.0143 0.3176 0.6564 0.1361 0.0754 colorIm(:,:,3) = 0.6518 0.0803 0.8697 0.6260 0.9642 0.5554 0.2037 0.8774 0.5705 0.6043 0.8113 0.8481 0.5199 0.0962 0.8689 0.5952 0.2817 0.6278 0.7716 0.8588 0.5810 0.9290 0.2000 0.1248 0.7606 >> colorIm(:,:,1)=red; >> colorIm(:,:,2)=green; >> colorIm(:,:,3)=blue; >> colorIm figure imshow(colorIm, 'InitialMagnification', 'fit') Roger S. Gaborski

  12. colorIm colorIm(1,1,: ) colorIm(4,4,: ) Roger S. Gaborski

  13. colorIm(:,:,1) = 0.0294 0.0193 0.3662 0.7202 0.0302 0.7845 0.3955 0.2206 0.4711 0.2949 0.7529 0.1159 0.6078 0.9778 0.5959 0.1586 0.1674 0.5524 0.9295 0.1066 0.7643 0.6908 0.3261 0.5889 0.1359 colorIm(:,:,2) = 0.2269 0.5605 0.6191 0.0493 0.1666 0.0706 0.4051 0.3297 0.7513 0.6484 0.9421 0.0034 0.8243 0.7023 0.8097 0.8079 0.5757 0.6696 0.9658 0.8976 0.0143 0.3176 0.6564 0.1361 0.0754 colorIm(:,:,3) = 0.6518 0.0803 0.8697 0.6260 0.9642 0.5554 0.2037 0.8774 0.5705 0.6043 0.8113 0.8481 0.5199 0.0962 0.8689 0.5952 0.2817 0.6278 0.7716 0.8588 0.5810 0.9290 0.2000 0.1248 0.7606 Roger S. Gaborski

  14. What are two methods to convert from a color image to a gray scale image? Roger S. Gaborski

  15. RECALL • What are two methods to convert from a color image to a gray scale image? • Average red, green and blue pixels Roger S. Gaborski

  16. Average • For example: >> colorImAverage = ( colorIm(:,:,1) + colorIm(:,:,2) + colorIm(:,:,3) )/3 colorImAverage = 0.3027 0.2200 0.6183 0.4651 0.3870 0.4701 0.3348 0.4759 0.5976 0.5159 0.8354 0.3224 0.6507 0.5921 0.7582 0.5206 0.3416 0.6166 0.8890 0.6210 0.4532 0.6458 0.3942 0.2833 0.3240 >> figure, imshow(colorImAverage, 'InitialMagnification', 'fit') Roger S. Gaborski

  17. Gray scale version of color image .5976 .5921 Roger S. Gaborski

  18. Color and Gray scale Images Roger S. Gaborski

  19. Color and Gray scale Images Conversion to gray scale results in a loss of information Roger S. Gaborski

  20. What are two methods to convert from a color image to a gray scale image? • Average red, green and blue pixels • Matlab’s rgb2gray function Roger S. Gaborski

  21. MATLAB’s rgb2gray Function >> colorIm_rgb2gray = rgb2gray(colorIm) colorIm_rgb2gray = 0.2163 0.3439 0.5721 0.3156 0.2168 0.3393 0.3792 0.3596 0.6469 0.5377 0.8706 0.1333 0.7249 0.7155 0.7525 0.5895 0.4202 0.6298 0.9328 0.6567 0.3031 0.4989 0.5056 0.2702 0.1716 Roger S. Gaborski

  22. colorIm and rgb2gray(colorIm) Roger S. Gaborski

  23. How does rgb2gray work? rgb2gray converts RGB values to grayscale values by forming a weighted sum of the R, G, and B components: Gray = 0.2989 * R + 0.5870 * G + 0.1140 * B Roger S. Gaborski

  24. Segmentation using Thesholding

  25. Segmentation – separate an image into its parts Separate the coins from the background Form two classes: Class 1: coins Class 2: background Roger S. Gaborski

  26. Thresholding >> I = imread('coins.png'); >> I=im2double(I); >> figure, imshow(I) Roger S. Gaborski

  27. Thresholding • Create a mask where coins have a value 1 and background has a value of 0 Roger S. Gaborski

  28. Histogram of coins image Roger S. Gaborski

  29. Select a threshold value Threshold t = .75 Roger S. Gaborski

  30. >> It75 = I>.75; >> figure, imshow(It75) >> whos Name Size Bytes Class Attributes I 246x300 590400 double It75 246x300 73800 logical Roger S. Gaborski

  31. Histogram of thresholded image Roger S. Gaborski

  32. Threshold = .5 Roger S. Gaborski

  33. Background Problems Roger S. Gaborski

  34. Coin Problem Roger S. Gaborski

  35. >> help graythresh graythreshGlobal image threshold using Otsu's method. LEVEL = graythresh(I) computes a global threshold (LEVEL) that can be used to convert an intensity image to a binary image with IM2BW. LEVEL is a normalized intensity value that lies in the range [0, 1]. graythresh uses Otsu's method, which chooses the threshold to minimize the intraclass variance of the thresholded black and white pixels. [LEVEL EM] = graythresh(I) returns effectiveness metric, EM, as the second output argument. It indicates the effectiveness of thresholding of the input image and it is in the range [0, 1]. The lower bound is attainable only by images having a single gray level, and the upper bound is attainable only by two-valued images. Roger S. Gaborski

  36. >> I = imread('coins.png'); >> I = im2double(I); >> level = graythresh(I) level = 0.4941 >> BW = I>level; >> figure, imshow(BW) >> [level,em] = graythresh(I) level = 0.4941 em = 0.9168 Roger S. Gaborski

  37. More Complicated Images

  38. Convert Image to Grayscale Roger S. Gaborski

  39. >> I = imread('Silver1.jpg'); >> I = im2double(I); >> Ig = rgb2gray(I); [level,em] = graythresh(Ig) level = 0.5529 em = 0.6971 (relatively low number) >> BW = Ig>level; >> figure, imshow(BW) Roger S. Gaborski

  40. Histogram of Grayscale Image level = 0.5529

  41. Simple Threshold Result BACKGROUND DETECTED Roger S. Gaborski

  42. impixel() impixel Pixel color values. impixel returns the red, green, and blue color values of specified image pixels. In the syntaxes below, impixel displays the input image and waits for you to specify the pixels with the mouse: P = impixel(I)

  43. Select Pixels From Grayscale Image >> figure, imshow(Ig) >> K=impixel(); >> K K = 0.8588 0.8588 0.8588 0.8398 0.8398 0.8398 0.7695 0.7695 0.7695 0.7225 0.7225 0.7225 0.7852 0.7852 0.7852 0.7842 0.7842 0.7842 0.8548 0.8548 0.8548 0.8514 0.8514 0.8514 0.7852 0.7852 0.7852 0.7375 0.7375 0.7375

  44. Min and Max of Selected Points >> MN = min(K(:,1)) MN = 0.7225 >> MX = max(K(:,1)) MX = 0.8588

  45. OBJECT

  46. >> figure, imshow(Ig>MN),title('Ig>.MN') MOST BACKGROUND NOT DETECTED

  47. figure, imshow(Ig>.45) Lower threshold than graythresh Background now detected along with more of object

  48. Potential Improvements: • Multilevel GrayscaleThresholding • Use of Color • Edge Detection

  49. Results using Simple Edge Detection

  50. Translate Text

More Related