polygon
-
skimage.draw.polygon()
-
Generate coordinates of pixels within polygon.
Parameters: y : (N,) ndarray
Y-coordinates of vertices of polygon.
x : (N,) ndarray
X-coordinates of vertices of polygon.
shape : tuple, optional
Image shape which is used to determine the maximum extent of output pixel coordinates. This is useful for polygons which exceed the image size. By default the full extent of the polygon are used.
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
.Examples
>>> from skimage.draw import polygon >>> img = np.zeros((10, 10), dtype=np.uint8) >>> x = np.array([1, 7, 4, 1]) >>> y = np.array([1, 2, 8, 1]) >>> rr, cc = polygon(y, x) >>> img[rr, cc] = 1 >>> img array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
Please login to continue.