Skip to contents

houghCircles finds circles in a grayscale image using the Hough transform.

Usage

houghCircles(
  image,
  method,
  dp,
  min_dist,
  param1 = 100,
  param2 = 100,
  min_radius = 0,
  max_radius = 0
)

Arguments

image

An 8-bit (8U) single-channel (GRAY) Image object.

method

A character string indicating the detection method to be used. The available methods are "GRADIENT" and "ALT" (generally more accurate).

dp

Inverse ratio of the accumulator resolution to the image resolution. For example, if dp = 1, the accumulator has the same resolution as the input image. If dp = 2, the accumulator has half the resolution. Etc. For method = "GRADIENT" the recommended value is dp = 1.5, unless some small very circles need to be detected.

min_dist

Minimum distance between the centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected. If it is too large, some circles may be missed.

param1

First method-specific parameter. In this case, it is the higher threshold of the two passed to the Canny edge detector (the lower one is twice smaller). The default value is 100 but note that method = "ALT" uses the Scharr algorithm to compute the image derivatives and, therefore, the threshold value should normally be higher, such as 300 for normally exposed and contrasty images.

param2

Second method-specific parameter. In case of method = "GRADIENT", it is the accumulator threshold for the circle centers at the detection stage. The smaller it is, the more false circles may be detected. Circles corresponding to the larger accumulator values will be returned first. In the case of method = "ALT", this is the circle "perfectness" measure. The closer it is to 1, the better shaped circles the algorithm will select. In most cases 0.9 should be fine. If you want get better detection of small circles, you may decrease it to 0.85, 0.8 or even less. But then also try to limit the search range [min_radius, max_radius] to avoid too many false circles.

min_radius

The minimum acceptable circle radius.

max_radius

The maximum acceptable circle radius. If max_radius <= 0, the function uses the maximum image dimension. If max_radius < 0 and method = "GRADIENT", the function returns the centers without the radiuses.

Value

A matrix with 5 columns corresponding to the unique id of each circle, the x and y coordinates of their centers, the estimates of their radius, and the estimated relative reliability of the detected circles ("votes").

See also

Author

Simon Garnier, garnier@njit.edu

Examples

dots <- image(system.file("sample_img/dots.jpg", package = "Rvision"))
dots_gray <- changeColorSpace(dots, "GRAY")
circ <- houghCircles(dots_gray, "ALT", 1.5, 25, 300, 0.9)