skimage 0.17.2

ParametersReturnsBackRef
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.

Parameters

image_shape : tuple

The number of rows and columns of the image to generate.

max_shapes : int

The maximum number of shapes to (attempt to) fit into the shape.

min_shapes : int, optional

The minimum number of shapes to (attempt to) fit into the shape.

min_size : int, optional

The minimum dimension of each shape to fit into the image.

max_size : int, optional

The maximum dimension of each shape to fit into the image.

multichannel : bool, optional

If True, the generated image has num_channels color channels, otherwise generates grayscale image.

num_channels : int, optional

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.

shape : {rectangle, circle, triangle, ellipse, None} str, optional

The name of the shape to generate or :None:None:`None` to pick random ones.

intensity_range : {tuple of tuples of uint8, tuple of uint8}, optional

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.

allow_overlap : bool, optional

If :None:None:`True`, allow shapes to overlap.

num_trials : int, optional

How often to attempt to fit a shape into the image before skipping it.

random_seed : int, optional

Seed to initialize the random number generator. If :None:None:`None`, a random seed from the operating system is used.

Returns

image : uint8 array

An image with the fitted shapes.

labels : list

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.

Examples

This example is valid syntax, but we were not able to check execution
>>> import skimage.draw
... 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)
This example is valid syntax, but we were not able to check execution
>>> labels # doctest: +SKIP
[('circle', ((22, 18), (25, 21))),
 ('triangle', ((5, 6), (13, 13)))]
See :

Back References

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

skimage.draw._random_shapes.random_shapes

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/_random_shapes.py#292
type: <class 'function'>
Commit: