Skip to content

mlvbench.stimuli.textures

Texturization utilities.

TextureDataset

Bases: Dataset

Dataset of texture images.

__getitem__(index)

Return the texture at the given index as a PIL Image.

__init__(path)

Initialize the dataset from a directory of *.jpg images.

__len__()

Return the number of textures.

load_textures(name, seed)

Load a texture dataset and return train, val, and test subsets.

If not done already, this will download and extract the dataset. The textures are split into train, val, and test subsets (80%/10%/10%).

Parameters:

Name Type Description Default
name str

Name of the textures dataset. Only "dtd" is supported.

required
seed int

Random seed for splitting the dataset into train, val, and test subsets.

required

Returns:

Type Description
dict[str, Subset]

A dictionary of subsets with keys "train", "val", and "test".

Raises:

Type Description
ValueError

If the dataset name is not supported.

texturize(region_map, texture_dataset, rng)

Fill each region in a region map with a unique random texture.

Parameters:

Name Type Description Default
region_map ndarray

Integer-labeled region map of shape (H, W, 1) and dtype uint8.

required
texture_dataset Dataset

Dataset of PIL Images. Each item must be a PIL Image that will be resized to match the region map dimensions. Must contain at least as many items as there are unique regions.

required
rng Generator

NumPy random number generator for reproducibility. Two calls with the same RNG state but different numbers of regions N and M will assign the same texture to the first min(N, M) regions.

required

Returns:

Type Description
ndarray

RGB image as uint8 NumPy array of shape (H, W, 3).

Raises:

Type Description
ValueError

If the number of unique regions exceeds the dataset size.