1.01k likes | 1.17k Views
Stanford CS223B Computer Vision, Winter 2006 Lecture 3 More On Features. Professor Sebastian Thrun CAs: Dan Maynes-Aminzade and Mitul Saha [with slides by D Forsyth, D. Lowe, M. Polleyfeys, C. Rasmussen, G. Loy, D. Jacobs, J. Rehg, A, Hanson, G. Bradski,…]. Today’s Goals. Canny Edge Detector
E N D
Stanford CS223B Computer Vision, Winter 2006Lecture 3 More On Features Professor Sebastian Thrun CAs: Dan Maynes-Aminzade and Mitul Saha [with slides by D Forsyth, D. Lowe, M. Polleyfeys, C. Rasmussen, G. Loy, D. Jacobs, J. Rehg, A, Hanson, G. Bradski,…]
Today’s Goals • Canny Edge Detector • Harris Corner Detector • Hough Transform • Templates and Image Pyramid • SIFT Features
Features in Matlab im = imread('bridge.jpg'); bw = double(im(:,:,1)) ./ 256; edge(im,’sobel’) - (almost) linear edge(im,’canny’) - not local, no closed form
Sobel Operator Edge Magnitude = 2 2 S1 + S1 S1 tan-1 S2 Edge Direction = -1 -2 -1 0 0 0 1 2 1 -1 0 1 -2 0 2 -1 0 1 S1= S2 =
Sobel in Matlab edge(im,’sobel’)
Canny Edge Detector edge(im,’canny’)
Comparison Sobel Canny
Canny Edge Detection Steps: • Apply derivative of Gaussian • Non-maximum suppression • Thin multi-pixel wide “ridges” down to single pixel width • Linking and thresholding • Low, high edge-strength thresholds • Accept all edges over low threshold that are connected to edge over high threshold
Non-Maximum Supression • Non-maximum suppression: • Select the single maximum point across the width of an edge.
Linking to the Next Edge Point Assume the marked point q is an edge point. Take the normal to the gradient at that point and use this to predict continuation points (either r or p).
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
Canny Edge Detection (Example) gap is gone Strong + connected weak edges Original image Strong edges only Weak edges courtesy of G. Loy
Canny Edge Detection (Example) Using Matlab with default thresholds
Bridge Example Again edge(im,’canny’)
Today’s Goals • Canny Edge Detector • Harris Corner Detector • Hough Transform • Templates and Image Pyramid • SIFT Features
Finding Corners Edge detectors perform poorly at corners. Corners provide repeatable points for matching, so are worth detecting. • Idea: • Exactly at a corner, gradient is ill defined. • However, in the region around a corner, gradient has two or more different values.
The Harris corner detector Form the second-moment matrix: Gradient with respect to x, times gradient with respect to y Sum over a small region around the hypothetical corner Matrix is symmetric Slide credit: David Jacobs
Simple Case First, consider case where: This means dominant gradient directions align with x or y axis If either λ is close to 0, then this is not a corner, so look for locations where both are large. Slide credit: David Jacobs
General Case It can be shown that since C is rotationally symmetric: So every case is like a rotated version of the one on last slide. Slide credit: David Jacobs
So, To Detect Corners • Filter image with Gaussian to reduce noise • Compute magnitude of the x and y gradients at each pixel • Construct C in a window around each pixel (Harris uses a Gaussian window – just blur) • Solve for product of ls (determinant of C) • If ls are both big (product reaches local maximum and is above threshold), we have a corner (Harris also checks that ratio of ls is not too high)
Gradient Orientation Closeup
Corner Detection Corners are detected where the product of the ellipse axis lengths reaches a local maximum.
Harris Corners • Originally developed as features for motion tracking • Greatly reduces amount of computation compared to tracking every pixel • Translation and rotation invariant (but not scale invariant)
Harris Corner in Matlab % Harris Corner detector - by Kashif Shahzad sigma=2; thresh=0.1; sze=11; disp=0; % Derivative masks dy = [-1 0 1; -1 0 1; -1 0 1]; dx = dy'; %dx is the transpose matrix of dy % Ix and Iy are the horizontal and vertical edges of image Ix = conv2(bw, dx, 'same'); Iy = conv2(bw, dy, 'same'); % Calculating the gradient of the image Ix and Iy g = fspecial('gaussian',max(1,fix(6*sigma)), sigma); Ix2 = conv2(Ix.^2, g, 'same'); % Smoothed squared image derivatives Iy2 = conv2(Iy.^2, g, 'same'); Ixy = conv2(Ix.*Iy, g, 'same'); % My preferred measure according to research paper cornerness = (Ix2.*Iy2 - Ixy.^2)./(Ix2 + Iy2 + eps); % We should perform nonmaximal suppression and threshold mx = ordfilt2(cornerness,sze^2,ones(sze)); % Grey-scale dilate cornerness = (cornerness==mx)&(cornerness>thresh); % Find maxima [rws,cols] = find(cornerness); % Find row,col coords. clf ; imshow(bw); hold on; p=[cols rws]; plot(p(:,1),p(:,2),'or'); title('\bf Harris Corners')
Harris Corners for Optical Flow Will talk about this later (optical flow)
Today’s Goals • Canny Edge Detector • Harris Corner Detector • Hough Transform • Templates and Image Pyramid • SIFT Features
Features? Local versus global
Vanishing Points A. Canaletto [1740], Arrival of the French Ambassador in Venice
Vanishing Points…? A. Canaletto [1740], Arrival of the French Ambassador in Venice
Hough Transform: Quantization m m Detecting Lines by finding maxima / clustering in parameter space
Hough Transform: Algorithm • For each image point, determine • most likely line parameters b,m (direction of gradient) • strength (magnitude of gradient) • Increment parameter counter by strength value • Cluster in parameter space, pick local maxima
Hough Transform: Results Image Edge detection Hough Transform
Summary Hough Transform • Smart counting • Local evidence for global features • Organized in a table • Careful with parameterization! • Subject to Curse of Dimensionality • Works great for simple features with 3 unknowns • Will fail for complex objects (e.g., all faces)
Today’s Goals • Canny Edge Detector • Harris Corner Detector • Hough Transform • Templates and Image Pyramid • SIFT Features
Problem: Features for Recognition … in here Want to find
Templates • Find an object in an image! • Want Invariance! • Scaling • Rotation • Illumination • Deformation
Convolution with Templates % read image im = imread('bridge.jpg'); bw = double(im(:,:,1)) ./ 256;; imshow(bw) % apply FFT FFTim = fft2(bw); bw2 = real(ifft2(FFTim)); imshow(bw2) % define a kernel kernel=zeros(size(bw)); kernel(1, 1) = 1; kernel(1, 2) = -1; FFTkernel = fft2(kernel); % apply the kernel and check out the result FFTresult = FFTim .* FFTkernel; result = real(ifft2(FFTresult)); imshow(result) % select an image patch patch = bw(221:240,351:370); imshow(patch) patch = patch - (sum(sum(patch)) / size(patch,1) / size(patch, 2)); kernel=zeros(size(bw)); kernel(1:size(patch,1),1:size(patch,2)) = patch; FFTkernel = fft2(kernel); % apply the kernel and check out the result FFTresult = FFTim .* FFTkernel; result = max(0, real(ifft2(FFTresult))); result = result ./ max(max(result)); result = (result .^ 1 > 0.5); imshow(result) % alternative convolution imshow(conv2(bw, patch, 'same'))
Aside: Convolution Theorem Fourier Transform of g: Fis invertible