imfindcircles

Syntax

centers = imfindcircles(A,radius)

[centers,radii]
= imfindcircles(A,radiusRange)

[centers,radii,metric]
= imfindcircles(A,radiusRange)

[___]
= imfindcircles(___,Name,Value)

Description

centers = imfindcircles(A,radius) finds
the circles in image A whose radii are approximately
equal to radius. The output, centers,
is a two-column matrix containing the x,y coordinates
of the circles centers in the image.

[centers,radii]
= imfindcircles(A,radiusRange) finds
circles with radii in the range specified by radiusRange.
The additional output argument, radii, contains
the estimated radii corresponding to each circle center in centers.

[centers,radii,metric]
= imfindcircles(A,radiusRange) also
returns a column vector, metric, containing the
magnitudes of the accumulator array peaks for each circle (in descending
order). The rows of centers and radii correspond
to the rows of metric.

Name-Value Pair Arguments

Specify optional
comma-separated pairs of Name,Value arguments. Name is
the argument name and Value is the corresponding value.
Name must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN.

'ObjectPolarity' — Object polarity'bright' (default) | 'dark'

Object polarity indicates whether the circular objects are brighter
or darker than the background, specified as the comma-separated pair
consisting of 'ObjectPolarity' and either of the
values in the following table.

'bright'

The circular objects are brighter than the background.

'dark'

The circular objects are darker than the background.

'Method' — Computation method'PhaseCode' (default) | 'TwoStage'

Computation method is the technique used to compute the accumulator
array, specified as the comma-separated pair consisting of 'Method' and
either of the values in the following table.

'PhaseCode'

Atherton and Kerbyson's [1] phase coding method . This is the default.

Sensitivity factor is the sensitivity for the circular Hough transform accumulator array,
specified as the comma-separated pair consisting of 'Sensitivity'
and a number in the range [0,1]. As you increase the sensitivity factor,
imfindcircles detects more circular objects, including weak and
partially obscured circles. Higher sensitivity values also increase the risk of false
detection.

'EdgeThreshold' — Edge gradient thresholdnumber in the range [0. 1]

Edge gradient threshold sets the gradient threshold for determining edge pixels in the image,
specified as the comma-separated pair consisting of 'EdgeThreshold'
and a number in the range [0,1]. Specify 0 to set the threshold to
zero-gradient magnitude. Specify 1 to set the threshold to the
maximum gradient magnitude. imfindcircles detects more circular
objects (with both weak and strong edges) when you set the threshold to a lower value.
It detects fewer circles with weak edges as you increase the value of the threshold.
By default, imfindcircles chooses the edge gradient threshold
automatically using the function graythresh.

Example: 'EdgeThreshold',0.5 sets the edge
gradient threshold to 0.5.

Output Arguments

centers — Coordinates of circle centersP-by-2 matrix

Coordinates of the circle centers, returned as a P-by-2 matrix
containing the x-coordinates of the circle centers
in the first column and the y-coordinates in the
second column. The number of rows, P, is the number
of circles detected. centers is sorted based
on the strength of the circles.

radii — Estimated radiicolumn vector

The estimated radii for the circle centers, returned as a column
vector. The radius value at radii(j) corresponds to the circle centered at centers(j,:).

metric — Circle strengthscolumn vector

Circle strengths is the relative strengths for the circle centers,
returned as a vector. The value at metric(j) corresponds to the circle with radius radii(j) centered at centers(j,:).

Tips

Specify a relatively small radiusRange for
better accuracy. A good rule of thumb is to choose radiusRange such
that rmax < 3*rmin and (rmax-rmin) <
100.

The accuracy of imfindcircles is
limited when the value of radius (or rmin)
is less than or equal to 5.

The radius estimation step is typically faster if
you use the (default) 'PhaseCode' method instead
of 'TwoStage'.

Both computation methods, 'PhaseCode' and 'TwoStage' are
limited in their ability to detect concentric circles. The results
for concentric circles can vary depending on the input image.

imfindcircles does not find circles
with centers outside the domain of the image.

imfindcircles preprocesses binary
(logical) images to improve the accuracy of the result. It converts
truecolor images to grayscale using the function rgb2gray before processing them.

Algorithms

