Feature Extraction Line & Curve 2/25/11 ECEn 631
Standard Procedure Locate edges within the image Link broken edges Thin thick edges For every edge pixel, find possible parameters Locate all clusters of parameters Average each cluster to find accurate parameters
3
4
Given a number of edge or feature pixels How to extract a line, curve, circle, or ellipse?
Line Detection Detects complex patterns of points in binary image. Maps a complex pattern decision problem into a simple peak detection problem in the space of the parameters of the curve Any line, y = m x + c, can be represented by a point in the m, c plane. Any point, [x, y], corresponds to a line c = -m x + y in parameter space. Different m and c represent different lines that pass the same point [x, y]
Peak Detection Image Space x Parameter Space m c y (10,22) and (30,62) n=-10m+22 and n=-30m+62 Multiple lines passing the same point
Y = m x + c for a vertical line? It won t work. Ex. (c, r)=(50, 50) θ< 0 0 50 θ d 50 c 50 θ d 50 c r θ=315 0 or -45 0 r θ=330 0 or -30 0 8
Ex. (c, r)=(50, 50) θ = 0 0 θ = -90 0 D=50 Θ=0 50 c D=50 50 c 50 50 r θ=0 0 r θ=270 0 or -90 0 9
Ex. (c, r)=(50, 50) θ > 0 0 θ > 180 0 d 50 c d 50 c 50 θ=30 0 50 r r θ=240 0 or -120 0 10
Ex. (c, r)=(50, 50) D=0 50 c Ex. (c, r)=(40, 30) D=0 40 30 c 50 r Θ~45 0 or 225 0 r Θ~53.1 0 or 233.1 0 There is a discontinuity between 11
12
Example P = [c, r] = [50, 50] and θ = 315 0 d = 50 cos(315) 50 sin(315) = 50(0.707)-50(-0.707) = 70 d θ 13
For each feature pixel, calculate d for all angles. 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 d 10 9 8 7 5 4 3 2 1 0 0 5 10 15 20 25 30 35 40 45 50 55 60 5 70 75 80 85 90 14 θ
0 2.0 5 2.2 10 2.3 15 2.4 20 2. 25 2.7 30 2.7 35 2.8 40 2.8 45 2.8 50 2.8 55 2.8 60 2.7 65 2.7 70 2. 75 2.4 80 2.3 85 2.2 90 2.0 5 5 5 5 4 4 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 1 0 1 1 1 1 1 1 0 0 0 0 1 0 0 0 0 0 1 0 For each feature pixel, calculate d for all angles. d 10 9 8 1 1 1 1 1 1 1 7 1 1 2 3 3 2 2 2 2 2 1 1 1 1 1 1 1 2 4 5 4 3 3 4 4 4 4 3 3 3 2 1 1 1 1 1 5 5 5 4 3 3 3 4 3 2 2 2 3 3 3 5 5 4 2 1 1 4 2 1 1 1 1 1 2 1 1 2 3 3 3 3 3 3 3 4 5 5 3 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 1 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 1 1 1 1 1 1 1 0 5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 15 θ
What do you do next? Find Local Maxima. Why and how? Noise from edge detector and curved contour generate local and noisy peaks. A unique and single peak is almost impossible. Interpolation or weighted average will yield better accuracy (better than 5 degrees in this case) Set a limit on the closest distance between two peaks 10 9 8 1 1 1 1 1 1 1 7 1 1 2 3 3 2 2 2 2 2 1 1 1 1 1 1 1 2 4 5 4 3 3 4 4 4 4 3 3 3 2 1 1 1 1 1 5 5 5 4 3 3 3 4 3 2 2 2 3 3 3 5 5 4 2 1 1 4 2 1 1 1 1 1 2 1 1 2 3 3 3 3 3 3 3 4 5 5 3 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 1 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 1 1 1 1 1 1 1 0 5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 1
6 5 4 6 5 4 1 1 2 5 5 2 1 1-5 0 5 1 1 2 4 5 1 1 1-5 0 5 θ = (1 ( 5 o )+1 0 o + 2 5 o + 4 ( 5 o )+ 6 0 o + 5 5 o + 2 ( 5 o )+1 0 o +1 5 o )/23 = 0.22 o d = (1 6 +1 6 + 2 6 + 4 5 + 6 5 + 5 5 + 1 4 +1 4 +1 4)/22 = 5.04545 17
18
19
An easier but not so accurate method 0 0 30 30 0 0 0 0 10 10 0 0 0 0 10 10 0 0 0 0 10 10 10 10 10 10 10 10 10 10 10 10 10 10 0 0 0 0 0 0 E x E y 0 0 20 20 0 0 10 10 0 0 0 0 0 0 0 0 30 30 20 10 30 30 20 10 30 30 30 30 20
0 0 30 30 0 0 0 0 E x 0 0 20 20 0 0 10 10 0 0 0 0 E y 30 30 20 10 30 30 20 10 30 30 30 30 0 0 0 0 0 0 d 0 4 5 0 0 3 3 4.9 5.8 0 0 4 4 5.4 6.4 0 0 5 5 5 5 0 θ 0 0 90 90 45 2 90 90 63 45 90 90 90 90-90 o =90 o 0 0 0 0 0 0 21
360 357 Store points to a list: d 3 2 1 2 1 8 0 0 10 20 30 40 50 60 70 80 90 θ 0 0 =(4,2)(5,2) 20 0 =(5,3) 40 0 =(4,3)(5,4) 60 0 =(4,4) 90 0 =(2,3)(2,4)(2,5)(3,3)(3,4) (3,5)(4,5)(5,5) 22
OpenCV Standard Hough transform (SHT) Accumulate all points HoughLines( Mat& image, vector<vec2f>& lines, double rho, double theta, int threshold, double srn=0, double stn=0 ); Progressive probabilissc Hough transform (PPPHT) Accumulate only a fracson of points to reduce computason Sme. HoughLinesP( Mat& image, vector<vec4i>& lines, double rho, double theta, int threshold, double minlinelength=0, double maxlinegap=0 ); 23
Circle Detection sinθ = E y /E cosθ = E x /E If a point [R, C] is given, a radius d is selected, and the direction of the vector from [R, C] to the center is computed, the coordinates of the center can be found. The radius d, row center r o, and column center c o are the three parameters used to vote for circles in the Hough Transform. It can be simplified if radius is known. 24
Circle Detection The accumulator is 3-dimensional (d, r o, c o ) Needs more memory and runs slower than line (2-D) Hough gradient method: Faster but not as accurate Find edge points Calculate their gradients local maxima selected as centers find points that have equal distance to a center H. K. Yuen, J. Princen, J. Illingworth, and J. Kittler. Comparative study of hough transform methods for circle finding. Image Vision Comput., 8(1):71 77, 1990. 25
Finding Any Curves A curve can be expressed as y = f (x,a), where a = [a 1,a 2,,a p ] is a vector of p parameters. Create an array A(s 1,s 2,,s p ) as an accumulator for all parameters, where s 1,s 2,,s p are the sizes of parameters. For each pixel E(i, j) such that when increment accumulator on the curve defined by y = f (x,a). Search local maxima. The output is a set of a 1,a 2,,a p that is the best representation of the curve. 2
Generalized Hough Transform Detects arbitrary shapes Select a localization point L within a template of the shape Move from an edge point to L Vote will peak at L D.H. Ballard, "Generalizing the Hough Transform to Detect Arbitrary Shapes", Pattern Recognition, Vol.13, No.2, p.111-122, 1981 θ R α L 27
HT is a voting algorithm (histogram) More efficient than pattern matching All points are processed independently Works well even with occlusion Robust to noise Computation time is long (ex. Line is faster than circle) Non-target shapes can cause problems 28