Stanford CS 223 B Computer Vision Winter 2005
Stanford CS 223 B Computer Vision, Winter 2005 Lecture 3 Filters and Features (with Matlab) Sebastian Thrun, Stanford Rick Szeliski, Microsoft Hendrik Dahlkamp, Stanford [with slides by D Forsyth, D. Lowe, M. Polleyfeys, C. Rasmussen, G. Loy, D. Jacobs, J. Rehg, A, Hanson, G. Bradski, …] Sebastian Thrun CS 223 B Computer Vision, Winter 2005 1
Assignment 1 FAQ • Compiling projects – cxcored. dll is the debug version of cxcore. dll, can be compiled from cxcore. dsp – Use template cvsample. dsp to get paths right • Taking the images – Assignment change: out-of-focus images no longer needed – Don’t print a border around the chessboard Sebastian Thrun CS 223 B Computer Vision, Winter 2005 2
Assignment 1 FAQ • Corner finding – Supply correct parameters e. g. corner_count<>0 – Visualize corner ordering • How to verify results – Backproject scene corners into image – Use common sense: Sebastian Thrun CS 223 B Computer Vision, Winter 2005 etc 3
Stanford CS 223 B Computer Vision, Winter 2005 Lecture 3 Filters and Features (with Matlab) Sebastian Thrun, Stanford Rick Szeliski, Microsoft Hendrik Dahlkamp, Stanford [with slides by D Forsyth, D. Lowe, M. Polleyfeys, C. Rasmussen, G. Loy, D. Jacobs, J. Rehg, A, Hanson, G. Bradski, …] Sebastian Thrun CS 223 B Computer Vision, Winter 2005 4
Today’s Goals • Features 101 • Linear Filters and Edge Detection • Canny Edge Detector Sebastian Thrun CS 223 B Computer Vision, Winter 2005 5
Today’s Question • • What is a feature? What is an image filter? How can we find corners? How can we find edges? Sebastian Thrun CS 223 B Computer Vision, Winter 2005 6
What is a Feature? • Local, meaningful, detectable parts of the image Sebastian Thrun CS 223 B Computer Vision, Winter 2005 7
Features in Computer Vision • What is a feature? – Location of sudden change • Why use features? – Information content high – Invariant to change of view point, illumination – Reduces computational burden Sebastian Thrun CS 223 B Computer Vision, Winter 2005 8
(One Type of) Computer Vision Image 1 Feature 2 : Feature N Computer Vision Algorithm Image 2 Feature 1 Feature 2 : Feature N Sebastian Thrun CS 223 B Computer Vision, Winter 2005 9
Where Features Are Used • Calibration • Image Segmentation • Correspondence in multiple images (stereo, structure from motion) • Object detection, classification Sebastian Thrun CS 223 B Computer Vision, Winter 2005 10
What Makes For Good Features? • Invariance – – View point (scale, orientation, translation) Lighting condition Object deformations Partial occlusion • Other Characteristics – Uniqueness – Sufficiently many – Tuned to the task Sebastian Thrun CS 223 B Computer Vision, Winter 2005 11
Today’s Goals • Features 101 • Linear Filters and Edge Detection • Canny Edge Detector Sebastian Thrun CS 223 B Computer Vision, Winter 2005 12
What Causes an Edge? • Depth discontinuity • Surface orientation discontinuity • Reflectance discontinuity (i. e. , change in surface material properties) • Illumination discontinuity (e. g. , shadow) Slide credit: Christopher Rasmussen Sebastian Thrun CS 223 B Computer Vision, Winter 2005 13
Quiz: How Can We Find Edges? Sebastian Thrun CS 223 B Computer Vision, Winter 2005 14
Edge Finding 101 im = imread('bridge. jpg'); image(im); figure(2); bw = double(rgb 2 gray(im)); image(bw); gradkernel = [-1 1]; dx = abs(conv 2(bw, gradkernel, 'same')); image(dx); colorbar; colormap gray matlab [dx, dy] = gradient(bw); gradmag = sqrt(dx. ^2 + dy. ^2); image(gradmag); Sebastian Thrun colorbar colormap(gray(255)) colormap(default) CS 223 B Computer Vision, Winter 2005 15
Edge Finding 101 • Example of a linear Filter Sebastian Thrun CS 223 B Computer Vision, Winter 2005 16
What is Image Filtering? Modify the pixels in an image based on some function of a local neighborhood of the pixels 10 5 4 5 1 1 Sebastian Thrun 3 1 7 Some function 7 CS 223 B Computer Vision, Winter 2005 17
Linear Filtering • Linear case is simplest and most useful – Replace each pixel with a linear combination of its neighbors. • The prescription for the linear combination is called the convolution kernel. 10 5 3 0 0 0 4 5 1 0 0. 5 0 1 1 7 0 1. 0 0. 5 7 kernel Sebastian Thrun CS 223 B Computer Vision, Winter 2005 18
Linear Filter = Convolution I(. ) I(. ) g 11 g 12 g 13 g 21 g 22 g 23 g 31 g 32 g 33 f (i, j) = Sebastian Thrun g 11 I(i-1, j-1) + g 12 I(i-1, j) + g 13 I(i-1, j+1) + g 21 I(i, j-1) + g 22 I(i, j) g 31 I(i+1, j-1) + g 32 I(i+1, j) + g 33 I(i+1, j+1) + g 23 I(i, j+1) CS 223 B Computer Vision, Winter 2005 + 19
Linear Filter = Convolution Sebastian Thrun CS 223 B Computer Vision, Winter 2005 20
Filtering Examples Sebastian Thrun CS 223 B Computer Vision, Winter 2005 21
Filtering Examples Sebastian Thrun CS 223 B Computer Vision, Winter 2005 22
Filtering Examples Sebastian Thrun CS 223 B Computer Vision, Winter 2005 23
Image Smoothing With Gaussian figure(3); sigma = 3; width = 3 * sigma; support = -width : width; gauss 2 D = exp( - (support / sigma). ^2 / 2); gauss 2 D = gauss 2 D / sum(gauss 2 D); smooth = conv 2(bw, gauss 2 D, 'same'), gauss 2 D', 'same'); image(smooth); colormap(gray(255)); gauss 3 D = gauss 2 D' * gauss 2 D; tic ; smooth = conv 2(bw, gauss 3 D, 'same'); toc Sebastian Thrun CS 223 B Computer Vision, Winter 2005 24
Smoothing With Gaussian Averaging Gaussian Slide credit: Marc Pollefeys Sebastian Thrun CS 223 B Computer Vision, Winter 2005 25
Smoothing Reduces Noise The effects of smoothing Each row shows smoothing with gaussians of different width; each column shows different realizations of an image of gaussian noise. Slide credit: Marc Pollefeys Sebastian Thrun CS 223 B Computer Vision, Winter 2005 26
Example of Blurring Image Blurred Image - Sebastian Thrun CS 223 B Computer Vision, Winter 2005 = 27
Edge Detection With Smoothed Images figure(4); [dx, dy] = gradient(smooth); gradmag = sqrt(dx. ^2 + dy. ^2); gmax = max(gradmag)); imshow(gradmag); colormap(gray(gmax)); Sebastian Thrun CS 223 B Computer Vision, Winter 2005 28
Scale Increased smoothing: • Eliminates noise edges. • Makes edges smoother and thicker. • Removes fine detail. Sebastian Thrun CS 223 B Computer Vision, Winter 2005 29
The Edge Normal Sebastian Thrun CS 223 B Computer Vision, Winter 2005 30
Displaying the Edge Normal figure(5); hold on; image(smooth); colormap(gray(255)); [m, n] = size(gradmag); edges = (gradmag > 0. 3 * gmax); inds = find(edges); [posx, posy] = meshgrid(1: n, 1: m); posx 2=posx(inds); posy 2=posy(inds); gm 2= gradmag(inds); sintheta = dx(inds). / gm 2; costheta = - dy(inds). / gm 2; quiver(posx 2, posy 2, gm 2. * sintheta / 10, -gm 2. * costheta / 10, 0); hold off; Sebastian Thrun CS 223 B Computer Vision, Winter 2005 31
Separable Kernels Sebastian Thrun CS 223 B Computer Vision, Winter 2005 32
Combining Kernels / Convolutions 0. 0030 0. 0133 0. 0219 0. 0133 0. 0030 0. 0133 0. 0596 0. 0983 0. 0596 0. 0133 0. 0219 0. 0983 0. 1621 0. 0983 0. 0219 0. 0133 0. 0596 0. 0983 0. 0596 0. 0133 0. 0030 0. 0133 0. 0219 0. 0133 0. 0030 Sebastian Thrun CS 223 B Computer Vision, Winter 2005 33
Effect of Smoothing Radius 1 pixel Sebastian Thrun 3 pixels 7 pixels CS 223 B Computer Vision, Winter 2005 34
Robert’s Cross Operator 1 0 0 1 0 -1 + -1 0 S= [ I(x, y) - I(x+1, y+1) ]2 + [ I(x, y+1) - I(x+1, y) ]2 or S = | I(x, y) - I(x+1, y+1) | + | I(x, y+1) - I(x+1, y) | Sebastian Thrun CS 223 B Computer Vision, Winter 2005 35
Sobel Operator -1 -2 -1 S 1= 0 0 0 1 2 1 Edge Magnitude = -1 -2 -1 S 2 = 2 1 2 S 1 + S 1 Edge Direction = tan-1 Sebastian Thrun 0 0 0 S 1 S 2 CS 223 B Computer Vision, Winter 2005 36
The Sobel Kernel, Explained Sobel kernel is separable! Averaging done parallel to edge Sebastian Thrun CS 223 B Computer Vision, Winter 2005 37
Sobel Edge Detector figure(6) edge(bw, 'sobel') Sebastian Thrun CS 223 B Computer Vision, Winter 2005 38
Robinson Compass Masks -1 -2 -1 0 2 0 1 2 -1 0 1 -2 -1 0 1 2 1 0 0 0 -1 -2 -1 2 1 0 -1 -2 1 0 -1 0 -2 1 -1 0 -1 -2 -1 0 -1 2 1 0 -1 -2 -1 0 0 0 1 2 1 -2 -1 0 1 0 1 2 Sebastian Thrun CS 223 B Computer Vision, Winter 2005 39
Claim Your Own Kernel! Frei & Chen Sebastian Thrun CS 223 B Computer Vision, Winter 2005 40
Comparison (by Allan Hanson) • Analysis based on a step edge inclined at an angle q (relative to yaxis) through center of window. • Robinson/Sobel: true edge contrast less than 1. 6% different from that computed by the operator. • Error in edge direction – Robinson/Sobel: less than 1. 5 degrees error – Prewitt: less than 7. 5 degrees error • Summary – Typically, 3 x 3 gradient operators perform better than 2 x 2. – Prewitt 2 and Sobel perform better than any of the other 3 x 3 gradient estimation operators. – In low signal to noise ratio situations, gradient estimation operators of size larger than 3 x 3 have improved performance. – In large masks, weighting by distance from the central pixel is beneficial. Sebastian Thrun CS 223 B Computer Vision, Winter 2005 41
Today’s Goals • Features 101 • Linear Filters and Edge Detection • Canny Edge Detector Sebastian Thrun CS 223 B Computer Vision, Winter 2005 42
Canny Edge Detector figure(7) edge(bw, 'canny') Sebastian Thrun CS 223 B Computer Vision, Winter 2005 43
Canny Edge Detection Steps: 1. Apply derivative of Gaussian 2. Non-maximum suppression • Thin multi-pixel wide “ridges” down to single pixel width 3. Linking and thresholding • Low, high edge-strength thresholds • Accept all edges over low threshold that are connected to edge over high threshold Sebastian Thrun CS 223 B Computer Vision, Winter 2005 44
Non-Maximum Supression Non-maximum suppression: Select the single maximum point across the width of an edge. Sebastian Thrun CS 223 B Computer Vision, Winter 2005 45
Linking to the Next Edge Point Assume the marked point is an edge point. Take the normal to the gradient at that point and use this to predict continuation points (either r or s). Sebastian Thrun CS 223 B Computer Vision, Winter 2005 46
Edge Hysteresis • Hysteresis: A lag or momentum factor • Idea: Maintain two thresholds khigh and klow – Use khigh to find strong edges to start edge chain – Use klow to find weak edges which continue edge chain • Typical ratio of thresholds is roughly khigh / klow = 2 Sebastian Thrun CS 223 B Computer Vision, Winter 2005 47
Canny Edge Detection (Example) gap is gone Strong + connected weak edges Original image Strong edges only Weak edges courtesy of G. Loy Sebastian Thrun CS 223 B Computer Vision, Winter 2005 48
Canny Edge Detection (Example) Using Matlab with default thresholds Sebastian Thrun CS 223 B Computer Vision, Winter 2005 49
Application: Road Finding • (add roadrunner video here) Sebastian Thrun CS 223 B Computer Vision, Winter 2005 50
Corner Effects Sebastian Thrun CS 223 B Computer Vision, Winter 2005 51
Today’s Goals • Features 101 • Linear Filters and Edge Detection • Canny Edge Detector Sebastian Thrun CS 223 B Computer Vision, Winter 2005 52
- Slides: 52