Skip to content

Hough transform for circles

Fact Value
Also called Hough circles, Circle Hough transform, Circular Hough transform
Status Implemented and tested
Family Texture, corners, blobs and features
Engine Science engine
Type Nonlinear, transform, voting in circle space
Output Features
Operator shown as algorithm (exact)
Support radius global
Code engine/src/pixelnexus_engine/filters/hough.py, hough_circles
Operator code engine/src/pixelnexus_engine/filters/hough.py, hough_circles_representation
Packages scikit-image

Overview

The circle Hough transform finds circles by voting, like the Hough transform for lines. First Canny finds the edge pixels. Then every edge pixel votes for the centers of all circles through it, one radius at a time. Centers where many votes meet are the circles. The circles go to the Features panel and are drawn on the canvas. The filter can also show the accumulator. It runs in the PixelNexus engine, with scikit-image.

Four panels. On the Disks image, a thin ring lies on the edge of each of the six disks. The accumulator shows a bright point at the center of each disk, inside rings and spokes of fainter votes. A band hides the tops of the two lower disks. With the threshold 0.3 both are still found, and small rings sit where the band meets them. With noise, the six disks are found and a few small rings appear in the background. Four panels. On the Disks image, a thin ring lies on the edge of each of the six disks. The accumulator shows a bright point at the center of each disk, inside rings and spokes of fainter votes. A band hides the tops of the two lower disks. With the threshold 0.3 both are still found, and small rings sit where the band meets them. With noise, the six disks are found and a few small rings appear in the background.
The Disks test image with the circles found for radii from 3 to 40, each drawn as a ring. Then the accumulator, and the circles with a share threshold of 0.3 when a band hides the tops of the two lower disks. Last, the circles with noise of sigma 12.

How it works

  1. Find edges with Canny on the luma.
  2. For each radius, let every edge pixel vote for the centers of all circles through it.
  3. Divide each count by the number of points on the circle.
  4. Find the peaks over all radii, and list them as circles.

Mathematical foundation

