480 likes | 584 Views
Lecture 10 Roger S. Gaborski. Computer Vision. Algorithm Development: Edges. We would like to develop algorithms that detect important edges in images The ‘quality’ of edges will depend on the image characteristics Noise can result in false edges. Profiles of an Ideal Edge.
E N D
Lecture 10 Roger S. Gaborski Computer Vision Roger S. Gaborski
Algorithm Development: Edges • We would like to develop algorithms that detect important edges in images • The ‘quality’ of edges will depend on the image characteristics • Noise can result in false edges Roger S. Gaborski
Profiles of an Ideal Edge Roger S. Gaborski
Profile of Edge - Analysis • Same gray level input range [0,1] • Edge is located at ‘peak’ of first derivative • Cannot choose only one threshold value because range of first derivative depends on slope of gray level values • The edge is located where the second derivative goes through zero-independent of slope of gray level signal Roger S. Gaborski
Edge Detection is Not Simple Roger S. Gaborski
The derivative operation can be used to detect edgesHow can the derivative operator be approximated in a digital image?? Roger S. Gaborski
MATLAB Examples • Approximation to derivative – difference of adjacent data values • data = [ .10 .14 .13 .12 .11 .10 .11 .34 .33 .32 .35 .10 .11 .12 .12 .12]; • diff operator: second- first data value (.14-.10) • diff(data) = 0.04 -0.01 -0.01 -0.01 -0.01 0.01 0.23 -0.01 -0.01 0.03 -0.25 0.01 0.01 0 0 diff operator is approximation to first derivative Roger S. Gaborski
Estimate of Second Derivative • diff(diff( data)) • -0.05 0 0.0 0 0.02 0.22 -0.24 0 0.04 -0.28 0.26 0 -0.0100 0 Roger S. Gaborski
Simulated Data data diff(data) diff(diff(data)) Roger S. Gaborski
How would you implement in a filter? • diff: second value – first value [ -1 +1 ] (could also use [+1 -1]) • Could also represent as: [-1 0 +1] • Use in correlation filter – same results Roger S. Gaborski
Actual Image Data Roger S. Gaborski
Row 80 Roger S. Gaborski
diff Operator Roger S. Gaborski
Smooth Image First Roger S. Gaborski
Gradient of a 2D Function Gradient is defined by a vector (see pg 366): Δ f = gx = f / x gy f / y The magnitude of the vector: mag( f) =[ gx2 + gy2 ]1/2 Δ Roger S. Gaborski
Direction of Gradient • The gradient points in the direction of maximum change of intensity α(x,y) = tan-1 (gy / gx) Roger S. Gaborski
Partial Derivatives in Vertical and Horizontal Directions • Vertical (y direction) • Horizontal (x direction) Roger S. Gaborski
Partial Derivatives in Vertical and Horizontal Directions 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 .* = 6 VERTICAL GRADIENT Roger S. Gaborski
First Derivative Approximation y+1 y y-1 eq1 eq2 x-1 x x+1 Roger S. Gaborski
First Derivative Approximation • First Derivative in x direction: fx (x,y) = f(x,y) – f(x-1,y) Eq 1 = f(x+1,y) – f(x,y) Eq 2 • First Derivative in y direction: fy(x,y) = f(x,y) – f(x, y-1) Eq3 = f(x, y+1) - f(x,y) Eq4 Roger S. Gaborski
First Derivative Approximation y+1 y y-1 eq1 eq2 x-1 x x+1 Roger S. Gaborski
Edge Detection • An Edge is defined as a discontinuity within a local set of pixels. x-1 x x+1 y+1 y y-1 Roger S. Gaborski
fy = (28-15)/2+(27-17)/2+(26-16)/2= fy = -6.5- 5.0 - 5.0 = 16.5 fx = (26-28)/2+(31-30)/2+(16-15)/2= fx = -1 + .5 + .5 = 0 Divide by 2 because 2 pixels apart. • = tan-1 (fy/fx) = tan-1 (16.5/0) = 90 degrees mag(f ) = [ fy2 + fx2 ]1/2 = 16.5 x-1 x x+1 y+1 y y-1 Roger S. Gaborski Y –direction X -direction
fy = (38-12)/2+(66-15)/2+(65-42)/2= fy = 13.00 + 25.5+ 11.5 = 50 fx = (65-38)/2+(64-14)/2+(42-12)/2= fx = 13.5 0+ 25.00 + 15.00 = 53.5 Divide by 2 because 2 pixels apart. Ignore dividing by two simply introduces a scaling error, but results in faster calculation • = tan-1 (fy/fx) = tan-1 (50/53.5)= 43 degrees mag(f ) = [ fy2 + fx2 ]1/2 = 73 Roger S. Gaborski Y –direction X -direction
Second Derivative Approximation • Discrete version of 2nd Partial Derivation of f(x,y) in x direction is found by taking the difference of Eq1 and Eq2: • 2 f(x,y) / x2 = Eq1-Eq2 = 2f(x,y)-f(x-1,y)-f(x+1,y) In y direction: • 2 f(x,y) / y2 = Eq3-Eq4 = 2f(x,y)-f(x,y-1)-f(x,y+1) Roger S. Gaborski
Derivative Approximation for Laplacian y+1 y y-1 x-1 x x+1 Roger S. Gaborski
Laplacian • Independent of edge orientation • Combine 2 f(x,y)/ x2 and 2 f(x,y)/ y2 =4 f(x,y) - f(x-1,y) – f(x+1,y) – f(x,y-1) – f(x,y+1) Roger S. Gaborski
EXAMPLE: Using Sobel Edge Filter Roger S. Gaborski
Simple First Derivative Approximation Difference x = Smoothing Roger S. Gaborski
Rotate Filter Sensitive to edges at different orientations Roger S. Gaborski
Sobel Filter • Consider unequal weights for smoothing operation = Sy x = Roger S. Gaborski
Sobel Filter • Consider unequal weights for smoothing operation = Sx x = Roger S. Gaborski
Sobel Edge Filter >> fh=fspecial('sobel') fh = 1 2 1 0 0 0 -1 -2 -1 >> Ifh=imfilter(Ig,fh); >> fv=f' fv = 1 0 -1 2 0 -2 1 0 -1 >> Ifv=imfilter(Ig,fv); Ifh is an image containing the Horizontal edges Ifv is an image containing the Vertical edges Can we use the command: figure, imshow(Ifh) to display the horizontal edges?? Roger S. Gaborski
>> max(Ifh(:)) ans = 2.8849 >> min(Ifh(:)) ans = -2.9685 Roger S. Gaborski
Horizontal Edges Vertical Edges Roger S. Gaborski
Sum of Horizontal and Vertical Edges Roger S. Gaborski
Absolute Value of Sum of Horizontal and Vertical Edges Roger S. Gaborski
Threshold of Absolute Value of Sum of Horizontal and Vertical Edges T=1 T=.5 Roger S. Gaborski
Threshold of Absolute Value of Sum of Horizontal and Vertical Edges T=.25 T=.1 Roger S. Gaborski
build1.jpg Roger S. Gaborski
Edge image Roger S. Gaborski
~ Operator Roger S. Gaborski
Box Image Roger S. Gaborski
Note missing Horizontal Edges Roger S. Gaborski
What are Edgels Edgels are defined as a rapid change in the image function over a small area Roger S. Gaborski
Edgels • Edgels have three properties: • Direction • Magnitude • Location • Edgels are not complete edges • They provide evidence for higher level structures, such as, boundary lines, contours Roger S. Gaborski