myimagelib.myImageLib.imfindcircles

myimagelib.myImageLib.imfindcircles(img, radius, edge_width=10, smooth_window=11, nIter=1)

Find circles in images. The algorithm is based on Hough Transform and the idea of Atherton and Kerbyson 1999, using the edge orientation information to improve the performance on noisy images. See step-by-step phase code find circles for more details about this method.

Parameters:
  • img (numpy array) – Input image. Note that it has to be grayscale and 8-bit, otherwise the function will raise an error.

  • radius (list) – Radius of circles to detect. A list of 2 values, [minimum, maximum].

  • edge_width (int) – An estimated with of the edge in pixels. Default is 10.

  • smooth_window (int) – Size of the Gaussian window for smoothing the image / gradient field / accumulator. Default is 11.

  • nIter (int) – Number of iterations for multi-stage detection. Default is 1. When nIter > 1, the function will run the detection multiple times with different radius ranges. This is useful when the circles have different sizes.

Returns:

DataFrame with columns [x, y, r] for the centers and radii of detected circles.

Return type:

pandas.DataFrame

>>> from myimagelib import imfindcircles
>>> circles = imfindcircles(img, [50, 120])
>>> circles = imfindcircles(img, [50, 120], edge_width=5)
>>> circles = imfindcircles(img, [50, 120], edge_width=5, smooth_window=5)
>>> circles = imfindcircles(img, [50, 120], edge_width=5, smooth_window=5, nIter=4)

Edit

  • Feb 27, 2025 – Initial commit.

  • Feb 28, 2025 – (i) Add smooth_window argument, include the preprocessing step in this function to simplify the code on the user side; (ii) determine step size adaptively.

  • Mar 04, 2025 – Smooth the score before locating the peak.

  • Mar 05, 2025 – (i) Implement multi-stage detection. Add nIter argument to determine the number of iterations. (ii) Use threshold of magnitude (magnitude > mean + 2*std) to determine the strong edges.