Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 08 Detecting Shape Using Hough Transform Lecture 08 Detecting Shape Using Hough Transform Mata kuliah: T0283 - Computer Vision Tahun: 2010.

Similar presentations


Presentation on theme: "Lecture 08 Detecting Shape Using Hough Transform Lecture 08 Detecting Shape Using Hough Transform Mata kuliah: T0283 - Computer Vision Tahun: 2010."— Presentation transcript:

1

2 Lecture 08 Detecting Shape Using Hough Transform Lecture 08 Detecting Shape Using Hough Transform Mata kuliah: T0283 - Computer Vision Tahun: 2010

3 January 20, 2010T0283 - Computer Vision3 Learning Objectives After carefullylistening this lecture, students will be able to do the following : After carefully listening this lecture, students will be able to do the following : explain how Hough Transforms are used to detect primitive shapes such as line and circle explain how Hough Transforms are used to detect primitive shapes such as line and circle demonstrate HT-based line and circle detection using MATLAB/OpenCV demonstrate HT-based line and circle detection using MATLAB/OpenCV

4 January 20, 2010T0283 - Computer Vision4 Line Detection Using Mask The mask shown below can be used to detect lines at various orientation

5 January 20, 2010T0283 - Computer Vision5 Hough Transform An algorithm to group edge points from edge detectors or from any other process

6 January 20, 2010T0283 - Computer Vision6 Straight Line Case Consider the slope-intercept equation of line y = ax + b a, b are constant, x is a variable, and y is a function of x Rewrite the equation as follows : b = -xa + y Now x, y are constant, a is a variable, b is a function of a

7 January 20, 2010T0283 - Computer Vision7 Algorithm The following properties are true Points lying on the same line in the x-y space, define lines in the parameter space which all intersect at the same point The coordinates of the point of intersection define the parameters of the line in the x-y space Algorithm For each edge point (x,y) for (a = a min ; a ≤ a max ; a++) b = -xa +y; P[a][b] ++;/*accumulator array*/ Find local maxima in P[a][b]

8 January 20, 2010T0283 - Computer Vision8 Problem with slope-intercept equation The slope can become very large or infinity. It will be impossible to quantize such a large space Polar representation of lines x cos  + y sin  =  (if the line is vertical,  = 0, x =  )   x 1,y 1 x y

9 January 20, 2010T0283 - Computer Vision9 Polar Representation of Lines HT uses the parametric representation of a line:  = x cos  + y sin  (*)  is the distance from the origin to the line along a vector  is the distance from the origin to the line along a vector perpendicular to the line. perpendicular to the line.  is the angle between the x-axis and this vector  is the angle between the x-axis and this vector. Hough function generates a parameter space matrix whose rows and columns correspond to  and  values whose rows and columns correspond to  and  values respectively. respectively. Peak values in this space represent potential lines in the input image. input image.

10 January 20, 2010T0283 - Computer Vision10 Algorithm Construct accumulator array in 2D ( ,  ) Initial values 0 Select granularity of angle  For instance 10  increments For every edge point Compute  using (*) Increment accumulator array by one for each computed ( ,  ) pair.

11 January 20, 2010T0283 - Computer Vision11 Hough Transform

12 January 20, 2010T0283 - Computer Vision12 Hough Transform

13 January 20, 2010T0283 - Computer Vision13 Hough Transform : Issues Noise Points slightly off curve result in multiple intersections Can use larger bins, smooth accumulator array Non-maximum suppression a good idea to get unique peaks Dimensionality Exponential increase in size of accumulator array as number of shape parameters goes up HT works best for shapes with 3 or fewer variables

14 January 20, 2010T0283 - Computer Vision14 clear all;clc; I = imread('line1.png'); I =im2bw(I); I = ~I; [y,x]=find(I); [sy,sx]=size(I) figure, imshow(I); totalpix = length(x); maxrho = round(sqrt(sx^2 + sy^2)); HM = zeros(2*maxrho,180); MATLAB Implementation

15 January 20, 2010T0283 - Computer Vision15 for cnt = 1:totalpix cnt2 = 1; for theta = -pi/2:pi/180:pi/2-pi/180 rho = round(x(cnt).*cos(theta) + y(cnt).*sin(theta)); HM(rho+maxrho,cnt2) = HM(rho+maxrho,cnt2) + 1; cnt2 = cnt2 + 1; end theta = rad2deg(-pi/2:pi/180:pi/2-pi/180); rho = -maxrho:maxrho-1; figure, imshow(uint8(HM),[],'xdata',theta,'ydata',rho); xlabel('\theta'),ylabel('\rho') axis on, axis normal; title('Hough Matrix'); MATLAB Implementation

16 January 20, 2010T0283 - Computer Vision16 Examples of Line Detection using HT

17 January 20, 2010T0283 - Computer Vision17 Examples of Line Detection using HT

18 January 20, 2010T0283 - Computer Vision18 Circle Case Similar to line fitting Three unknowns Construct a 3D accumulator array A Dimensions: x 0, y 0, r Fix one of the parameters change the others Increment corresponding entry in A. Find the local maxima in A

19 January 20, 2010T0283 - Computer Vision19 Circle Fitting

20 January 20, 2010T0283 - Computer Vision20 Circle Fitting

21 January 20, 2010T0283 - Computer Vision21 clear all;clc; I = imread('pic21.bmp'); I =im2bw(I); [y,x]=find(I); [sy,sx]=size(I) figure, imshow(I); totalpix = length(x); HM = zeros(sy,sx,50); R = 1:30; R2 = R.^2; sz = sy*sx; MATLAB Implementation

22 January 20, 2010T0283 - Computer Vision22 for cnt = 1:totalpix for cntR = 1:30; b = 1:sy; a = (round(x(cnt) - sqrt(R2(cntR) - (y(cnt) - [1:sy]).^2))); b = b(imag(a)==0 & a>0); a = a(imag(a)==0 & a>0); ind = sub2ind([sy,sx],b,a); HM(sz*(cntR-1)+ind) = HM(sz*(cntR-1)+ind) + 1; end for cnt = 1:30 H(cnt) = max(max(HM(:,:,cnt))); end figure, plot(H,'*-'); MATLAB Implementation

23 January 20, 2010T0283 - Computer Vision23 b = 1:sy; for cnt = 1:totalpix a = (round(x(cnt) - sqrt(R2 - (y(cnt) - [1:sy]).^2))); for cnt2 =1:sy if isreal(a(cnt2)) & a(cnt2)>0 HM(cnt2,a(cnt2)) = HM(cnt2,a(cnt2)) + 1; end figure,imshow(HM,[]); MATLAB Implementation

24 January 20, 2010T0283 - Computer Vision24 [maxval, maxind] = max(H); [B,A] = find(HM(:,:,maxind)==maxval) figure,imshow(I); hold on; plot(mean(A),mean(B),'xr') text(mean(A),mean(B),num2str(maxind),'color','green') MATLAB Implementation

25 January 20, 2010T0283 - Computer Vision25 Examples of Circle Detection using HT


Download ppt "Lecture 08 Detecting Shape Using Hough Transform Lecture 08 Detecting Shape Using Hough Transform Mata kuliah: T0283 - Computer Vision Tahun: 2010."

Similar presentations


Ads by Google