This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.



h = viscircles(ax,centers,radii)
h = viscircles(___,Name,Value)



viscircles(centers,radii) draws circles with specified centers and radii onto the current axes.

viscircles(ax,centers,radii) draws circles onto the axes specified by ax.

h = viscircles(ax,centers,radii) draws circles and returns a handle to the circles created. This handle is an hggroup object that is a child of the axes object, ax.


h = viscircles(___,Name,Value) specifies additional options with one or more Name,Value pair arguments, using any of the previous syntaxes. Parameter names can be abbreviated.


collapse all

This example shows how to draw lines around both bight and dark circles in an image.

Read the image into the workspace and display it.

A = imread('circlesBrightDark.png');

Define the radius range.

Rmin = 30;
Rmax = 65;

Find all the bright circles in the image within the radius range.

[centersBright, radiiBright] = imfindcircles(A,[Rmin Rmax],'ObjectPolarity','bright');

Find all the dark circles in the image within the radius range.

[centersDark, radiiDark] = imfindcircles(A,[Rmin Rmax],'ObjectPolarity','dark');

Draw blue lines around the edges of the bright circles.

viscircles(centersBright, radiiBright,'Color','b');

Draw red dashed lines around the edges of the dark cirles.

viscircles(centersDark, radiiDark,'LineStyle','--');

The viscircles function does not clear the target axes before plotting circles. To remove circles that have been previously plotted in an axes, use the cla function. To illustrate, this example creates a new figure and then loops, drawing a set of circles with each iteration, clearing the axes each time.

colors = {'b','r','g','y','k'};

for k = 1:5
    % Create 5 random circles to display,
    X = rand(5,1);
    Y = rand(5,1);
    centers = [X Y];
    radii = 0.1*rand(5,1);

    % Clear the axes.

    % Fix the axis limits.
    xlim([-0.1 1.1])
    ylim([-0.1 1.1])

    % Set the axis aspect ratio to 1:1.
    axis square

    % Set a title.
    title(['k = ' num2str(k)])

    % Display the circles.

    % Pause for 1 second.

Input Arguments

collapse all

Coordinates of circle centers, specified as a P-by-2 matrix, such as that obtained from imfindcircles. The x-coordinates of the circle centers are in the first column and the y-coordinates are in the second column. The coordinates can be integers (of any numeric type) or floating-point values (of type double or single).

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Circle radii, specified as a column vector such as that returned by imfindcircles. The radius value at radii(j) corresponds to the circle with center coordinates centers(j,:). The values of radii can be nonnegative integers (of any numeric type) or floating-point values (of type double or single).

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Axes in which to draw circles, specified as a handle object returned by gca or axes.

Data Types: double

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 single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: viscircles(centers,radii,'Color','b') specifies blue circle edges, using the short name for blue.

collapse all

Augment drawn circles with contrasting features to improve visibility, specified as a logical value true or false. If you set the value to true, viscircles draws a contrasting circle below the colored circle.

Data Types: logical

Color of circle edges, specified as a MATLAB® ColorSpec value.

Line style of circle edge, specified as the comma-separated pair consisting of 'LineStyle' and any line specifier in the table below.

Line StyleDescriptionResulting Line
'-'Solid line

'--'Dashed line

':'Dotted line

'-.'Dash-dotted line

'none'No lineNo line

Width of circle edge, specified a positive floating-point double value. Line width is expressed in points, where each point equals 1/72 of an inch.

Output Arguments

collapse all

Circles drawn, returned as a handle to an hggroup object. This object is a child of the axes object, ax.

Introduced in R2012a

Was this topic helpful?