Edge Detection Low Level
Total Page:16
File Type:pdf, Size:1020Kb
Image Processing - Lesson 10 Image Processing - Computer Vision Edge Detection Low Level • Edge detection masks Image Processing representation, compression,transmission • Gradient Detectors • Compass Detectors image enhancement • Second Derivative - Laplace detectors • Edge Linking edge/feature finding • Hough Transform image "understanding" Computer Vision High Level UFO - Unidentified Flying Object Point Detection -1 -1 -1 Convolution with: -1 8 -1 -1 -1 -1 Large Positive values = light point on dark surround Large Negative values = dark point on light surround Example: 5 5 5 5 5 -1 -1 -1 5 5 5 100 5 * -1 8 -1 5 5 5 5 5 -1 -1 -1 0 0 -95 -95 -95 = 0 0 -95 760 -95 0 0 -95 -95 -95 Edge Definition Edge Detection Line Edge Line Edge Detectors -1 -1 -1 -1 -1 2 -1 2 -1 2 -1 -1 2 2 2 -1 2 -1 -1 2 -1 -1 2 -1 -1 -1 -1 2 -1 -1 -1 2 -1 -1 -1 2 gray value gray x edge edge Step Edge Step Edge Detectors -1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 -1 1 1 -1 -1 -1 -1 1 1 1 1 -1 1 -1 -1 1 1 1 1 1 1 gray value gray -1 -1 1 1 1 -1 1 1 x edge edge Example Edge Detection by Differentiation Step Edge detection by differentiation: 1D image f(x) gray value gray x 1st derivative f'(x) threshold |f'(x)| - threshold Pixels that passed the threshold are -1 -1 1 1 -1 -1 -1 -1 Edge Pixels -1 -1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 1 1 1 -1 -1 1 1 1 -1 1 1 Gradient Edge Detection Gradient Edge - Examples ∂f ∂x ∇ f((x,y) = Gradient ∂f ∂y ∂f ∇ f((x,y) = ∂x , 0 f 2 f 2 Gradient Magnitude ∂ + ∂ √( ∂ x ) ( ∂ y ) ∂f ∂f Gradient Direction tg-1 ( / ) ∂y ∂x ∂f ∇ f((x,y) = 0 , ∂y Differentiation in Digital Images Example Edge horizontal - differentiation approximation: ∂f(x,y) Original FA = ∂x = f(x,y) - f(x-1,y) convolution with [ 1 -1 ] Gradient-X Gradient-Y vertical - differentiation approximation: ∂f(x,y) FB = ∂y = f(x,y) - f(x,y-1) convolution with 1 -1 Gradient-Magnitude Gradient-Direction Gradient (FA , FB) 2 2 1/2 Magnitude ((FA ) + (FB) ) Approx. Magnitude |FA | + |FB| Roberts Edge Detector Sobel Edge Detector F = f(x,y) - f(x-1,y-1) A -1 0 1 -1 -2 -1 FB = f(x-1,y) - f(x,y-1) A = -2 0 2 B = 0 0 0 -1 0 1 1 2 1 1 0 0 1 A = B = 0 -1 -1 0 Roberts and other 2x2 operators are sensitive to noise. Isotropic Edge Detector Prewitt Edge Detector -1 0 1 -1 -√2 -1 A = -√2 0 √2 B = 0 0 0 -1 0 1 -1 -1 -1 -1 0 1 1 √2 1 A = -1 0 1 B = 0 0 0 -1 0 1 1 1 1 Smoothed operators Edge Detector - Comparison Compass Operators 1 1 1 1 1 0 1 0 -1 0 -1 -1 Original 0 0 0 1 0 -1 1 0 -1 1 0 -1 -1 -1 -1 0 -1 -1 1 0 -1 1 1 0 N NW WSW -1 -1 -1 -1 -1 0 -1 0 1 0 1 1 Roberts 0 0 0 -1 0 1 -1 0 1 -1 0 1 1 1 1 0 1 1 -1 0 1 -1 -1 0 S SE ENE Given k operators, g (x,y) is the image obtained by Sobel k convolving f(x,y) with the kth operator. The gradient is defined as: g(x,y) = max gk(x,y) Prewitt k k defines the edge direction Magnitude Negative Magnitude Various Compass Operators: Edge Detector - Comparison 1 1 1 1 1 1 1 2 1 Original 1 -2 1 0 0 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -2 -1 5 5 5 Sobel -3 0 -3 Kirsch Edge Detector -3 -3 -3 Kirsch (Compass) Direction Map Magnitude Negative Magnitude Laplacian Operators Derivatives Approximation of second derivative (horizontal): ∂f2(x,y) ∂2x = f''(x,y) = f'(x+1,y) - f'(x,y) = = [f(x+1,y) - f(x,y)] - [f(x,y) - f(x-1,y)] f(x) = f(x+1,y) - 2 f(x,y) + f(x-1,y) convolution with: [ 1 -2 1] Approximation of second derivative (vertical): f (x) convolution with: 1 -2 1 2 2 f (x) 2 ∂ ∂ Laplacian Operator ∇ = ( ∂ x 2 + ∂ y 2 ) 0 -1 0 zero crossing convolution with: -1 4 -1 0 -1 0 Variations on Laplace Operators: Example of Laplacian Edge Detection 1 -2 1 0 -1 0 -1 -1 -1 -2 4 -2 -1 4 -1 -1 8 -1 1 -2 1 0 -1 0 -1 -1 -1 All are approximations of: Laplacian ~ Difference of gaussians Laplacian Operator Laplacian Filter (Image Domain) (Frequency Domain) - = FFT DOG = Difference of Gaussians - = FFT - = Enhancement Using the Laplacian Operator Examples of enhanced images Original Laplacian Image Edge Image f(x) ∂f 1st derivative ∂x 2nd derivative ∂2f (Laplacian) ∂x2 2 - ∂ f ∂x2 Scaled Laplacian Image Enhanced Image 2 f(x) - ∂ f ∂x2 Mach Bands Edge Detection - Noise Issues Edge Detection - Noise Issues f f ( x ) g d f ( x ) g ∗ f dx ∂ ()g ∗ f ∂x ∂ Peaks in () g ∗ f mark the edge ∂x Edge Detection - Noise Issues Edge Detection - Noise Issues From the convolution theorem we have: ∂ ⎛ ∂ ⎞ ()h ∗ f = ⎜ h ⎟ ∗ f ∂x ⎝ ∂x ⎠ f ∂ 2 g f ∂x 2 ⎛ ∂ 2 ⎞ ∂ ⎜ g ⎟ ∗ f h ⎜ 2 ⎟ ∂x ⎝ ∂x ⎠ ⎛ ∂ ⎞ ⎜ h ⎟ ∗ f ⎝ ∂x ⎠ ∂ 2 Zero Crossings in () g ∗ f mark the edge ∂x 2 Canny Edge Detector Canny Edge Detector - Step 1 1) Convolve image with derivative of a Gaussian Convolve image with derivative of a Gaussian 2) Perform NonMaximum suppression. 3) Perform Hysteresis Thresholding. f(x,y) * G'(x,y) ≅ f(x,y) * G'x(x,y) + f(x,y) * G'y(x,y) Fa = f(x,y) * Gx(x,y) * Dx(x,y) = f(x,y) *1 2 4 2 1 * 1 -1 Fb = f(x,y) * Gy(x,y) * Dy(x,y) 1 2 1 = f(x,y) *4 * -1 2 1 2 2 1/2 Magnitude ((FA ) + (FB) ) Canny Edge Detector - Step 1 Canny Edge Detector - Step 2 NonMaximum suppression. Original Remove edges that are NOT local Maxima in the gradient direction. x x x x x x f * Gx f * Gy Local Maxima Local Maxima Fa = Fb = f*Gx*Dx f*Gy*Dy Magnitude 2 2 1/2 ((FA ) + (FB) ) Canny Edge Detector - Step 2 Canny Edge Detector - Step 3 Hysteresis Thresholding. NonMaximum Suppression. Magnitude NonMaximum Supression Edge Pixel High Threshold Possible Edge Pixel Low Threshold Non-Edge Pixel Include possible edge pixels that are adjacent to edge pixels. Canny Edge Detector - Step 3 Effect of Scale Effect of σ (Gaussian kernel size) Magnitude (NonMax original Suppressed) Low Threshold High Threshold Canny with σ = 1 Canny with σ = 2 Hysteresis Threshold Scale Space Edge Completion Witkin 83 first derivative peaks Gaussian filtered signal Properties of Scale Space: • Position of edges may change with scale. • Edges may merge with increase in scale. • Edges do NOT split with increase in scale. Edge Linking Examples of edge linking (x,y) is an edge pixel. Search for neighboring edge pixels that are "similar". Original Sobel Vertical Similarity: Similarity in Edge Orientation Similarity in Edge strength (Gradient Amplitude) Perform Edge Following along similar edge pixels. (as in Contour Following in binary images). Sobel Horizontal Linked Edges Edge Points linked: Gradient Value > 25 Gradient direction within 15% Hough Transform Problem: Edges are not lines even when linked. Image Domain Hough Domain s y (θ, s) s θ x θ straight line Hough Transform Edge pixels are not ellipses even when linked. y = ax+b s = xcos(θ)+ysin(θ) Hough Transform Hough Transform Image Domain Hough Domain y = ax+b s y (θ, s) y s s θ x θ x θ straight line Hough Transform many points on a line = many lines in the Hough transform space which intersect at 1 point. s y x θ single point = many possible lines Hough Transform Example Hough Transform Example Original Edges Original square image Hough Transform Hough Transform s (s,θ) space θ Results1 Results2 Results3 Reconstructed line segments Hough Transform Example Hough Transform for Circles Image Domain Hough Domain Original (x0,y0) r (x0,y0,r) y r y0 x x0 circle Hough Transform Edges 2 2 2 r = (x-x0) +(y-y0) Result Nice demo: http://www.markschulze.net/java/hough/index.html 3D Perception - Depth Perception Impossible Figures (Escher).