[Digital Image Processing] Hough Transform

Series Article Directory

This series is mainly study notes when reading papers. When encountering more classic digital image processing algorithms and knowledge points, organize and summarize them, mainly including principles, methods, algorithms, etc. (hope I can stick to it)

The series of articles are as follows:

Not yet (continuously updated)



introduction

The Hough transform is a more classic method for detecting simple shapes such as line segments and circles, ellipses, etc. The basic idea adopted is the idea of ​​cumulative voting.


1. The principle of Hough transform

        There are two ways to represent a straight line in the Cartesian coordinate system (planar Cartesian coordinate system):

  1. y = kx + b
  2. r = xcosθ + ysinθ

 1.1 y = kx + b

        Here, the commonly used method is the first one, and a straight line can be determined by knowing the determined k0 and b0. This leads to the Hough space. In the Cartesian coordinate system space, the abscissa is x and the ordinate is y, while in the coordinate system of the Hough space, the abscissa is k and the ordinate is b. The method used to represent the straight line in the Hough coordinate system is: b = xk + y.

        For a known and determined straight line: y = k0x +b0, there is a known point (k0, b0) corresponding to it in the Hough coordinate system. Correspondingly, if there is a straight line in the Hough coordinate system: b = -x0k + y0, there is a known point (x0, y0) corresponding to it in the Cartesian coordinate system. Pay attention to the negative sign here because y = kx + b corresponds to b = -xk + y in the correspondence. The relevant corresponding relationship is shown in the figure below:

Title A known straight line in the Cartesian coordinate system corresponds to a point in the Hough coordinate system
A known straight line in the title Hough space corresponds to a point in the Cartesian coordinate system

 

        So the mapping relationship is obtained:

  • A known straight line in Cartesian coordinate system maps to a point in Hough coordinate system
  • A known straight line in Hough space maps a point in Cartesian coordinate system

1.2 r = xcosθ + ysinθ

        And there is a special existence in the Cartesian coordinate system: x = a (a straight line perpendicular to the x-axis, k is infinite), in this case it is impossible to find a point corresponding to it in the general Hough coordinate system, at this time the coordinates Converted to polar coordinates (ρ-θ), ρ is the vertical distance from the origin to the line, θ is the angle between the vertical line of the line and the horizontal axis counterclockwise, the angle of the vertical line is 0, and the angle of the horizontal line is 180 degrees . In the Hough space, the abscissa of the coordinate system becomes θ, and the ordinate becomes ρ.

        The mapping relationship is shown in the figure below:

Mutual mapping relationship in polar coordinates

 

        So the mapping relationship becomes:

  • A known point in the Cartesian polar coordinate system is mapped to a curve in Hough space
  • A known point in the polar coordinate system of Hough space is mapped to a straight line in Cartesian space

1.3 Principle of use

        Purpose: Find lines in Cartesian space

  1. Convert Cartesian space to Hough space, convert points in Cartesian space to straight lines (curves) in Hough space
  2. A lot of points are converted into straight lines (curves), and these lines will produce intersection points.
  3. Find the point with the most intersections in the Hough space. The Hough coordinate value of this point is the k and b (ρ and θ) of the line in the Cartesian space.


2. Implementation steps

Suppose there is a 100x100 pixel picture, now use Hough transform to detect straight lines in the picture:
1. Create a two-dimensional array and initialize all values ​​to 0. The rows of the array represent r, and the columns represent θ. That is, a polar coordinate system in Hough space is created. The size of the array size determines the accuracy of the results. If we want the accuracy of the angle of the straight line to be 1 degree, then the columns of this array are set to 180 columns, each column is one degree, in turn from 0 degrees to 180 degrees. The row of the array represents r. If we want the accuracy of the straight line to reach the pixel level, the maximum value of r should be equal to the diagonal distance of the image (that is, the upper left corner of the image is considered to be the origin of the image, and the distance from the middle point of the image to the origin is r ), so r is taken from 0 to the diagonal length value of the image. This array is also called the accumulator.
2. Traversing each point in the original image, calculating each r of each point in θ between 0-180, if this value has a corresponding position in the above accumulator, add 1 to this position. After traversal, many curves in the polar coordinate system in Hough space are obtained.
3. Search for the maximum value in the accumulator ( that is, find the intersection of many curves in the polar coordinate system in the Hough space obtained in 2 ) and find the r and θ corresponding to this maximum value, and then you can express the straight line in the image up.


quote

Related references and citations:


  1. opencv study notes (16): Hough transform
  2. Chapter 16: The Hough Transform

Guess you like

Origin blog.csdn.net/shisniend/article/details/125809795