packages/vaex-core/vaex/image.py
def polychrome(I, colors, vmin=None, vmax=None, axis=-1):
    """Similar to monochrome, but now do it for multiple colors

    Example
    >>> I = np.arange(32.).reshape(4,4,2)
    >>> colors = [(0, 0, 1), (0, 1, 0)] # red and green
    >>> rgb = vx.image.polychrome(I, colors) # shape is (4,4,3)

    :param I: ndarray of any shape (3d will result in a 2d image)
    :param colors: sequence of [(r,g,b), ...] values
    :param vmin: normalization minimum for I, or np.nanmin(I) when None
    :param vmax: normalization maximum for I, or np.nanmax(I) when None
    :param axis: axis which to sum over, by default the last
    :return:
    """
    axes_length = len(I.shape)
    allaxes = list(range(axes_length))
    otheraxes = list(allaxes)
    otheraxes.remove((axis + axes_length) % axes_length)
    otheraxes = tuple(otheraxes)

    if vmin is None:
        vmin = np.nanmin(I, axis=otheraxes)
    if vmax is None:
        vmax = np.nanmax(I, axis=otheraxes)
    normalized = (I - vmin) / (vmax - vmin)
    return np.clip(normalized, 0, 1).dot(colors)
def polychrome(I, colors, vmin=None, vmax=None, axis=-1):
    """Similar to monochrome, but now do it for multiple colors

    Example
    >>> I = np.arange(32.).reshape(4,4,2)
    >>> colors = [(0, 0, 1), (0, 1, 0)] # red and green
    >>> rgb = vx.image.polychrome(I, colors) # shape is (4,4,3)

    :param I: ndarray of any shape (3d will result in a 2d image)
    :param colors: sequence of [(r,g,b), ...] values
    :param vmin: normalization minimum for I, or np.nanmin(I) when None
    :param vmax: normalization maximum for I, or np.nanmax(I) when None
    :param axis: axis which to sum over, by default the last
    :return:
    """
    axes_length = len(I.shape)
    allaxes = list(range(axes_length))
    otheraxes = list(allaxes)
    otheraxes.remove((axis + axes_length) % axes_length)
    otheraxes = tuple(otheraxes)

    if vmin is None:
        vmin = np.nanmin(I, axis=otheraxes)
    if vmax is None:
        vmax = np.nanmax(I, axis=otheraxes)
    normalized = (I - vmin) / (vmax - vmin)
    return np.clip(normalized, 0, 1).dot(colors)
Similar to monochrome, but now do it for multiple colors

    Example
    >>> I = np.arange(32.).reshape(4,4,2)
    >>> colors = [(0, 0, 1), (0, 1, 0)] # red and green
    >>> rgb = vx.image.polychrome(I, colors) # shape is (4,4,3)

    :param I: ndarray of any shape (3d will result in a 2d image)
    :param colors: sequence of [(r,g,b), ...] values
    :param vmin: normalization minimum for I, or np.nanmin(I) when None
    :param vmax: normalization maximum for I, or np.nanmax(I) when None
    :param axis: axis which to sum over, by default the last
    :return: