regions

Splits a polyshape into its disconnected regions.

Category: Mathematics > Computational Geometry

Syntax

R = regions(pshape)

One element per connected region, each with its own holes.

R = regions(pshape, I)

Only the regions selected by the index I.

Description

Each region is a solid piece together with the holes inside it. This is the tool for analysing pieces one by one, for instance computing the area of each island of a shape, or discarding small ones.

To count the regions only, read the NumRegions property.

Input arguments

pshape
A polyshape object.

Output arguments

R
The regions, as separate polyshape objects.

Example

Count the regions

P = polyshape([0 1 1 0 NaN 3 5 5 3], [0 0 1 1 NaN 0 0 2 2]);
R = regions(P);
numel(R)
Output
ans = 2

Notes

In MatLivre the result is returned as a cell array of polyshapes rather than a polyshape array, so use R{k} to reach the k-th region.

See also

holes numboundaries sortregions rmslivers addboundary