\[ (x - a)^2 + (y - b)^2 = r^2, \qquad H(a, b, r) = \frac{\#\{\text{edge pixels on the circle } (a, b, r)\}}{\#\{\text{points on the circle}\}} \]

The formula shows the default parameter values.

where

  • \(a, b\): The center of a circle
  • \(r\): The radius
  • \(H\): The share of the circle that is edge

A circle has a center (a, b) and a radius r. For each radius, an edge pixel lies on all circles whose center is r away from it. These centers form a circle themselves. Every edge pixel draws this circle of votes into the accumulator of its radius. Where many of these circles cross, many edge pixels lie on one circle, so peaks are circles. Here scikit-image divides each count by the number of points on the circle. So H is the share of the circle that is edge, and circles of different sizes compare fairly. Duda and Hart described this extension of the Hough transform to curves.

For a fixed radius r, the centers of all circles through an edge pixel lie on a circle of radius r around that pixel. Each edge pixel draws this circle of votes. For a real circle of radius r in the image, all its edge pixels draw circles that pass through its center, so the votes pile up there.

A large circle has more edge pixels than a small one, so its raw count is higher. Dividing by the number of points on the circle gives the share of the circle that lies on edges. A full, clean circle reaches about 0.6 here, since Canny edges and the drawn circle do not match pixel for pixel. A circle that is partly hidden reaches less, so the share threshold decides how much of a circle must be visible.

Kernel or operator

There is no kernel. The Inspector asks the engine for the stages with the current settings: the Canny edges, the voting with the range of radii, and the peak search.

Parameters

Parameter Default Values Meaning
Output output Circles Circles, Accumulator The found circles as a table, drawn on the canvas, or the accumulator as an image.
Edge smoothing sigma 1 0.5 to 5 px The sigma of the Gaussian blur before Canny finds edges. scikit-image uses 1.
Low threshold lowThreshold 0.1 0 to 2 Weak edges must reach this Sobel magnitude, on the luma from 0 to 1. scikit-image uses 0.1.
High threshold highThreshold 0.2 0 to 2 Strong edges must reach this Sobel magnitude. scikit-image uses 0.2. A value below the low threshold counts as the low threshold.
Border mode border Reflect 101 (default) Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap How pixels outside the image are filled when the window reaches past the edge.
Smallest radius minRadius 5 2 to 200 px The smallest radius to look for.
Largest radius maxRadius 50 2 to 200 px The largest radius to look for. A value below the smallest radius counts as the smallest radius.
Radius step radiusStep 1 1 to 20 px The step between the radii that are tried.
Share threshold threshold 0.5 0.05 to 1 A circle needs at least this share of the points on its circle to be edge pixels.
Most circles circles 10 1 to 200 At most this many circles, the strongest first.
Distance apart minDistance 5 1 to 100 px Two centers of one radius must be at least this far apart in x or in y.

Implementation

hough_circles in engine/src/pixelnexus_engine/filters/hough.py finds edges with skimage.feature.canny on the luma from 0 to 1. Then skimage.transform.hough_circle builds one accumulator for each radius, normalized by the number of points on the circle. Next, hough_circle_peaks finds the peaks of each radius that reach the threshold. With a distance apart above 1, it also drops a circle whose center lies within that distance in both x and y of a stronger circle, of any radius. The table gives the center, the radius and the share, strongest first. The accumulator view is the largest share over all radii at each center, stretched.

Worked example

Image Disk center Radius (px) Found radius (share)
Clean (48, 48) 24 24 (0.62)
Clean (128, 48) 12 12 (0.64)
Clean (192, 48) 6 6 (0.55)
Clean (224, 48) 3 3 (0.58)
Clean (64, 160) 36 36 (0.63)
Clean (176, 160) 18 18 (0.54)
Clean elsewhere 0 circles
Partly hidden (48, 48) 24 24 (0.62)
Partly hidden (128, 48) 12 12 (0.64)
Partly hidden (192, 48) 6 6 (0.55)
Partly hidden (224, 48) 3 3 (0.58)
Partly hidden (64, 160) 36 not found
Partly hidden (176, 160) 18 not found
Partly hidden elsewhere 0 circles
Partly hidden, threshold 0.3 (48, 48) 24 24 (0.62)
Partly hidden, threshold 0.3 (128, 48) 12 12 (0.64)
Partly hidden, threshold 0.3 (192, 48) 6 6 (0.55)
Partly hidden, threshold 0.3 (224, 48) 3 3 (0.58)
Partly hidden, threshold 0.3 (64, 160) 36 36 (0.47)
Partly hidden, threshold 0.3 (176, 160) 18 18 (0.40)
Partly hidden, threshold 0.3 elsewhere 4 circles
Noise (48, 48) 24 24 (0.66)
Noise (128, 48) 12 12 (0.64)
Noise (192, 48) 6 6 (0.57)
Noise (224, 48) 3 3 (0.67)
Noise (64, 160) 36 36 (0.63)
Noise (176, 160) 18 18 (0.59)
Noise elsewhere 4 circles

The images of the figure with radii from 3 to 40 and the other defaults, unless a threshold is named. A disk counts as found when a circle has its center within 2 pixels of the disk center. The share is the part of the circle that lies on edges.

On the clean image, every disk is found with its radius and nothing else. A band that hides about a third of the circles of the two lower disks drops their share below 0.5, so they are lost. A threshold of 0.3 finds them again, along with 4 small circles at the corners where the band meets the disks. Noise of sigma 12 keeps all six disks and adds 4 small circles elsewhere.

Complexity

  • Time: \(O(E R r)\)
  • Memory: \(O(R N)\)

E is the number of edge pixels, R the number of radii, r the largest radius and N the number of pixels.

Artifacts and limitations

Limitations

  • Each radius needs its own accumulator, so a wide range of radii is slow and needs memory.
  • Ellipses and circles seen at a slant are not found.
  • Concentric edges, such as both sides of a thick ring, give two circles.

Artifacts

  • Circles of nearby radii on one round object, when the distance apart is small.

Tests

The six disks of the Disks image must each be found once, at their center and with their radius within 1 pixel. Each share must be the value of scikit-image's normalized accumulator at that center and radius, and at least the threshold. The table must have the columns x, y, radius and share, and the accumulator view must be the largest share over the radii, stretched. The engine API test checks the JSON table.

References

  • Duda, R. O., and Hart, P. E. Use of the Hough transformation to detect lines and curves in pictures. Communications of the ACM 15(1), 11 to 15, 1972. DOI 10.1145/361237.361242.
  • Canny, J. A computational approach to edge detection. IEEE Transactions on Pattern Analysis and Machine Intelligence PAMI-8(6), 679 to 698, 1986. DOI 10.1109/TPAMI.1986.4767851.
  • scikit-image documentation, skimage.transform.hough_circle and hough_circle_peaks.