skimage 0.17.2

NotesParametersReturnsBackRef
rectangle(start, end=None, extent=None, shape=None)

Notes

This function can be applied to N-dimensional images, by passing start and end or :None:None:`extent` as tuples of length N.

Parameters

start : tuple

Origin point of the rectangle, e.g., ([plane,] row, column) .

end : tuple

End point of the rectangle ([plane,] row, column) . For a 2D matrix, the slice defined by the rectangle is [start:(end+1)] . Either end or :None:None:`extent` must be specified.

extent : tuple

The extent (size) of the drawn rectangle. E.g., ([num_planes,] num_rows, num_cols) . Either end or :None:None:`extent` must be specified. A negative extent is valid, and will result in a rectangle going along the oposite direction. If extent is negative, the start point is not included.

shape : tuple, optional

Image shape used to determine the maximum bounds of the output coordinates. This is useful for clipping rectangles that exceed the image size. By default, no clipping is done.

Returns

coords : array of int, shape (Ndim, Npoints)

The coordinates of all pixels in the rectangle.

Generate coordinates of pixels within a rectangle.

Examples

This example is valid syntax, but we were not able to check execution
>>> import numpy as np
... from skimage.draw import rectangle
... img = np.zeros((5, 5), dtype=np.uint8)
... start = (1, 1)
... extent = (3, 3)
... rr, cc = rectangle(start, extent=extent, shape=img.shape)
... img[rr, cc] = 1
... img array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]], dtype=uint8)
This example is valid syntax, but we were not able to check execution
>>> img = np.zeros((5, 5), dtype=np.uint8)
... start = (0, 1)
... end = (3, 3)
... rr, cc = rectangle(start, end=end, shape=img.shape)
... img[rr, cc] = 1
... img array([[0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]], dtype=uint8)
This example is valid syntax, but we were not able to check execution
>>> import numpy as np
... from skimage.draw import rectangle
... img = np.zeros((6, 6), dtype=np.uint8)
... start = (3, 3) >>>
This example is valid syntax, but we were not able to check execution
>>> rr, cc = rectangle(start, extent=(2, 2))
... img[rr, cc] = 1
... rr, cc = rectangle(start, extent=(-2, 2))
... img[rr, cc] = 2
... rr, cc = rectangle(start, extent=(-2, -2))
... img[rr, cc] = 3
... rr, cc = rectangle(start, extent=(2, -2))
... img[rr, cc] = 4
... print(img) [[0 0 0 0 0 0] [0 3 3 2 2 0] [0 3 3 2 2 0] [0 4 4 1 1 0] [0 4 4 1 1 0] [0 0 0 0 0 0]]
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

skimage.draw.draw.rectangle skimage.draw.draw.rectangle_perimeter

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /skimage/draw/draw.py#755
type: <class 'function'>
Commit: