Skip to content

Utils

Source

Shared utilities for normalization.

broadcast_stats(stats, n_channels, name)

Broadcast a length-1 stats list to n_channels, or validate length.

Parameters:

  • stats (list[float]) –

    A length-1 list (global) or a per-channel list.

  • n_channels (int) –

    Expected number of channels.

  • name (str) –

    Field name used in error messages.

Returns:

  • list[float]

    Values matching n_channels.

Raises:

  • ValueError

    If stats length is neither 1 nor n_channels.

reshape_stats(stats, ndim, channel_axis=0)

Reshape stats to match the number of dimensions of the input image.

Parameters:

  • stats (list of float) –

    List of per-channel statistic values.

  • ndim (int) –

    Number of dimensions in the image.

  • channel_axis (int, default: 0 ) –

    Position of the channel axis in the image.

Returns:

  • NDArray

    Stats array reshaped, with the channel dimension at the specified axis and singleton dimensions elsewhere.