MAN-522: Computer Vision Edge detection Feature and blob detection Hough transform Fitting Image alignment MAN-522: COMPUTER VISION
Edge detection Goal: Identify sudden changes (discontinuities) in an image Intuitively, most semantic and shape information from the image can be encoded in the edges More compact than pixels Ideal: artist’s line drawing (but artist is also using object-level knowledge) Source: D. Lowe
Origin of Edges Edges are caused by a variety of factors surface normal discontinuity depth discontinuity surface color discontinuity illumination discontinuity Edges are caused by a variety of factors Source: Steve Seitz
Characterizing edges An edge is a place of rapid change in the image intensity function intensity function (along horizontal scanline) image first derivative edges correspond to extrema of derivative
Image gradient The gradient of an image: The gradient points in the direction of most rapid increase in intensity The gradient direction is given by how does this relate to the direction of the edge? The edge strength is given by the gradient magnitude give definition of partial derivative: lim h->0 [f(x+h,y) – f(x,y)]/h Source: Steve Seitz
Differentiation and convolution Recall, for 2D function, f(x,y): This is linear and shift invariant, so must be the result of a convolution. We could approximate this as (which is obviously a convolution) I tend not to prove “Now this is linear and shift invariant, so must be the result of a convolution” but leave it for people to look up in the chapter. -1 1 Source: D. Forsyth, D. Lowe
Finite difference filters Other approximations of derivative filters exist: Source: K. Grauman
Finite differences: example Which one is the gradient in the x-direction (resp. y-direction)?
Effects of noise Consider a single row or column of the image Plotting intensity as a function of position gives a signal Where is the edge? How to fix? Source: S. Seitz
Effects of noise Finite difference filters respond strongly to noise Image noise results in pixels that look very different from their neighbors Generally, the larger the noise the stronger the response What is to be done? Source: D. Forsyth
Effects of noise Finite difference filters respond strongly to noise Image noise results in pixels that look very different from their neighbors Generally, the larger the noise the stronger the response What is to be done? Smoothing the image should help, by forcing pixels different to their neighbors (=noise pixels?) to look more like neighbors Source: D. Forsyth
Solution: smooth first g f * g To find edges, look for peaks in Source: S. Seitz
Derivative theorem of convolution Differentiation is convolution, and convolution is associative: This saves us one operation: f Source: S. Seitz
Derivative of Gaussian filter * [1 -1] = Is this filter separable?
Derivative of Gaussian filter x-direction y-direction Which one finds horizontal/vertical edges?
Summary: Filter mask properties Filters act as templates Highest response for regions that “look the most like the filter” Dot product as correlation Smoothing masks Values positive Sum to 1 → constant regions are unchanged Amount of smoothing proportional to mask size Derivative masks Opposite signs used to get high response in regions of high contrast Sum to 0 → no response in constant regions High absolute value at points of high contrast Source: K. Grauman
Tradeoff between smoothing and localization 1 pixel 3 pixels 7 pixels Smoothed derivative removes noise, but blurs edge. Also finds edges at different “scales”. Source: D. Forsyth
Implementation issues The gradient magnitude is large along a thick “trail” or “ridge,” so how do we identify the actual edge points? How do we link the edge points to form curves? Figures show gradient magnitude of zebra at two different scales Source: D. Forsyth
Edge finding We wish to mark points along the curve where the magnitude is biggest. We can do this by looking for a maximum along a slice normal to the curve (non-maximum suppression). These points should form a curve. There are then two algorithmic issues: at which point is the maximum, and where is the next one? Source: D. Forsyth
Non-maximum suppression At q, we have a maximum if the value is larger than those at both p and at r. Interpolate to get these values. Source: D. Forsyth
Predicting the next edge point Assume the marked point is an edge point. Then we construct the tangent to the edge curve (which is normal to the gradient at that point) and use this to predict the next points (here either r or s). Source: D. Forsyth
Designing an edge detector Criteria for an “optimal” edge detector: Good detection: the optimal detector must minimize the probability of false positives (detecting spurious edges caused by noise), as well as that of false negatives (missing real edges) Good localization: the edges detected must be as close as possible to the true edges Single response: the detector must return one point only for each true edge point; that is, minimize the number of local maxima around the true edge Source: L. Fei-Fei
Canny edge detector This is probably the most widely used edge detector in computer vision Theoretical model: step-edges corrupted by additive Gaussian noise Canny has shown that the first derivative of the Gaussian closely approximates the operator that optimizes the product of signal-to-noise ratio and localization J. Canny, A Computational Approach To Edge Detection, IEEE Trans. Pattern Analysis and Machine Intelligence, 8:679-714, 1986. Source: L. Fei-Fei
Source: D. Lowe, L. Fei-Fei Canny edge detector Filter image with derivative of Gaussian Find magnitude and orientation of gradient Non-maximum suppression: Thin multi-pixel wide “ridges” down to single pixel width Linking and thresholding (hysteresis): Define two thresholds: low and high Use the high threshold to start edge curves and the low threshold to continue them MATLAB: edge(image, ‘canny’) Source: D. Lowe, L. Fei-Fei
The Canny edge detector original image (Lena)
The Canny edge detector norm of the gradient
The Canny edge detector thresholding
The Canny edge detector thinning (non-maximum suppression)
Hysteresis thresholding original image high threshold (strong edges) low threshold (weak edges) hysteresis threshold Source: L. Fei-Fei
Effect of (Gaussian kernel spread/size) original Canny with Canny with The choice of depends on desired behavior large detects large scale edges small detects fine features Source: S. Seitz
Edge detection is just the beginning… image human segmentation gradient magnitude Berkeley segmentation database: http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/segbench/
Next time: Corner and blob detection
Feature extraction: Corners and blobs
Review: Linear filtering and edge detection Name two different kinds of image noise Name a non-linear smoothing filter What advantages does median filtering have over Gaussian smoothing? What is aliasing? How do we find edges? Why do we need to smooth before computing image derivatives? What are some characteristics of an “optimal” edge detector? What is nonmaximum suppression? What is hysteresis thresholding?
Why extract features? Motivation: panorama stitching We have two images – how do we combine them?
Why extract features? Motivation: panorama stitching We have two images – how do we combine them? Step 2: match features Step 1: extract features
Why extract features? Motivation: panorama stitching We have two images – how do we combine them? Step 1: extract features Step 2: match features Step 3: align images
Characteristics of good features Repeatability The same feature can be found in several images despite geometric and photometric transformations Saliency Each feature has a distinctive description Compactness and efficiency Many fewer features than image pixels Locality A feature occupies a relatively small area of the image; robust to clutter and occlusion
Applications Feature points are used for: Motion tracking Image alignment 3D reconstruction Object recognition Indexing and database retrieval Robot navigation
Finding Corners Key property: in the region around a corner, image gradient has two or more dominant directions Corners are repeatable and distinctive C.Harris and M.Stephens. "A Combined Corner and Edge Detector.“ Proceedings of the 4th Alvey Vision Conference: pages 147--151.
The Basic Idea We should easily recognize the point by looking through a small window Shifting a window in any direction should give a large change in intensity “flat” region: no change in all directions “edge”: no change along the edge direction “corner”: significant change in all directions Source: A. Efros
Harris Detector: Mathematics Change of intensity for the shift [u,v]: Intensity Window function Shifted intensity or Window function w(x,y) = Gaussian 1 in window, 0 outside Source: R. Szeliski
Harris Detector: Mathematics Change of intensity for the shift [u,v]: Second-order Taylor expansion of E(u,v) about (0,0) (bilinear approximation for small shifts):
Harris Detector: Mathematics The bilinear approximation simplifies to where M is a 22 matrix computed from image derivatives: M
Interpreting the second moment matrix First, consider an axis-aligned corner:
Interpreting the second moment matrix First, consider an axis-aligned corner: 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 Since M is symmetric, we have We can visualize M as an ellipse with axis lengths determined by the eigenvalues and orientation determined by R direction of the slowest change direction of the fastest change (max)-1/2 (min)-1/2 Ellipse equation:
Visualization of second moment matrices
Visualization of second moment matrices
Interpreting the eigenvalues Classification of image points using eigenvalues of M: 2 “Edge” 2 >> 1 “Corner” 1 and 2 are large, 1 ~ 2; E increases in all directions 1 and 2 are small; E is almost constant in all directions “Edge” 1 >> 2 “Flat” region 1
Corner response function α: constant (0.04 to 0.06) “Edge” R < 0 “Corner” R > 0 |R| small “Edge” R < 0 “Flat” region
Harris Detector: Steps
Harris Detector: Steps Compute corner response R
Harris Detector: Steps Find points with large corner response: R>threshold
Harris Detector: Steps Take only the points of local maxima of R
Harris Detector: Steps
Harris detector: Summary of steps Compute Gaussian derivatives at each pixel Compute second moment matrix M in a Gaussian window around each pixel Compute corner response function R Threshold R Find local maxima of response function (nonmaximum suppression)
Invariance We want features to be detected despite geometric or photometric changes in the image: if we have two transformed versions of the same image, features should be detected in corresponding locations
Models of Image Change Geometric Photometric Rotation Scale Affine valid for: orthographic camera, locally planar object Photometric Affine intensity change (I a I + b)
Harris Detector: Invariance Properties Rotation Ellipse rotates but its shape (i.e. eigenvalues) remains the same Corner response R is invariant to image rotation
Harris Detector: Invariance Properties Affine intensity change Only derivatives are used => invariance to intensity shift I I + b Intensity scale: I a I R x (image coordinate) threshold Partially invariant to affine intensity change
Harris Detector: Invariance Properties Scaling Corner All points will be classified as edges Not invariant to scaling
Scale-invariant feature detection Goal: independently detect corresponding regions in scaled versions of the same image Need scale selection mechanism for finding characteristic region size that is covariant with the image transformation
Scale-invariant features: Blobs
Recall: Edge detection f Derivative of Gaussian Edge = maximum of derivative Source: S. Seitz
Edge detection, Take 2 f Edge Second derivative of Gaussian (Laplacian) Edge = zero crossing of second derivative Source: S. Seitz
From edges to blobs Edge = ripple Blob = superposition of two ripples maximum Spatial selection: the magnitude of the Laplacian response will achieve a maximum at the center of the blob, provided the scale of the Laplacian is “matched” to the scale of the blob
original signal (radius=8) Scale selection We want to find the characteristic scale of the blob by convolving it with Laplacians at several scales and looking for the maximum response However, Laplacian response decays as scale increases: increasing σ original signal (radius=8) Why does this happen?
Scale normalization The response of a derivative of Gaussian filter to a perfect step edge decreases as σ increases
Scale normalization The response of a derivative of Gaussian filter to a perfect step edge decreases as σ increases To keep response the same (scale-invariant), must multiply Gaussian derivative by σ Laplacian is the second Gaussian derivative, so it must be multiplied by σ2
Effect of scale normalization Original signal Unnormalized Laplacian response Scale-normalized Laplacian response maximum
Blob detection in 2D Laplacian of Gaussian: Circularly symmetric operator for blob detection in 2D
Blob detection in 2D Laplacian of Gaussian: Circularly symmetric operator for blob detection in 2D Scale-normalized:
Scale selection The 2D Laplacian is given by Therefore, for a binary circle of radius r, the Laplacian achieves a maximum at (up to scale) Laplacian response r scale (σ) image
Characteristic scale We define the characteristic scale as the scale that produces peak of Laplacian response characteristic scale T. Lindeberg (1998). "Feature detection with automatic scale selection." International Journal of Computer Vision 30 (2): pp 77--116.
Scale-space blob detector Convolve image with scale-normalized Laplacian at several scales Find maxima of squared Laplacian response in scale-space
Scale-space blob detector: Example
Scale-space blob detector: Example
Scale-space blob detector: Example
Efficient implementation Approximating the Laplacian with a difference of Gaussians: (Laplacian) (Difference of Gaussians)
Efficient implementation David G. Lowe. "Distinctive image features from scale-invariant keypoints.” IJCV 60 (2), pp. 91-110, 2004.
From scale invariance to affine invariance
Affine adaptation Recall: We can visualize M as an ellipse with axis lengths determined by the eigenvalues and orientation determined by R direction of the slowest change direction of the fastest change (max)-1/2 (min)-1/2 Ellipse equation:
Affine adaptation The second moment ellipse can be viewed as the “characteristic shape” of a region We can normalize the region by transforming the ellipse into a unit circle
Orientation ambiguity There is no unique transformation from an ellipse to a unit circle We can rotate or flip a unit circle, and it still stays a unit circle
Orientation ambiguity There is no unique transformation from an ellipse to a unit circle We can rotate or flip a unit circle, and it still stays a unit circle So, to assign a unique orientation to keypoints: Create histogram of local gradient directions in the patch Assign canonical orientation at peak of smoothed histogram 2 p
Affine adaptation Problem: the second moment “window” determined by weights w(x,y) must match the characteristic shape of the region Solution: iterative approach Use a circular window to compute second moment matrix Perform affine adaptation to find an ellipse-shaped window Recompute second moment matrix using new window and iterate
Iterative affine adaptation K. Mikolajczyk and C. Schmid, Scale and Affine invariant interest point detectors, IJCV 60(1):63-86, 2004. http://www.robots.ox.ac.uk/~vgg/research/affine/
Affine adaptation example Scale-invariant regions (blobs)
Affine adaptation example Affine-adapted blobs
Summary: Feature extraction Eliminate rotational ambiguity Compute appearance descriptors Extract affine regions Normalize regions SIFT (Lowe ’04)
Invariance vs. covariance features(transform(image)) = features(image) Covariance: features(transform(image)) = transform(features(image)) Covariant detection => invariant description