hough transform
play

HOUGH TRANSFORM INEL 6088 - Fall 2018 - M. Toledo Jain et.al. - PowerPoint PPT Presentation

HOUGH TRANSFORM INEL 6088 - Fall 2018 - M. Toledo Jain et.al. section 6.8.4 Davies, section 9.2 and chapter 10 y = mx + b = x cos = x cos + y sin sin + sin tan = cos 1 slope = m = sin y-intercept =


  1. HOUGH TRANSFORM INEL 6088 - Fall 2018 - M. Toledo Jain et.al. section 6.8.4 Davies, section 9.2 and chapter 10

  2. y = mx + b = − x cos θ ρ ρ = x cos θ + y sin θ sin θ + sin θ tan θ = − cos θ 1 slope = m = − sin θ ρ y-intercept = b = sin θ θ θ line is a dot in parameter plane ρ ρ 90- θ c θ =cos θ ; s θ =sin θ θ

  3. For a point (x 1 , y 1 ) you get a curve in the ρ - θ plane. Each point in the curve correspond to a line passing thru (x 1 ,y 1 ) y ρ = x 1 cos θ + y 1 sin θ θ ρ x

  4. For co-linear points the curves intersect. y θ ρ x

  5. ρ = x 1 cos θ + y 1 sin θ Puntos (2,5) y (4,1) y ⇒ ρ , x ⇒ θ

  6. Example: θ versus ρ ; points (2,5) and (4,1) 90" 80" 70" 60" 50" θ" Series2" 40" 30" 20" θ =27; ρ =4 10" 0" 0" 1" 2" 3" 4" 5" 6" y= m x + b = - x/tan(27) + 4/sin(27) = -2x + 9

  7. Hough Transform for line detection The input is E, and M x N binary image in which each pixel E(i,j) is 1 if an edge pixel, 0 otherwise. Let ρ d , θ d be arrays containing discretized intervals of the ρ , θ parameter spaces ( ρ is within the image, θ is between 0 and π ), and R and T, respectively, their number of elements. 1. Discretize the parameter space of ρ and θ using sampling steps δρ , δθ , which must yield acceptable resolution and be of manageable size for ρ d and θ d. 2. Let A(R,T) be an array of integer counters. Initialize all elements to 0. 3.For each pixel E(i,j) = 1 and for h=1...T i. let ρ = i cos θ d (h) + j sin θ d (h) ii. find the index k of the element ρ d closest to ρ iii. increment A(k,h) by one 4. find all local maxima (k p , h p ) for which A(k p , h p ) > threshold. The output is a set of pairs ( ρ d (k p , h p ), θ d (k p , h p )) describing the detected lines in polar form.

  8. im = zeros(256,256); im = mat2gray(im); [nim xyp] = makeline(im, 3, 75, 255, 4, 1); figure; imshow(nim); [ints, slopes]=mc_hough(xyp); figure; plot(slopes, ints); [rhos angles]=hough(xyp, 1); figure; plot(angles, rhos); vm = votes(rhos, angles); % [newim, coords] = makeline(im, slope, yint, value, radious, period) % Creates a line in an 8-bit image. figure; mesh(vm); % newim: name of new image % im: initial image (without the line) % slope: line slope % yint: y intercept % value: line pixel graylevel % radious: radious of point (num of pixels) % 1 for single pixel % period: number of x points to omit between % calculations; use 0 for max points in line %

  9. 200 im = zeros(256,256); im = mat2gray(im); 100 [nim xyp] = makeline(im, 3, 75, 255, 4, 1); 0 figure; imshow(nim); -100 [ints, slopes]=mc_hough(xyp); -200 figure; plot(slopes, ints); -300 [rhos angles]=hough(xyp, 1); figure; plot(angles, rhos); -400 1 2 3 4 5 6 7 8 9 10 vm = votes(rhos, angles); figure; mesh(vm); function [ints, slopes] = mc_hough(pts) % function [intercepts slopes] = mc_hough(pts) % Draw an image for parameter space of hough transform % pts = matrix of point coordinates, size 2x(number of points) % % for each point draw a line;

  10. im = zeros(256,256); im = mat2gray(im); 300 250 [nim xyp] = makeline(im, 3, 75, 255, 4, 1); 200 figure; imshow(nim); 150 [ints, slopes]=mc_hough(xyp); 100 figure; plot(slopes, ints); 50 0 [rhos angles]=hough(xyp, 1); -50 figure; plot(angles, rhos); -100 0 20 40 60 80 100 120 140 160 180 vm = votes(rhos, angles); figure; mesh(vm); function [rhos, angles] = hough(pts, ar) % function [rhos angles] = hough(pts, ar, rr) % Draw an image for parameter space of hough transform % pts = matrix of point coordinates, size 2x(number of % points) % ar = theta (angle) resolution (example 10 degrees) %

  11. im = zeros(256,256); im = mat2gray(im); [nim xyp] = makeline(im, 3, 75, 255, 4, 1); figure; imshow(nim); [ints, slopes]=mc_hough(xyp); figure; plot(slopes, ints); [rhos angles]=hough(xyp, 1); figure; plot(angles, rhos); vm = votes(rhos, angles); figure; mesh(vm); function vmat = votes(rhos, angles) % function vmat = votes(rhos, angles) % Find the votes for two parameter space hough transform % rhos = matrix of point distances % % angles = vector of theta (angle) %

  12. Equation of a circle r 2 = ( x − a ) 2 + ( y − b ) 2 x = a + r cos θ y = b + r sin θ a = x − r cos θ b = y − r sin θ Hough transform for circles 1. Select a value of r 2. Create a vector of quantized angles 3. For each θ , a) edge point (x,y), calculate a and b b) increment the votes for (a,b,r) 4. Threshold the (a,b,r) table to find the circles

  13. function value = count_coins(fname) % value = count_coins(fname) % input: filename containing image % output: value of coins % % will also display an image of the file % indicating the coins found % warning off;close all; I=imread(fname); I=rgb2gray(I); %ime=edge(I,'sobel',0.12); ime=edge(I,'canny',[0.15 0.25],2); figure;imshow(ime) r=[141 125 110 103]; %radios to considering vr=[0.25 0.05 0.01 0.1]; tic; %Hough Transform for each radio cont=0;

  14. >> count_coins('fig002.jpg') Elapsed time is 8.986488 seconds. ans = 0.9100 %******Calculate the value of money in coins******************* CC1=length(find(C1(1:nm(1),1))); CC2=length(find(C1(nm(1)+1:nm(1)+nm(2),1))); CC3=length(find(C1(nm(1)+nm(2)+1:nm(1)+nm(2)+nm(3),1))); CC4=length(find(C1(nm(1)+nm(2)+nm(3)+1:nm(1)+nm(2)+nm(3)+nm(4),1))); value=CC1*0.25+CC2*0.05+CC3*0.01+CC4*0.1; y=find(C1(:,1)); C1=C1(y,:); %*************************************************** %Plot of centers ans circles figure;imshow(I);hold on; theta1 = 0:0.01:2*pi; plot(C1(:,2), C1(:,1), 'b+'); %Center of circles for i = 1:size(C1,1) plot(C1(i,2)+C1(i,3)*sin(theta1),C1(i,1)+C1(i,3)*cos(theta1),'r'); %plot of the Circle(s) end toc; end

  15. %Hough Transform for each radio cont=0; for k=1:size(r,2), [C]=hough_circ(ime,r(k)); temp=cont+size(C,1); C1(cont+1:temp,:)=C; cont=temp; for i=nm(1)+1:nm(1)+nm(2), nm(k)=size(C,1); for j=nm(1)+nm(2)+1:size(C1,1) end if C1(i,1)==0 %***End Hough Transform calculation continue; end % Remove repeated coins temp1=abs(C1(i,1)-C1(j,1)); for i=1:nm(1), temp2=abs(C1(i,2)-C1(j,2)); if (temp1<50)&(temp2<50) for j=nm(1)+1:size(C1,1) C1(j,:)=0; temp1=abs(C1(i,1)-C1(j,1)); end temp2=abs(C1(i,2)-C1(j,2)); end if (temp1<50)&(temp2<50) end C1(j,:)=0; end if length(find(C1(nm(1)+nm(2)+nm(3)+1:nm(1)+nm(2)+nm(3)+nm(4),1)))>1 for i=nm(1)+nm(2)+1:nm(1)+nm(2)+nm(3), end for j=nm(1)+nm(2)+nm(3)+1:size(C1,1) end if C1(i,1)==0 continue; end temp1=abs(C1(i,1)-C1(j,1)); temp2=abs(C1(i,2)-C1(j,2)); if (temp1<20)&(temp2<20) C1(j,:)=0; end end end elseif length(find(C1(nm(1)+nm(2)+1:nm(1)+nm(2)+nm(3),1)))>=1 C1(nm(1)+nm(2)+1:nm(1)+nm(2)+nm(3),1)=0; end %***************************** repeated coins removed

  16. Fitting a line to a set of points To fit a line to several points: − x 1 cos θ = y 1 sin θ − ρ − x 1 = y 1 tan θ − ρ / cos θ � ✓ ρ / cos θ ◆ � 1 x 1 = − y 1 tan θ For 3 points 0 1 0 1 x 1 1 − y 1 ✓ ρ / cos θ ◆ x 2 = 1 − y 2 @ A @ A tan θ x 3 1 − y 3 X = MA ✓ ρ / cos θ ◆ � − 1 M t X � M t M A = = tan θ = arctan A (2) θ = A (1) cos θ ρ The points are on the same line if the rms error is below some threshold.

  17. Fitting a Circle ( x − x c ) 2 + ( y − y c ) 2 r 2 = x 2 − 2 x c x + x 2 c + y 2 − 2 y c y + y 2 c − r 2 0 = x 2 + ax + y 2 + by + c 0 = This form is the implicit parametric equation of the circle. To fit a circle to n data points with coordinates ( x i , y i ), − x 2 ax i + y 2 = i + by i + c i 2 3 x i y 2 − x 2 6 7 ⇥ ⇤ i 1 = a b c 6 7 i y i 4 5 1 = − X BM − XM T BMM T = MM T � − 1 = − XP − XM T � = B Notice that a = B (1) = − 2 x c , b = B (3) = − 2 y c and c = B (4) = x 2 c + y 2 c − r 2 .

  18. measured fitted and true circles measured 1 fitted true 0.8 0.6 0.4 0.2 0 center (0.0224336 , -0.00316806 ); R=1.10003 y -0.2 -0.4 -0.6 -0.8 -1 -1 -0.5 0 0.5 1 x

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend