{ } Raw JSON

bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / draw / draw / polygon

function

skimage.draw.draw:polygon

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

Signature

def   polygon ( r c shape = None )

Summary

Generate coordinates of pixels inside a polygon.

Parameters

r : (N,) array_like

Row coordinates of the polygon's vertices.

c : (N,) array_like

Column coordinates of the polygon's vertices.

shape : tuple, optional

Image shape which is used to determine the maximum extent of output pixel coordinates. This is useful for polygons that exceed the image size. If None, the full extent of the polygon is used. Must be at least length 2. Only the first two values are used to determine the extent of the input image.

Returns

rr, cc : ndarray of int

Pixel coordinates of polygon. May be used to directly index into an array, e.g. img[rr, cc] = 1.

Notes

This function ensures that rr and cc don't contain negative values. Pixels of the polygon that whose coordinates are smaller 0, are not drawn.

Examples

import skimage as ski
r = np.array([1, 2, 8])
c = np.array([1, 7, 4])
rr, cc = ski.draw.polygon(r, c)
img = np.zeros((10, 10), dtype=int)
img[rr, cc] = 1
img
If the image `shape` is defined and vertices / points of the `polygon` are outside this coordinate space, only a part (or none at all) of the polygon's pixels is returned. Shifting the polygon's vertices by an offset can be used to move the polygon around and potentially draw an arbitrary sub-region of the polygon.
offset = (2, -4)
rr, cc = ski.draw.polygon(r - offset[0], c - offset[1], shape=img.shape)
img = np.zeros((10, 10), dtype=int)
img[rr, cc] = 1
img

See also

polygon2mask

Create a binary mask from a polygon.

Aliases

  • skimage.draw.polygon