enp.interp#
- etils.enp.interp(x: etils.enp.array_types.typing.Array, from_: Tuple[int | float | etils.enp.array_types.typing.Array | Tuple[Any, ...] | List[Any], int | float | etils.enp.array_types.typing.Array | Tuple[Any, ...] | List[Any]], to: Tuple[int | float | etils.enp.array_types.typing.Array | Tuple[Any, ...] | List[Any], int | float | etils.enp.array_types.typing.Array | Tuple[Any, ...] | List[Any]], *, axis: int = -1, xnp: Any = Ellipsis) etils.enp.array_types.typing.FloatArray [source]#
Linearly scale the given value by the given range.
Somehow similar to np.interp or scipy.interpolate.inter1d with some differences like support scaling an axis by a different factors and extrapolate values outside the boundaries.
from_ and to are expected to be (min, max) tuples and the function interpolate between the two ranges.
Example: Normalizing a uint8 image to (-1, 1).
img = jnp.array([ [0, 0], [127, 255], ]) img = enp.interp(img, (0, 255), (0, 1)) img == jnp.array([ [-1, -1], [0.498..., 1], ])
min and max can be either float values or array like structure, in which case the numpy broadcasting rules applies (x should be a Array[… d] and min/max values should be Array[d].
Example: Converting normalized 3d coordinates to world coordinates.
coords = enp.interp(coords, from_=(-1, 1), to=(0, (h, w, d)))
coords[:, 0] is interpolated from (-1, 1) to (0, h)
coords[:, 1] is interpolated from (-1, 1) to (0, w)
coords[:, 2] is interpolated from (-1, 1) to (0, d)
- Parameters:
x – Array to scale
from – Range of x.
to – Range to which normalize x.
axis – Axis on which normalizing. Only relevant if from_ or to items contains range value.
xnp – Numpy module to use
- Returns:
Float tensor with same shape as x, but with normalized coordinates.