imfindcircles uses a Circular Hough Transform (CHT) based algorithm for
finding circles in images. This approach is used because of its robustness in the presence of
noise, occlusion and varying illumination.

The CHT is not a rigorously specified algorithm, rather there
are a number of different approaches that can be taken in its implementation.
However, by and large, there are three essential steps which are
common to all.

Accumulator Array Computation

Foreground pixels of high gradient are designated as being candidate pixels and are
allowed to cast ‘votes’ in the accumulator array. In a classical CHT implementation, the
candidate pixels vote in pattern around them that forms a full circle of a fixed radius.
Figure 1a shows an example of a candidate pixel lying on an actual circle (solid circle)
and the classical CHT voting pattern (dashed circles) for the candidate pixel.

Classical CHT Voting Pattern

Center Estimation

The votes of candidate pixels belonging to an image circle tend to accumulate at the
accumulator array bin corresponding to the circle’s center. Therefore, the circle centers
are estimated by detecting the peaks in the accumulator array. Figure 1b shows an example
of the candidate pixels (solid dots) lying on an actual circle (solid circle), and their
voting patterns (dashed circles) which coincide at the center of the actual circle.

Radius Estimation

If the same accumulator array is used for more than one radius value, as is commonly
done in CHT algorithms, radii of the detected circles have to be estimated as a separate
step.

imfindcircles provides two algorithms for finding circles in images:
Phase-Coding (default) and Two-Stage. Both share some common computational steps, but each has
its own unique aspects as well.

The common computational features shared by both algorithms
are as follow:

Use of 2-D Accumulator Array

The classical Hough Transform requires a 3-D array for storing votes for multiple
radii, which results in large storage requirements and long processing times. Both the
Phase-Coding and Two-Stage methods solve this problem by using a single 2-D accumulator
array for all the radii. Although this approach requires an additional step of radius
estimation, the overall computational load is typically lower, especially when working
over large radius range. This is a widely adopted practice in modern CHT
implementations.

Use of Edge Pixels

Overall memory requirements and speed is strongly governed by the number of candidate
pixels. To limit their number, the gradient magnitude of the input image is threshold so
that only pixels of high gradient are included in tallying votes.

Use of Edge Orientation Information

Another way to optimize performance is to restrict the number of bins available to
candidate pixels. This is accomplished by utilizing locally available edge information to
only permit voting in a limited interval along direction of the gradient (Figure
2).

Voting Mode: Multiple Radii, Along Direction of Gradient

rmin

Minimum search radius

rmax

Maximum search radius

ractual

Radius of the circle that the candidate pixel belongs to

cmin

Center of the circle of radius rmin

cmax

Center of the circle of radius rmax

cactual

Center of the circle of radius ractual

The two CHT methods employed by function imfindcircles fundamentally
differ in the manner by which the circle radii are computed.

Two-Stage

Radii are explicitly estimated utilizing the estimated circle centers along with image
information. The technique is based on computing radial histograms [2][3].

Phase-Coding

The key idea in Phase Coding [1] is the use of complex values in the accumulator array with the radius information
encoded in the phase of the array entries. The votes cast by the edge pixels contain
information not only about the possible center locations but also about the radius of the
circle associated with the center location. Unlike the Two-Stage method where radius has
to be estimated explicitly using radial histograms, in Phase Coding the radius can be
estimated by simply decoding the phase information from the estimated center location in
the accumulator array.

Compatibility Considerations

imfindcircles uses new filter size for logical images

Behavior changed in R2019a

Staring in R2019a, the imfindcircles function uses a 5-by-5 filter
size for smoothing logical images. imfindcircles may now return a
different answer than in previous releases, when the filter size was 6-by-6. For example, in
some instances, the function may return a different number of circles.

Extended Capabilities

C/C++ Code GenerationGenerate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

imfindcircles supports the generation of C
code (requires MATLAB®
Coder™). Note that if you choose the generic MATLAB Host Computer
target platform, imfindcircles generates code that uses a precompiled,
platform-specific shared library. Use of a shared library preserves performance optimizations
but limits the target platforms for which code can be generated. For more information, see Code Generation Using a Shared Library.

When generating code, all character vector input parameters
and values must be a compile-time constant.

This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic. By continuing to use this website, you consent to our use of cookies. Please see our Privacy Policy to learn more about cookies and how to change your settings.