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_likeRow coordinates of the polygon's vertices.
c: (N,) array_likeColumn coordinates of the polygon's vertices.
shape: tuple, optionalImage 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 intPixel 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✓
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