| Image Processing Toolbox™ | ![]() |
STATS = regionprops(L, properties)
STATS = regionprops(L, I,properties)
STATS = regionprops(L, properties) measures a set of properties for each labeled region L. L can be a label matrix or a multidimensional array. WhenL is a label matrix, positive integer elements of L correspond to different regions. For example, the set of elements of L equal to 1 corresponds to region 1; the set of elements of L equal to 2 corresponds to region 2; and so on. The return value STATS is a structure array of length max(L(:)). The fields of the structure array denote different measurements for each region, as specified by properties. See Properties for a list of valid property strings.
STATS = regionprops(L, I,properties) measures a set of properties for each labeled region in the 2-D or N-D grayscale image I. L is a label matrix that identifies the regions in I and must have the same size as I.
properties can be a comma-separated list of strings, a cell array containing strings, the single string 'all', or the string 'basic'. If properties is the string 'all', regionprops computes all the shape measurements, listed in Shape Measurements. If called with a grayscale image, regionprops also returns the pixel value measurements, listed in Pixel Value Measurements. If properties is not specified or if it is the string 'basic', regionprops computes only the 'Area', 'Centroid', and 'BoundingBox' measurements. The following properties can be calculated on N-D label matrices: 'Area', 'BoundingBox','Centroid', 'FilledArea', 'FilledImage', 'Image','PixelIdxList', 'PixelList', and 'SubarrayIdx'.
Shape Measurements
Pixel Value Measurements
'Area' — Scalar; the actual number of pixels in the region. (This value might differ slightly from the value returned by bwarea, which weights different patterns of pixels differently.)
'BoundingBox' — 1-by-ndims(L)*2 vector; the smallest rectangle containing the region. BoundingBox is [ul_corner width], where
ul_corner | is in the form [x y z ...] and specifies the upper left corner of the bounding box |
width | is in the form [x_width y_width ...] and specifies the width of the bounding box along each dimension |
'Centroid' – 1-by-ndims(L) vector that specifies the center of mass of the region. Note that the first element of Centroid is the horizontal coordinate (or x-coordinate) of the center of mass, and the second element is the vertical coordinate (or y-coordinate). All other elements of Centroid are in order of dimension.
This figure illustrates the centroid and bounding box. The region consists of the white pixels; the green box is the bounding box, and the red dot is the centroid.

'ConvexHull' — p-by-2 matrix that specifies the smallest convex polygon that can contain the region. Each row of the matrix contains the x- and y-coordinates of one vertex of the polygon. This property is supported only for 2-D input label matrices.
'ConvexImage' — Binary image (logical) that specifies the convex hull, with all pixels within the hull filled in (i.e., set to on). (For pixels that the boundary of the hull passes through, regionprops uses the same logic as roipoly to determine whether the pixel is inside or outside the hull.) The image is the size of the bounding box of the region. This property is supported only for 2-D input label matrices.
'ConvexArea' — Scalar that specifies the number of pixels in 'ConvexImage'. This property is supported only for 2-D input label matrices.
'Eccentricity' — Scalar that specifies the eccentricity of the ellipse that has the same second-moments as the region. The eccentricity is the ratio of the distance between the foci of the ellipse and its major axis length. The value is between 0 and 1. (0 and 1 are degenerate cases; an ellipse whose eccentricity is 0 is actually a circle, while an ellipse whose eccentricity is 1 is a line segment.) This property is supported only for 2-D input label matrices.
'EquivDiameter' — Scalar that specifies the diameter of a circle with the same area as the region. Computed as sqrt(4*Area/pi). This property is supported only for 2-D input label matrices.
'EulerNumber' — Scalar that specifies the number of objects in the region minus the number of holes in those objects. This property is supported only for 2-D input label matrices. regionprops uses 8-connectivity to compute the EulerNumber measurement. To learn more about connectivity, see Pixel Connectivity.
'Extent' — Scalar that specifies the proportion of the pixels in the bounding box that are also in the region. Computed as the Area divided by the area of the bounding box. This property is supported only for 2-D input label matrices.
'Extrema' — 8-by-2 matrix that specifies the extrema points in the region. Each row of the matrix contains the x- and y-coordinates of one of the points. The format of the vector is [top-left top-right right-top right-bottom bottom-right bottom-left left-bottom left-top]. This property is supported only for 2-D input label matrices.
This figure illustrates the extrema of two different regions. In the region on the left, each extrema point is distinct; in the region on the right, certain extrema points (e.g., top-left and left-top) are identical.

'FilledArea' — Scalar specifying the number of on pixels in FilledImage.
'FilledImage' — Binary image (logical) of the same size as the bounding box of the region. The on pixels correspond to the region, with all holes filled in.

