Function File: regionprops (BW)
Function File: regionprops (L)
Function File: regionprops (CC)
Function File: regionprops (…, properties)
Function File: regionprops (…, I, properties)

Compute properties of image regions.

Measures several properties for each region within an image. Returns a struct array, one element per region, whose field names are the measured properties.

Individual regions can be defined in three different ways, a binary image, a labelled image, or a bwconncomp struct, each providing different advantages.

BW

A binary image. Must be of class logical. Individual regions will be the connected component as computed by bwconnmp using the maximal connectivity for the number of dimensions of bw (see conndef for details). For alternative connectivities, call bwconncomp directly and use its output instead.

bw must really be of class logical. If not, even if it is a numeric array of 0’s and 1’s, it will be treated as a labelled image with a single discontinuous region. For example:

## Handled as binary image with 3 regions
bw = logical ([
  1 0 1 0 1
  1 0 1 0 1
]);

## Handled as labelled image with 1 region
bw = [
  1 0 1 0 1
  1 0 1 0 1
];
L

A labelled image. Each region is the collection of all positive elements with the same value. This allows computing properties of regions that would otherwise be considered separate or connected. For example:

## Recognizes 4 regions
l = [
  1 2 3 4
  1 2 3 4
];

## Recognizes 2 (discontinuous) regions
l = [
  1 2 1 2
  1 2 1 2
];
CC

A bwconnmp() structure. This is a struct with the following 4 fields: Connectivity, ImageSize, NumObjects, and PixelIdxList. See bwconncomp for details.

The properties to be measured can be defined via a cell array or a comma separated list or strings. Some of the properties are only supported if the matching grayscale image I is also supplied. Others are only supported for 2 dimensional images. See the list below for details on each property limitation. If none is specified, it defaults to the "basic" set of properties.

"Area"

The number of pixels in the region. Note that this differs from bwarea where each pixel has different weights.

"BoundingBox"

The smallest rectangle that encloses the region. This is represented as a row vector such as [x y z … x_length y_length z_length …].

The first half corresponds to the lower coordinates of each dimension while the second half, to the length in that dimension. For the two dimensional case, the first 2 elements correspond to the coordinates of the upper left corner of the bounding box, while the two last entries are the width and the height of the box.

"Centroid"

The coordinates for the region centre of mass. This is a row vector with one element per dimension, such as [x y z …].

"ConvexArea"

Number of pixels in the ConvexImage. Only supported for 2D images.

"ConvexHull"

The coordinates of the smallest convex polygon that fully encloses the region. Returns a m*2 matrix with each row containing the x- and y-coordinate of one corner point of the polygon. Only supported for 2D images. (see also: convhull)

"ConvexImage"

A binary image containing all pixels inside the convex hull. The size of this image is the bounding box. Only supported for 2D images. (see also: poly2mask)

"Eccentricity"

The eccentricity of the ellipse that has the same normalized second central moments as the region (value between 0 and 1).

"EquivDiameter"

The diameter of a circle with the same area as the object.

"EulerNumber"

The Euler number of the region using connectivity 8. Only supported for 2D images. See bweuler for details.

"Extent"

The area of the object divided by the area of the bounding box.

"Extrema"

Returns an 8-by-2 matrix with the extrema points of the object. The first column holds the returned x- and the second column the y-values. The order of the 8 points is: top-left, top-right, right-top, right-bottom, bottom-right, bottom-left, left-bottom, left-top.

"FilledArea"

The area of the object including possible holes.

"FilledImage"

A binary image with the same size as the object’s bounding box that contains the object with all holes removed.

"Image"

An image with the same size as the bounding box that contains the original pixels.

"MajorAxisLength"

The length of the major axis of the ellipse that has the same normalized second central moments as the object.

"MaxIntensity"

The maximum intensity value inside each region. Requires a grayscale image I.

"MeanIntensity"

The mean intensity value inside each region. Requires a grayscale image I.

"MinIntensity"

The minimum intensity value inside each region. Requires a grayscale image I.

"MinorAxisLength"

The length of the minor axis of the ellipse that has the same normalized second central moments as the object.

"Orientation"

The angle between the x-axis and the major axis of the ellipse that has the same normalized second central moments as the object (value in degrees between -90 and 90).

"Perimeter"

The length of the boundary of the object.

"PixelIdxList"

The linear indices for the elements of each region in a column vector.

"PixelList"

The subscript indices for the elements of each region. This is a p-by-Q matrix where p is the number of elements and Q is the number of dimensions. Each row is of the form [x y z …].

"PixelValues"

The actual pixel values inside each region in a column vector. Requires a grayscale image I.

"Solidity"

Ratio of Area / ConvexArea. Only supported for 2D images.

"SubarrayIdx"

A cell array with subscript indices for the bounding box. This can be used as I(props(p).SubarrayIdx{:}), where p is one of the regions, to extract the image in its bounding box.

"WeightedCentroid"

The coordinates for the region centre of mass when using the intensity of each element as weight. This is a row vector with one element per dimension, such as [x y z …]. Requires a grayscale image I.

In addition, the strings "basic" and "all" can be used to select a subset of the properties:

"basic" (default)

Compute "Area", "Centroid", and "BoundingBox".

"all"

Computes all possible properties for the image, i.e., it will not compute properties that require grayscale unless the grayscale image is available, and it will not compute properties that are limited to 2 dimensions, unless the image is 2 dimensions.

See also: bwlabel, bwperim, bweuler, convhull, poly2mask.

Package: image