hough transforms cse 6367 – computer vision vassilis athitsos university of texas at arlington
TRANSCRIPT
![Page 1: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/1.jpg)
Hough Transforms
CSE 6367 – Computer VisionVassilis Athitsos
University of Texas at Arlington
![Page 2: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/2.jpg)
Hough Transforms
• Goal: identify simple geometric shapes in images, such as lines and circles.
Example: find the most prominent line in an image.
![Page 3: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/3.jpg)
Hough Transforms
• Goal: identify simple geometric shapes in images, such as lines and circles.
Example: find the most prominent line in an image.
![Page 4: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/4.jpg)
Code for Previous Resultsfunction result = hough_demo(image, threshold, result_number) % detect edgesedges = canny(image, threshold);
% find lines[h theta rho] = hough(edges); % draw the most prominent line on the image.result = image * 0.7;for i = 1:result_number max_value = max(max(h)); [rho_indices, theta_indices] = find(h == max_value); rho_index = rho_indices(1); theta_index = theta_indices(1); distance = rho(rho_index); angle = theta(theta_index); result = draw_line2(result, distance, angle); h(rho_index, theta_index) = 0;end
![Page 5: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/5.jpg)
What is a Straight Line?
![Page 6: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/6.jpg)
What is a Straight Line?
• It is infinite.
• It is defined in multiple ways:
![Page 7: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/7.jpg)
Defining Straight Lines
• How many parameters do we need to define a line?
![Page 8: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/8.jpg)
Defining Straight Lines• How many parameters define a line?• One option:
– a point (x0, y0) and a theta.
• Another option: – two points (x0, y0) and (x1, y1).
• NOTE: for representing 2D points, two conventions are common:
• (x, y), where x is horizontal coord., y is vertical coord.• (i, j), where i is vertical coord, j is horizontal coord.
– In any piece of code, ALWAYS VERIFY THE CONVENTION.
![Page 9: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/9.jpg)
Defining Straight Lines• How many parameters define a line?
• One option: – a point (x0, y0) and a theta.
• Another option: – two points (x0, y0) and (x1, y1).
• Any problem with the above two parametrizations?
![Page 10: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/10.jpg)
Defining Straight Lines• How many parameters define a line?
• One option: – a point (x0, y0) and a theta.
• Another option: – two points (x0, y0) and (x1, y1).
• Any problem with the above two parametrizations?– It is redundant.
• A line has infinite parametrizations/representations.
![Page 11: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/11.jpg)
Defining Straight Lines
• y = c1 * x + c2– Problems?
![Page 12: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/12.jpg)
Defining Straight Lines
• y = c1 * x + c2– The above parametrization cannot represent
vertical lines.
![Page 13: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/13.jpg)
Defining Straight Lines
• Can we define a line in a non-redundant way?
![Page 14: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/14.jpg)
Defining Straight Lines
• Defining a line using rho and theta:
• rho = x*cos(theta) + y*sin(theta)– rho: distance of line from origin.– theta: direction PERPENDICULAR to line.– The line is the set of (x, y) values satisfying the
equation.
![Page 15: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/15.jpg)
Voting for Lines
• Every edge pixel votes for all the lines it is a part of.
• Vote array: # of rhos x # of thetas.– We choose how much we want to
discretize.– Votes collected in a single for loop.
![Page 16: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/16.jpg)
Voting for Lines - Pseudocode
• counters = zeros(# of rhos, # of thetas)• For every pixel (i, j):
– if (i, j) not an edge pixel, then continue– for every theta in thetas:
• rho = find_rho(i, j, theta)• counters(rho, theta)++;
![Page 17: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/17.jpg)
Voting for Lines - Pseudocode• counters = zeros(# of rhos, # of thetas)
• For every pixel (i, j):– if (i, j) not an edge pixel, then continue– for every theta in thetas:
• rho = find_rho(i, j, theta)• counters(rho, theta)++;
• How long does it take?
![Page 18: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/18.jpg)
Voting for Lines - Pseudocode• counters = zeros(# of rhos, # of thetas)• For every pixel (i, j):
– if (i, j) not an edge pixel, then continue– for every theta in thetas:
• rho = find_rho(i, j, theta)• counters(rho, theta)++;
• How long does it take?– # pixels * # thetas.– # edge pixels * # thetas.
![Page 19: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/19.jpg)
Hough Transform for Lines
• The Hough transform for lines simply computes the votes for all lines.
![Page 20: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/20.jpg)
Using the Matlab Hough Functionfunction result = hough_demo(image, threshold, result_number) % calls canny(image, threshold), does hough transform % on the resulting edge% image, and draws the top "result_number" results. edges = canny(image, threshold);[h theta rho] = hough(edges); result = image * 0.5;for i = 1:result_number max_value = max(max(h)); [rho_indices, theta_indices] = find(h == max_value); rho_index = rho_indices(1); theta_index = theta_indices(1); distance = rho(rho_index); angle = theta(theta_index); result = draw_line2(result, distance, angle); h(rho_index, theta_index) = 0;end
![Page 21: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/21.jpg)
Voting for Lines
• Using edge orientations to make it faster:
![Page 22: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/22.jpg)
Voting for Lines
• Using edge orientations to make it faster:
• Use the orientation of an edge pixel to limit the thetas that it votes for.
![Page 23: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/23.jpg)
Voting for Lines – Pseudocode 2• counters = zeros(# of rhos, # of thetas)• For every pixel (i, j):
– if (i, j) not an edge pixel, then continue– o = gradient_orientations(i, j)– pixel_thetas = thetas such that abs(angle(o, theta)) <= thr.– for every theta in pixel_thetas:
• rho = find_rho(i, j, theta)• counters(rho, theta)++;
![Page 24: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/24.jpg)
Defining Circles
![Page 25: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/25.jpg)
Defining Circles
• Parameters: center_x, center_y, radius.
• (x - center_x)2 + (y - center_y)2 = radius2
• The circle is the set of all (x, y) values satisfying the above equation.
![Page 26: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/26.jpg)
Hough Transform on Circles
• What is the voting space?
• Who votes?
• What does each voter vote for?
![Page 27: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/27.jpg)
Hough Transform on Circles
• What is the voting space?– the set of all circles that can be defined.– size of array:
• Who votes?
• What does each voter vote for?
![Page 28: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/28.jpg)
Hough Transform on Circles
• What is the voting space?– the set of all circles that can be defined.– size of array: # centers * # radii.
• Who votes?
• What does each voter vote for?
![Page 29: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/29.jpg)
Hough Transform on Circles
• What is the voting space?– the set of all circles that can be defined.– size of array: # centers * # radii.– Coarser discretizations can be used.
• combine 3x3 neighborhoods for center locations.• choose step at which radii are sampled.
• Who votes?
• What does each voter vote for?
![Page 30: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/30.jpg)
Hough Transform on Circles
• What is the voting space?– the set of all circles that can be defined.
• Who votes?
• What does each voter vote for?
![Page 31: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/31.jpg)
Hough Transform on Circles
• What is the voting space?– the set of all circles that can be defined.
• Who votes?– Every edge pixel.
• What does each voter vote for?
![Page 32: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/32.jpg)
Hough Transform on Circles
• What is the voting space?– the set of all circles that can be defined.
• Who votes?– Every edge pixel.
• What does each voter vote for?– Every edge pixel votes for all the circles that it
belongs to.
![Page 33: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/33.jpg)
Hough Transform on Circles
• What is the voting space?– the set of all circles that can be defined.
• Who votes?– Every edge pixel.
• What does each voter vote for?– Every edge pixel votes for all the circles that it
can belong to.– Faster version:
![Page 34: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/34.jpg)
Hough Transform on Circles
• What is the voting space?– the set of all circles that can be defined.
• Who votes?– Every edge pixel.
• What does each voter vote for?– Every edge pixel votes for all the circles that it can belong
to.– Faster version: every edge pixel (i, j) votes for all the circles
that it can belong to, such that the line from (i, j) to the circle center makes a relatively small angle with the gradient orientation at (i, j).
![Page 35: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/35.jpg)
Hough Transform on Circles
• What does each voter vote for?– Every edge pixel votes for all the circles that it
can belong to.– Faster version: every edge pixel (i, j) votes for all
the circles that it can belong to, such that the line from (i, j) to the circle center makes a relatively small angle with the gradient orientation at (i, j).
• How long does it take?
![Page 36: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/36.jpg)
Hough Transform on Circles
• What does each voter vote for?– Every edge pixel votes for all the circles that it
can belong to.– Faster version: every edge pixel (i, j) votes for all
the circles that it can belong to, such that the line from (i, j) to the circle center makes a relatively small angle with the gradient orientation at (i, j).
• How long does it take?– # edge pixels * # pixels * # radii.
![Page 37: Hough Transforms CSE 6367 – Computer Vision Vassilis Athitsos University of Texas at Arlington](https://reader035.vdocuments.mx/reader035/viewer/2022062712/56649c755503460f94928c27/html5/thumbnails/37.jpg)
General Hough Transforms
• In theory, we can use Hough transforms to detect more complicated shapes.
• In practice, this requires memory and time exponential to the number of parameters, and is usually not practical.