'Image' — Binary image (logical) of the same size as the bounding box of the region; the on pixels correspond to the region, and all other pixels are off.
'MajorAxisLength' — Scalar specifying the length (in pixels) of the major axis of the ellipse that has the same normalized second central moments as the region. This property is supported only for 2-D input label matrices.
'MaxIntensity' — Scalar specifying the value of the pixel with the greatest intensity in the region.
'MeanIntensity' — Scalar specifying the mean of all the intensity values in the region.
'MinIntensity' — Scalar specifying the value of the pixel with the lowest intensity in the region.
'MinorAxisLength' — Scalar; the length (in pixels) of the minor axis of the ellipse that has the same normalized second central moments as the region. This property is supported only for 2-D input label matrices.
'Orientation' — Scalar; the angle (in degrees ranging from -90 to 90 degrees) between the x-axis and the major axis of the ellipse that has the same second-moments as the region. This property is supported only for 2-D input label matrices.
This figure illustrates the axes and orientation of the ellipse.
The left side of the figure shows an image region and its corresponding
ellipse. The right side shows the same ellipse, with features indicated
graphically; the solid blue lines are the axes, the red dots are the
foci, and the orientation is the angle between the horizontal dotted
line and the major axis
.
'Perimeter' — p-element vector containing the distance around the boundary of each contiguous region in the image, where p is the number of regions. regionprops computes the perimeter by calculating the distance between each adjoining pair of pixels around the border of the region. If the image contains discontiguous regions, regionprops returns unexpected results. The following figure shows the pixels included in the perimeter calculation for this object

'PixelIdxList' — p-element vector containing the linear indices of the pixels in the region.
'PixelList' — p-by-ndims(L) matrix specifying the locations of pixels in the region. Each row of the matrix has the form [x y z ...] and specifies the coordinates of one pixel in the region.
'PixelValues' — p-by-1 vector, where p is the number of pixels in the region. Each element in the vector contains the value of a pixel in the region.
'Solidity' — Scalar specifying the proportion of the pixels in the convex hull that are also in the region. Computed as Area/ConvexArea. This property is supported only for 2-D input label matrices.
'SubarrayIdx' — Vector of linear indices of nonzero elements returned in Image. See 'Image' for more information.
'WeightedCentroid' — p-by-ndims(L) vector of coordinates specifying the center of the region based on location and intensity value. The first element of WeightedCentroid is the horizontal coordinate (or x-coordinate) of the weighted centroid, and the second element is the vertical coordinate (or y-coordinate). All other elements of WeightedCentroid are in order of dimension.
The input label matrix L can have any numeric class and any dimension, but must be real, nonsparse, and contain integers.
You must convert a binary image into a label matrix before passing it to regionprops. There are two common ways to convert a binary image into a label matrix:
Using the bwlabel function
L = bwlabel(BW);
Using the double function
L = double(BW);
Note, however, that these functions produce different but equally valid label matrices from the same binary image.
For example, given the following logical matrix, BW,
1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1
bwlabel creates a label matrix containing two contiguous regions labeled by the integer values 1 and 2.
mylabel = bwlabel(BW)
mylabel =
1 1 0 0 0 0
1 1 0 0 0 0
0 0 0 0 0 0
0 0 0 0 2 2
0 0 0 0 2 2The double function creates a label matrix containing one discontiguous region labeled by the integer value 1.
mylabel2 = double(BW)
mylabel2 =
1 1 0 0 0 0
1 1 0 0 0 0
0 0 0 0 0 0
0 0 0 0 1 1
0 0 0 0 1 1
Because each result is legitimately desirable in certain situations, regionprops does not attempt to perform either type of conversion on binary images and instead requires that you convert them using either method. You should convert a binary image to a label matrix using one of these methods (or another method if appropriate) before calling regionprops.
The function ismember is useful in conjunction with regionprops for selecting regions based on certain criteria. For example, these commands create a binary image containing only the regions whose area is greater than 80.
idx = find([stats.Area] > 80); BW2 = ismember(L,idx);
The comma-separated list syntax for structure arrays is very useful when you work with the output of regionprops. For example, for a field that contains a scalar, you can use this syntax to create a vector containing the value of this field for each region in the image.
For instance, if stats is a structure array with field Area, then the following two expressions are equivalent:
stats(1).Area, stats(2).Area, ..., stats(end).Area
and
stats.Area
Therefore, you can use these calls to create a vector containing the area of each region in the image.
stats = regionprops(L,'Area'); allArea = [stats.Area];
allArea is a vector of the same length as the structure array stats.
Most of the measurements take very little time to compute. However, there are a few measuements, listed below, that can take significantly longer, depending on the number of regions in L:
'ConvexHull'
'ConvexImage'
'ConvexArea'
'FilledImage'
Note that computing certain groups of measurements takes about the same amount of time as computing just one of them because regionprops takes advantage of intermediate computations used in both computations. Therefore, it is fastest to compute all the desired measurements in a single call to regionprops.
Compute the centroids of all the labelled regions in an image and then superimpose a plot of the centroids over the original image.
bw = imread('text.png');
L = bwlabel(bw);
s = regionprops(L, 'centroid');
centroids = cat(1, s.Centroid);
imshow(bw)
hold on
plot(centroids(:,1), centroids(:,2), 'b*')
hold offbwlabel, bwlabeln, ismember, watershed
ismember (MATLAB® function)
![]() | reflect | rgb2gray | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |