import numpy as np


def to_rgb(pixels):
    return np.repeat(pixels, 3 if pixels.shape[2] == 1 else 1, 2)

def binarize(arr, generate=np.random.uniform):
    return (generate(size=arr.shape) < arr).astype('i')

import numpy as np


def to_rgb(pixels):
    return np.repeat(pixels, 3 if pixels.shape[2] == 1 else 1, 2)

def binarize(arr, generate=np.random.uniform):
    return (generate(size=arr.shape) < arr).astype('i')

def quantisize(arr, levels):
    return (np.digitize(arr, np.arange(levels) / levels) - 1).astype('i')

Add method I am yet to use