680 likes | 854 Views
Introduction to Computer Vision Lecture 8. Roger S. Gaborski. Graduate Student Projects. Pupil Detection Results. Pineapple and Orange Examples. Histograms. A histogram is just a method for summarizing data, for example, gray level pixel values Can also summarize edge data.
E N D
Introduction to Computer VisionLecture 8 Roger S. Gaborski
Graduate Student Projects Roger S. Gaborski
Pupil Detection Results Roger S. Gaborski
Pineapple and Orange Examples Roger S. Gaborski
Histograms • A histogram is just a method for summarizing data, for example, gray level pixel values • Can also summarize edge data Roger S. Gaborski
>> imP1=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
Edges >> imP1=imread('Pineapple1.jpg'); >> figure, imshow(imP1) >> %Convert to Gray scale >> imP1gray = rgb2gray(imP1); >> figure, imshow(imP1gray) >> imP1grayNor = mat2gray(imP1gray, [ 0 255]); >> figure, hist(imP1grayNor(:)) Roger S. Gaborski
Edges >> imP1=imread('Pineapple1.jpg'); >> figure, imshow(imP1) >> %Convert to Gray scale >> imP1gray = rgb2gray(imP1); >> figure, imshow(imP1gray) >> imP1grayNor = mat2gray(imP1gray, [ 0 255]); >> figure, hist(imP1grayNor(:)) >> >> w=[1 1 1;0 0 0; -1 -1 -1] w = 1 1 1 0 0 0 -1 -1 -1 >> imP1edge = imfilter(double(imP1grayNor),w); >> figure, imshow(imP1edge, [ ]) Roger S. Gaborski
>> figure, imshow(imP1edge,[ ]) >>figure, imshow(abs(imP1edge),[ ]) Roger S. Gaborski
Edge Histogram Edge histogram Absolute Edge Histogram Roger S. Gaborski
Edge Image Thresholds >> figure, imshow(abs(imP1edge)>1.0),title('Threshold 1.0') Roger S. Gaborski
>> w=[1 1 1;0 0 0; -1 -1 -1]' w = 1 0 -1 1 0 -1 1 0 -1 >> imP1edge2 = imfilter(double(imP1gray),w); >> figure, imshow(imP1edge2,[ ]) >> figure, imshow(abs(imP1edge2,[ ])) Roger S. Gaborski
>> 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
[BW,thresh,gv,gh] = edge(imP1grayNor,'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
[BW,thresh,gv,gh] = edge(imP1grayNor,'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
BW = edge(imP1grayNor,'canny',THRESH,SIGMA); >> BW = edge(imP1grayNor,'canny',.1); >> figure, imshow(BW), title(‘Threshold = .1’) Roger S. Gaborski
Orange1 - Canny Roger S. Gaborski
Edge Images • Very low level representations • Simply 0s and 1s • We would like to have a higher representation • Which 1’s belong to which edges? Roger S. Gaborski
Connect component analysis Roger S. Gaborski
Korean Textdemo Gray scale image Roger S. Gaborski Roger S. Gaborski 26
Connect Component Labeling Foreground = 1 Background = 0 Roger S. Gaborski Roger S. Gaborski 27
Connect Component Labeling-2 Foreground = 1 Background = 0 Roger S. Gaborski Roger S. Gaborski 28
Connect Component Labeling-3 Foreground = 1 Background = 0 Roger S. Gaborski Roger S. Gaborski 29
Connect Component Labeling-4 Foreground = 1 Background = 0 Roger S. Gaborski Roger S. Gaborski 30
Connect Component Labeling-5 Foreground = 1 Background = 0 Roger S. Gaborski Roger S. Gaborski 31
Connect Component Labeling-6 Foreground = 1 Background = 0 Roger S. Gaborski Roger S. Gaborski 32
Connect Component Labeling-7 Foreground = 1 Background = 0 NW,W neighbors are a, but NE is b Roger S. Gaborski Roger S. Gaborski 33
Connect Component Labeling-8 Foreground = 1 Background = 0 NW,W neighbors are a, but NE is b Resolve by making all elements in conflict the same label, in this case a Roger S. Gaborski Roger S. Gaborski 34
Final Connect Component Labeling Foreground = 1 Background = 0 Roger S. Gaborski Roger S. Gaborski 35
MATLAB Connected Component Labeling >> LabelImage = bwlabel(image,8) LabelImage = 0 1 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 1 0 1 1 1 1 0 1 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • >> image = [ 0 1 0 0 0 0 0 0 1 1;... • 0 1 1 0 0 0 0 0 1 0;... • 0 0 1 0 0 0 0 1 1 1;... • 0 1 1 1 1 0 1 1 1 1;... • 0 0 0 0 1 1 1 0 0 0;... • 0 0 0 0 0 0 0 0 0 0;... • 0 0 0 0 1 1 1 0 0 0;... • 0 0 0 0 0 0 0 0 0 0;... • 0 0 1 1 1 0 0 0 0 0;... • 0 0 0 0 0 0 0 0 0 0]; Roger S. Gaborski Roger S. Gaborski 36
Visualization of Labeled data Labeled image, three connected Components and dark blue background Original image, Foreground = white, Background = black Roger S. Gaborski Roger S. Gaborski 37
Labeled Korean Characters Input image Output image Roger S. Gaborski Roger S. Gaborski 38
Color Segmentation Roger S. Gaborski
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 40
ZR ZG ZB Blue component Green component Red component Roger S. Gaborski
Row of Data (red, green and blue) Roger S. Gaborski 43
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 45
RGB color space rgbcube(vx, vy, vz) Roger S. Gaborski Roger S. Gaborski 46
HSV color space hsv_image = rgb2hsv(rgb_image); rgb_image = hsv2rgb(hsv_image); Roger S. Gaborski Roger S. Gaborski 47
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 48
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 49
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 50