edge detection
DESCRIPTION
02/02/12. Edge Detection. Computer Vision (CS 543 / ECE 549) University of Illinois Derek Hoiem. Magritte, “Decalcomania”. Many slides from Lana Lazebnik, Steve Seitz, David Forsyth, David Lowe, Fei-Fei Li. Last class. How to use filters for Matching Compression - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/1.jpg)
Edge Detection
Computer Vision (CS 543 / ECE 549) University of Illinois
Derek Hoiem
02/02/12
Many slides from Lana Lazebnik, Steve Seitz, David Forsyth, David Lowe, Fei-Fei Li
Magritte, “Decalcomania”
![Page 2: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/2.jpg)
Last class
• How to use filters for– Matching– Compression
• Image representation with pyramids
• Texture and filter banks
![Page 3: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/3.jpg)
Issue from Tuesday• Why not use an ideal filter?
Attempt to apply ideal filter in frequency domain
Answer: has infinite spatial extent, clipping results in ringing
![Page 4: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/4.jpg)
Denoising
Additive Gaussian Noise
Gaussian Filter
![Page 5: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/5.jpg)
Smoothing with larger standard deviations suppresses noise, but also blurs the image
Reducing Gaussian noise
Source: S. Lazebnik
![Page 6: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/6.jpg)
Reducing salt-and-pepper noise by Gaussian smoothing
3x3 5x5 7x7
![Page 7: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/7.jpg)
Alternative idea: Median filtering• A median filter operates over a window by
selecting the median intensity in the window
• Is median filtering linear?Source: K. Grauman
![Page 8: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/8.jpg)
Median filter• What advantage does median filtering have over
Gaussian filtering?– Robustness to outliers, preserves edges
Source: K. Grauman
![Page 9: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/9.jpg)
Median filterSalt-and-pepper noise Median filtered
Source: M. Hebert
• MATLAB: medfilt2(image, [h w])
![Page 10: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/10.jpg)
Median vs. Gaussian filtering3x3 5x5 7x7
Gaussian
Median
![Page 11: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/11.jpg)
Other non-linear filters• Weighted median (pixels further from center count less)• Clipped mean (average, ignoring few brightest and darkest
pixels)• Max or min filter (ordfilt2)• Bilateral filtering (weight by spatial distance and intensity
difference)
http://vision.ai.uiuc.edu/?p=1455Image:
Bilateral filtering
![Page 12: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/12.jpg)
Bilateral filters• Edge preserving: weights similar pixels more
Carlo Tomasi, Roberto Manduchi, Bilateral Filtering for Gray and Color Images, ICCV, 1998.
Original Gaussian Bilateral
spatial similarity (e.g., intensity)
![Page 13: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/13.jpg)
Today’s class
• Detecting edges
• Finding straight lines
![Page 14: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/14.jpg)
Origin of Edges
• Edges are caused by a variety of factors
depth discontinuity
surface color discontinuity
illumination discontinuity
surface normal discontinuity
Source: Steve Seitz
![Page 15: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/15.jpg)
Closeup of edges
![Page 16: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/16.jpg)
Closeup of edges
![Page 17: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/17.jpg)
Closeup of edges
![Page 18: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/18.jpg)
Closeup of edges
![Page 19: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/19.jpg)
Characterizing edges• An edge is a place of rapid change in the image
intensity function
imageintensity function
(along horizontal scanline) first derivative
edges correspond toextrema of derivative
![Page 20: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/20.jpg)
Intensity profile Intensity
Gradient
![Page 21: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/21.jpg)
With a little Gaussian noise
Gradient
![Page 22: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/22.jpg)
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?Source: S. Seitz
![Page 23: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/23.jpg)
Effects of noise• 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 can we do about it?
Source: D. Forsyth
![Page 24: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/24.jpg)
Solution: smooth first
• To find edges, look for peaks in )( gfdxd
f
g
f * g
)( gfdxd
Source: S. Seitz
![Page 25: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/25.jpg)
• Differentiation is convolution, and convolution is associative:
• This saves us one operation:
gdxdfgf
dxd
)(
Derivative theorem of convolution
gdxdf
f
gdxd
Source: S. Seitz
![Page 26: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/26.jpg)
Derivative of Gaussian filter
• Is this filter separable?
* [1 0 -1] =
![Page 27: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/27.jpg)
• Smoothed derivative removes noise, but blurs edge. Also finds edges at different “scales”.
1 pixel 3 pixels 7 pixels
Tradeoff between smoothing and localization
Source: D. Forsyth
![Page 28: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/28.jpg)
Designing an edge detector• Criteria for a good edge detector:
– Good detection: the optimal detector should find all real edges, ignoring noise or other artifacts
– Good localization• the edges detected must be as close as possible to
the true edges• the detector must return one point only for each
true edge point
• Cues of edge detection– Differences in color, intensity, or texture across the boundary– Continuity and closure– High-level knowledge
Source: L. Fei-Fei
![Page 29: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/29.jpg)
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
![Page 30: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/30.jpg)
Example
input image (“Lena”)
![Page 31: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/31.jpg)
Derivative of Gaussian filter
x-direction y-direction
![Page 32: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/32.jpg)
Compute Gradients (DoG)
X-Derivative of Gaussian Y-Derivative of Gaussian Gradient Magnitude
![Page 33: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/33.jpg)
Get Orientation at Each Pixel• Threshold at minimum level• Get orientation
theta = atan2(-gy, gx)
![Page 34: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/34.jpg)
Non-maximum suppression for each orientation
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
![Page 35: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/35.jpg)
Bilinear Interpolation
http://en.wikipedia.org/wiki/Bilinear_interpolation
![Page 36: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/36.jpg)
Sidebar: Interpolation options• imx2 = imresize(im, 2, interpolation_type)
• ‘nearest’ – Copy value from nearest known– Very fast but creates blocky edges
• ‘bilinear’– Weighted average from four nearest known pixels– Fast and reasonable results
• ‘bicubic’ (default)– Non-linear smoothing over larger area– Slower, visually appealing, may create negative
pixel values
Examples from http://en.wikipedia.org/wiki/Bicubic_interpolation
![Page 37: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/37.jpg)
Before Non-max Suppression
![Page 38: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/38.jpg)
After non-max suppression
![Page 39: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/39.jpg)
Hysteresis thresholding
• Threshold at low/high levels to get weak/strong edge pixels• Do connected components, starting from strong edge pixels
![Page 40: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/40.jpg)
Hysteresis thresholding
• Check that maximum value of gradient value is sufficiently large– drop-outs? use hysteresis
• use a high threshold to start edge curves and a low threshold to continue them.
Source: S. Seitz
![Page 41: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/41.jpg)
Final Canny Edges
![Page 42: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/42.jpg)
Canny edge detector
1. Filter image with x, y derivatives of Gaussian 2. Find magnitude and orientation of gradient3. Non-maximum suppression:
– Thin multi-pixel wide “ridges” down to single pixel width
4. Thresholding and linking (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
![Page 43: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/43.jpg)
Effect of (Gaussian kernel spread/size)
Canny with Canny with original
The choice of depends on desired behavior• large detects large scale edges• small detects fine features
Source: S. Seitz
![Page 44: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/44.jpg)
Learning to detect boundaries
• Berkeley segmentation database:http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/segbench/
image human segmentation gradient magnitude
![Page 45: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/45.jpg)
pB boundary detector
Figure from Fowlkes
Martin, Fowlkes, Malik 2004: Learning to Detection Natural Boundaries…http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/papers/mfm-pami-boundary.pdf
![Page 46: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/46.jpg)
pB Boundary Detector
Figure from Fowlkes
![Page 47: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/47.jpg)
Brightness
Color
Texture
Combined
Human
![Page 48: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/48.jpg)
Results
Human (0.95)
Pb (0.88)
![Page 49: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/49.jpg)
Results
Human
Pb
Human (0.96)
Global PbPb (0.88)
![Page 50: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/50.jpg)
Human (0.95)
Pb (0.63)
![Page 51: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/51.jpg)
Human (0.90)
Pb (0.35)
For more: http://www.eecs.berkeley.edu/Research/Projects/CS/vision/bsds/bench/html/108082-color.html
![Page 52: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/52.jpg)
Global pB boundary detector
Figure from Fowlkes
![Page 53: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/53.jpg)
State of edge detection
• Local edge detection is mostly solved– Intensity gradient, color, texture
• Some methods to take into account longer contours, but could probably do better
• Poor use of object and high-level information
![Page 54: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/54.jpg)
Finding straight lines
![Page 55: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/55.jpg)
Finding line segments using connected components
1. Compute canny edges– Compute: gx, gy (DoG in x,y directions)– Compute: theta = atan(gy / gx)
2. Assign each edge to one of 8 directions3. For each direction d, get edgelets:
– find connected components for edge pixels with directions in {d-1, d, d+1}
4. Compute straightness and theta of edgelets using eig of x,y 2nd moment matrix of their points
5. Threshold on straightness, store segment
2
2
yyx
yxx
yyxyxx
M )eig(],[ Μλv))2,1(),2,2(2(atan vv
12 /conf
Larger eigenvector
![Page 56: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/56.jpg)
2. Canny lines … straight edges
![Page 57: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/57.jpg)
Homework 1• Due Feb 14, but try to finish by Tues (HW 2
will take quite a bit more time)
http://www.cs.illinois.edu/class/sp12/cs543/hw/CV_Spring12_HW1.pdf
![Page 58: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/58.jpg)
Things to remember• Canny edge detector = smooth derivative thin threshold link
• Pb: learns weighting of gradient, color, texture differences
• Straight line detector = canny + gradient orientations orientation binning linking check for straightness
![Page 59: Edge Detection](https://reader036.vdocuments.us/reader036/viewer/2022062520/56815ef0550346895dcdae96/html5/thumbnails/59.jpg)
Next classes: Correspondence and Alignment
• Detecting interest points
• Tracking points
• Object/image alignment and registration– Aligning 3D or edge points– Object instance recognition– Image stitching