Main Content

circles2mask

Create binary masks from circles

Since R2024a

Description

mask = circles2mask(centers,radii,maskSize) creates a binary mask image from circles specified by center coordinates centers and radius lengths radii. The maskSize argument specifies the dimensions of the output binary mask, mask.

example

Examples

collapse all

Load a grayscale image into the workspace and display it.

A = imread("coins.png");
imshow(A)

Figure contains an axes object. The hidden axes object contains an object of type image.

Find all the circles with radii in the range [20, 35] pixels.

[centers,radii] = imfindcircles(A,[20 35],Sensitivity=0.9);

Create a binary mask image that contains masks for the detected circles.

mask = circles2mask(centers,radii,size(A));

Display the original image and the mask image.

figure
montage({A,mask})

Figure contains an axes object. The hidden axes object contains an object of type image.

Input Arguments

collapse all

Circle centers, specified as a P-by-2 matrix. Each row specifies the xy-coordinates of a circle center. You can specify this argument using the centers output of the imfindcircles function.

Data Types: double

Circle radii, specified as a vector. You can specify this argument using the radii output of the imfindcircles function.

Data Types: double

Mask image size, specified as a 2-element row vector of nonnegative integers of the form [height width]. This argument specifies the dimensions of the output binary mask, mask, in pixels.

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

Output Arguments

collapse all

Binary mask image, returned as a logical matrix of the size specified by the maskSize argument.

Data Types: logical

Tips

  • circles2mask can generate masks for circles with centers outside the bounds of the image.

Extended Capabilities

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

Version History

Introduced in R2024a