Imaging helpers#

Image utilities: rendering, encoding, composite galleries and image features.

The image features are cheap, documented proxies of perceptual attributes used by simulated users, by computational-aesthetics baselines and by the psychometric audit of AI judges:

  • brightness — mean relative luminance (ITU-R BT.709 weights);

  • contrast — standard deviation of luminance (RMS contrast);

  • colorfulness — the metric of Hasler and Süsstrunk (2003);

  • saturation — mean HSV saturation;

  • hue_x, hue_y — saturation-weighted circular mean of hue (cosine, sine);

  • entropy — Shannon entropy of the luminance histogram (bits / 8);

  • edge_density — fraction of strong Sobel edges;

  • symmetry_lr, symmetry_ud — 1 − mean absolute difference to the mirror image;

  • coverage — fraction of pixels that differ from the dominant background;

  • complexity — PNG compression ratio (a Kolmogorov-complexity proxy used in computational aesthetics, cf. Machado and Cardoso, 1998).

Image conversion, grids, colour spaces and image features.

Functions#

fig_to_array(fig[, close])

Rasterize a matplotlib figure into a uint8 RGB array.

to_uint8(img)

Float image in [0, 1] (or uint8) → uint8 RGB array (H, W, 3).

png_bytes(img)

Encode an image as PNG bytes (Pillow).

png_base64(img)

decode_png(data)

PNG (bytes or base64 string) → uint8 RGB array.

resize(img, size)

Resize to size (int → square, or (w, h)) with Lanczos filtering.

compose_grid(images[, labels, ncols, tile, ...])

Tile images into one labelled gallery image (used for VLM judges and reports).

image_features(img[, size])

The IMAGE_FEATURES vector of an image (all roughly in [0, 1]).

hsv_to_rgb(h, s, v)

Vectorized HSV → RGB (all in [0, 1]); returns an array (..., 3).

rgb_to_hsv(rgb)

luminance(img)

Relative luminance in [0, 1] (BT.709 weights on gamma-encoded values).

text_card(text[, size, background, color])

Render short text on a card (for text-valued phenotypes in galleries).

Constants#

IMAGE_FEATURES

Built-in mutable sequence.