fitcircle
R2026bDescription
measures a circle in a grayscale or RGB input image, measurementData = fitcircle(I,position)I, by
positioning a circle tool at the position position. This function
performs a semi-automatic circle measurement when the tool snaps to circular edges
detected near the specified position.
specifies options using one or more name-value arguments. For example,
measurementData = fitcircle(I,position,Name=Value)SnapNeighborhood=1 specifies the snapping neighborhood as 1
pixel.
Examples
Read a test image into the workspace.
A = imread("metalplate.png");Adjust the image contrast.
A = imadjust(A);
Display the adjusted image.
hIm = imageshow(A);

Measure the circle at the position [1372,1873,61.5] using the fitcircle function.
measuredCircle= fitcircle(A,[1372,1873,61.5])
measuredCircle = struct with fields:
Center: [1.3683e+03 1.8812e+03]
Radius: 43.4954
Area: 5.9434e+03
Circumference: 273.2894
Position: [1.3683e+03 1.8812e+03 43.4954]
Input Arguments
Input image in which to perform the circle measurement, specified as one of these values:
| Image Type | Data Format |
|---|---|
| Grayscale | H-by-W numeric matrix |
| RGB | H-by-W-by-3 numeric array |
Note
By default, spatial image coordinates are in the intrinsic coordinate
system, where the center of the upper left pixel has intrinsic coordinates
(1.0, 1.0). If you perform a coordinate transformation on the image input
I, units are defined in the world coordinate system. To
learn more, see Image Coordinate Systems.
Position of the circle tool, specified as one of these options:
Position format | Description |
|---|---|
| 3-element row vector | The vector is of the form [xCenter yCenter R], where the [xCenter yCenter] coordinate is the center of the circle and R is the circle radius. |
| N-by-2 matrix | Each row in the matrix represents a coordinate point to which the circle is fit. |
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN, where Name is
the argument name and Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example:
fitcircle(hImage,position,SnapNeighborhood=1) specifies the snapping
neighborhood as 1 pixel.
Snap the circle to edges, specified as a numeric or logical
1 (true) or 0
(false). By default, the tool detects nearby circular
edges using the method specified by the EdgeMap argument,
and then fits the circle to the edges using the RANSAC algorithm.
Specify the snapping neighborhood using the
SnapNeighborhood argument.
Snapping neighborhood, specified as a positive scalar.
SnapNeighborhood specifies a band-shaped search region
for edge snapping, specified as a fraction of the circle radius. The algorithm
searches for edges within an annular neighborhood extending from
(1 – S)R to
(1 + S) R around the circle’s
circumference. S is the value of
SnapNeighborhood, and R is the
radius of the circle. Units are in pixels.
Edge detection method for snapping, specified as a logical array or one of these options.
| Method | Description |
|---|---|
"canny"
| Finds edges by looking for local maxima of the
gradient of the image. The |
"sobel"
| Finds edges at those points where the gradient of the image is maximum, using the Sobel approximation to the derivative. |
"prewitt"
| Finds edges at those points where the gradient of the image is maximum, using the Prewitt approximation to the derivative. |
"roberts"
| Finds edges at those points where the gradient of the image is maximum, using the Roberts approximation to the derivative. |
"log"
| Finds edges by looking for zero-crossings after filtering the image with a Laplacian of Gaussian (LoG) filter. |
"zerocross"
| Finds edges by looking for zero-crossings after filtering the image. |
"approxcanny"
| Finds edges using an approximate version of the Canny edge detection algorithm that provides faster execution time at the expense of less precise detection. |
If you specify EdgeMap as a logical array,
you define a binary image that contains precomputed edge locations for
snapping. Select this option to avoid repeated edge detection when making
multiple measurements on the same image.
Number of RANSAC iterations to run to detect the most accurately snapped circle, specified as a positive integer. The Random Sample Consensus (RANSAC) algorithm for circle estimation involves repeated random sampling steps to robustly estimate the parameters of a circle from a set of measurement points. Increase the number of iterations to increase the chance that at least one sample contains only inliers (points in the true circle), leading to a good model at the expense of longer computation time.
Inlier distance threshold, specified as a positive numeric scalar. This
value defines the maximum allowable distance, in pixels, between a measurement
point and the estimated circle for that point to be considered an inlier.
Increase the RansacInlierDistance value to count more
noisy or slightly off-circle points as inliers, at the expense of a less
accurate circle fit and measurement.
Angle defining the circumference arc, specified as a 2-element numeric
vector. The vector is in the form [startAngle,
stopAngle], where startAngle and
stopAngle represent the initial and final angle of the
arc, respectively, measured counterclockwise from the positive
x-axis. Both angles are unbounded. For example,
[0, 360] and [-180, 180] define the
same full circle. Specify the AngleRange to snap to an
obstructed circle or circle arc.
Geometric transformation for the input image data that defines a 2-D world
coordinate system, specified as an affinetform2d object, an imref2d object, a rigidtform2d object, a simtform2d object, or a transltform2d object.
If you perform a coordinate transformation on the input image data, the
units of measurementData are defined in the world
coordinate system. To learn more about image coordinate systems, see Image Coordinate Systems.
Output Arguments
Circle measurement result, returned as a structure with these fields:
measurementData Field | Description |
|---|---|
Position | Measured circle position, stored as a 3-element row vector. The vector is of the form [xCenter yCenter R], where the [xCenter yCenter] coordinate is the center of the circle and R is the circle radius. |
Center | Measured circle center, stored as a 2-element row vector. The vector is of the form [xCenter yCenter], where the xCenter and yCenter coordinates define the center of the circle. |
Radius | Measured circle radius, stored as a positive numeric scalar. |
Area | Measured circle area, stored as a positive numeric scalar. |
Circumference | Measured circle circumference, stored as a positive numeric scalar |
Extended Capabilities
Usage notes and limitations:
String inputs must be compile-time constants.
Usage notes and limitations:
String inputs must be compile-time constants.
Version History
Introduced in R2026b
See Also
uifitcircle | affinetform2d | imref2d | rigidtform2d | simtform2d | transltform2d
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)