Skip to content

mlvbench.stimuli.shapes

Shape generation utilities.

random_idsprite(image_size, rng)

Generate a segmentation map for a random idsprite.

The shape generation is adapted from the idsprites library (Dziadzio et al., 2023).

Parameters:

Name Type Description Default
image_size int

Side length of the square image in pixels.

required
rng Generator

NumPy random number generator for reproducibility.

required

Returns:

Type Description
ndarray

Region map as uint8 NumPy array of shape (image_size, image_size, 1) with values 0 (background) and 1 (foreground shape).

split_figure(segmentation, rng, *, min_region_size=0.0)

Split the foreground region of a binary segmentation into two sub-regions.

A random line divides the foreground pixels (label 1 in the input) into two sub-regions. Background pixels (label 0) are left unchanged.

Parameters:

Name Type Description Default
segmentation ndarray

Binary segmentation map of shape (H, W, 1) and dtype uint8 with values 0 (background) and 1 (foreground). The foreground region will be split into two sub-regions using a random line.

required
rng Generator

NumPy random number generator used for reproducibility.

required
min_region_size float

Minimum size of each foreground sub-region as a fraction of the total foreground area. Must be in [0.0, 0.5]. When 0.0 (the default) any non-empty split is accepted.

0.0

Returns:

Type Description
ndarray

Region map as uint8 numpy array of shape (H, W, 1) with values 0 (background), 1 (foreground sub-region A), and 2 (foreground sub-region B).

Raises:

Type Description
ValueError

If min_region_size is outside [0.0, 0.5].