random_shapes(image_shape, max_shapes, min_shapes=1, min_size=2, max_size=None, multichannel=True, num_channels=3, shape=None, intensity_range=None, allow_overlap=False, num_trials=100, random_seed=None)
The image is populated with random shapes with random sizes, random locations, and random colors, with or without overlap.
Shapes have random (row, col) starting coordinates and random sizes bounded by :None:None:`min_size`
and :None:None:`max_size`
. It can occur that a randomly generated shape will not fit the image at all. In that case, the algorithm will try again with new starting coordinates a certain number of times. However, it also means that some shapes may be skipped altogether. In that case, this function will generate fewer shapes than requested.
The number of rows and columns of the image to generate.
The maximum number of shapes to (attempt to) fit into the shape.
The minimum number of shapes to (attempt to) fit into the shape.
The minimum dimension of each shape to fit into the image.
The maximum dimension of each shape to fit into the image.
If True, the generated image has num_channels
color channels, otherwise generates grayscale image.
Number of channels in the generated image. If 1, generate monochrome images, else color images with multiple channels. Ignored if multichannel
is set to False.
The name of the shape to generate or :None:None:`None`
to pick random ones.
The range of values to sample pixel values from. For grayscale images the format is (min, max). For multichannel - ((min, max),) if the ranges are equal across the channels, and ((min_0, max_0), ... (min_N, max_N)) if they differ. As the function supports generation of uint8 arrays only, the maximum range is (0, 255). If None, set to (0, 254) for each channel reserving color of intensity = 255 for background.
If :None:None:`True`
, allow shapes to overlap.
How often to attempt to fit a shape into the image before skipping it.
Seed to initialize the random number generator. If :None:None:`None`
, a random seed from the operating system is used.
An image with the fitted shapes.
A list of labels, one per shape in the image. Each label is a (category, ((r0, r1), (c0, c1))) tuple specifying the category and bounding box coordinates of the shape.
Generate an image with random shapes, labeled with bounding boxes.
>>> import skimage.drawThis example is valid syntax, but we were not able to check execution
... image, labels = skimage.draw.random_shapes((32, 32), max_shapes=3)
... image # doctest: +SKIP array([ [[255, 255, 255], [255, 255, 255], [255, 255, 255], ..., [255, 255, 255], [255, 255, 255], [255, 255, 255]]], dtype=uint8)
>>> labels # doctest: +SKIP [('circle', ((22, 18), (25, 21))), ('triangle', ((5, 6), (13, 13)))]See :
The following pages refer to to this document either explicitly or contain code examples using this.
skimage.draw._random_shapes.random_shapes
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