{ } Raw JSON

bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / draw / _polygon2mask / polygon2mask

function

skimage.draw._polygon2mask:polygon2mask

source: /dev/scikit-image/src/skimage/draw/_polygon2mask.py :6

Signature

def   polygon2mask ( image_shape polygon )

Summary

Create a binary mask from a polygon.

Parameters

image_shape : tuple of (int, int)

The shape of the mask.

polygon : array_like of shape (N, 2)

The polygon coordinates, where N is the number of points. The coordinates are (row, column).

Returns

mask : 2-D ndarray of type 'bool'

The binary mask that corresponds to the input polygon.

Notes

This function does not do any border checking. Parts of the polygon that are outside the coordinate space defined by image_shape are not drawn.

Examples

import skimage as ski
image_shape = (10, 10)
polygon = np.array([[1, 1], [2, 7], [8, 4]])
mask = ski.draw.polygon2mask(image_shape, polygon)
mask.astype(int)
If vertices / points of the `polygon` are outside the coordinate space defined by `image_shape`, only a part (or none at all) of the polygon is drawn in the mask.
offset = np.array([[2, -4]])
ski.draw.polygon2mask(image_shape, polygon - offset).astype(int)

See also

polygon

Generate coordinates of pixels inside a polygon.

Aliases

  • skimage.draw.polygon2mask