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 |
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 |
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 |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |