def letterbox(image, shape):
    """
    Pads image with black letterboxing to bring image.shape up to shape

    Parameters
    ----------
    image : WRITEME
    shape : WRITEME

    Returns
    -------
    WRITEME
    """

    assert len(image.shape) == 3  # rows, cols, channels
    assert len(shape) == 2  # rows, cols

    assert image.shape[0] <= shape[0]
    assert image.shape[1] <= shape[1]

    if image.shape[0] == shape[0] and image.shape[1] == shape[1]:
        return image.copy()

    rval = np.zeros((shape[0], shape[1], image.shape[2]), dtype=image.dtype)

    rstart = (shape[0] - image.shape[0]) / 2
    cstart = (shape[1] - image.shape[1]) / 2

    rend = rstart + image.shape[0]
    cend = cstart + image.shape[1]
    rval[rstart:rend, cstart:cend] = image

    return rval
dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/utils/image.py/letterbox/original