760 likes | 886 Views
Introduction to Computer Vision Lecture 10. Roger S. Gaborski. 1. RECALL: 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. 2. Covariance.
E N D
Introduction to Computer VisionLecture 10 Roger S. Gaborski 1
RECALL: 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 2
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 3
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
C11 = sum(dataM(:,1) .* dataM(:,1))/2 C11 = 4.3333 >> C12 = sum(dataM(:,1) .*dataM(:,2))/2 C12 = 5.1667 Etc.
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 6
In Class Exercise • Euclidean Distance dEuc(P,M) =SQRT { (P-M)’ (P-M) } M = [5; 7; 6], P = [7; 6; 1] M and P are 3x1 vectors P-M is a 3x1 vector Need to transpose first vector
(P-M)’ = [ 2 -1 -5] (P-M)’ (P-M) = 30 dEuc(P,M) =SQRT { (P-M)’ (P-M) } = SQRT(30) = 5.47
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)
[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
Extract and Analyze Brandy im=imread('IMGP1715.JPG'); >> imSm = imresize(im, .25); >> figure,imshow(imSm) Roger S. Gaborski 11
Approaches Gray scale thresholding Roger S. Gaborski 12
1.Gray scale thresholding • Approach – First convert to gray scale (losing color • information), then threshold • >> imSmGray = rgb2gray(imSm); • >> imSmGray = im2double(imSmGray); • >>figure, imshow(imSmGray) • >>figure, imshow(im2bw(imSmGray,graythresh(imSmGray))) Roger S. Gaborski 13
Clearly, unsuccessful WHY DID IT FAIL?? The intensity value of pixels of Brandy is very close to intensity values of pixels of the background, which makes it hard to segment based on intensity distribution. Roger S. Gaborski 14
Grayscale Histogram >> max(imSmGray(:)) ans = 0.9804 >> min(imSmGray(:)) ans = 0.0510 >> figure, imhist(imSmGray) No clear separation line of dog and background Roger S. Gaborski 15
Approaches Gray scale thresholding Detect edges and then segment Roger S. Gaborski 16
2. Edge Detection: Sobel Roger S. Gaborski 17
2. Edge Detection: Laplacian of Gaussian Roger S. Gaborski 18
2. Edge Detection: Canny Roger S. Gaborski 19
Reason of the failures • Gray scale thresholding and edge detection: • Both these 2 algorithms work in gray scale space, only taking into account of intensity values of the pixel. However, the intensity value of the dog and the grass is very similar to each other, which makes the noise very hard to eliminate. The edge detection algorithms also fail in this case. • They ignore the most informative component: distinct colors of the brown dog and the green grass
Approaches Gray scale thresholding Detect edges and then segment Color segmentation Color spaces : RGB Euclidean distance Mahananobis distance Roger S. Gaborski 21
3. Color Segmentation: Euclidean Distance Manually select pixels Roger S. Gaborski 22
3. Color Segmentation: Mahalanobis Distance Brandy Noise from brown earth Manually select pixels Roger S. Gaborski 23
Original Brandy picture Have very similar color with brandy Roger S. Gaborski 24
Discussion None of the 3 planes will work for the segmentation of Brandy and the grass. However, by combining B, G, and B planes together, we can roughly segment Brandy from the grass by Euclidean distance and achieve desirable segmentation by Mahalanobis distance (taking into account of correlations between different color planes). Roger S. Gaborski 25
Individual Color Planes >> figure, subplot(2,3,1),imshow(imSm(:,:,1)),title('Red') >> subplot(2,3,2),imshow(imSm(:,:,2)),title('Green') >> subplot(2,3,3),imshow(imSm(:,:,3)),title('Blue') >> subplot(2,3,4),imshow(im2bw(imSm(:,:,1),graythresh(imSm(:,:,1)))) title('Red Threshold') >> subplot(2,3,5),imshow(im2bw(imSm(:,:,2),graythresh(imSm(:,:,2)))) title('Green Threshold') >> subplot(2,3,6),imshow(im2bw(imSm(:,:,3),graythresh(imSm(:,:,3)))) title('Blue Threshold') Roger S. Gaborski 26
HSV Color Space Seems doesn’t work when combining HSV together >> imH = rgb2hsv(imSm); >> figure, imshow(imH) Roger S. Gaborski 27
Distinct hues of brown color (brandy) and green color (grass) Perfect for separating the dog from the background Hard to distinguish >> figure, subplot(1,3,1),imshow(imH(:,:,1)),title('Hue') >> subplot(1,3,2),imshow(imH(:,:,2)),title('Saturation') >> subplot(1,3,3),imshow(imH(:,:,2)),title('Value') Roger S. Gaborski 28
Imhist(imH(:,:,1)) Grass distribution Dog distribution Separating line Histogram distribution in Hue space Roger S. Gaborski 29
Dog pixels gray level value = 0 Still, very similar hue with Brandy >> level = graythresh(imH(:,:,1)) level = 0.1725 (automatic threshold) >> figure, imshow(imH(:,:,1)>level) Roger S. Gaborski 30
Summary Color is the ideal descriptor in segmenting Brandy from the grass (distinct colors) Edge detection algorithms fail when the intensity values of adjacent pixels are very similar with each other We will continue with color segmentation and morphological processing in next lecture Follow up assignments on region growing and color segmentation will be posted on course website shortly. You will be informed when they are posted.
Approaches • We look at two approaches for color segmentation: • Region segmentation using a distance measurements • Region growing using seeds and a distance measurement
L*a*b Color Space • 'L*' luminosity or brightness layer, • 'a*' chromaticity layer indicating where color falls along the red-green axis • 'b*' chromaticity layer indicating where the color falls along the blue-yellow axis.
Distance Measure in L*a*b Space • Only use a and b planes • Manually sample image • Estimate mean of a and b values • Calculate distance as before
K-means Clustering • MATLAB: IDX = kmeans(X,k) partitions the points in the n-by-p data matrix X into k clusters. • How many clusters? k • Distance measure: Euclidean
Very Simple Example • Consider 1 dimensional data (algorithm works with n dimensional data Assume k = 2 Assume cluster centers, randomly pick 2 values
Very Simple Example • Measure distance between centers and remaining points Assign points to closer center Recalculate centers based on membership 1 = 1 (2+3+5+6+7+8+9)/7 = 5.7143
Very Simple Example 1.000 5.7143 Assign points to closer new center Recalculate centers based on membership (1+2+3)/3 = 2.0 (5+6+7+8+9)/5 = 7.0
Very Simple Example No points reassigned, done Z1 = 2.0 Z2 = 7.0