def reshape_nd(image, ndim):
    """Return image array with at least ndim dimensions.

    Prepend 1s to image shape as necessary.

    >>> reshape_nd(numpy.empty(0), 1).shape
    (0,)
    >>> reshape_nd(numpy.empty(1), 2).shape
    (1, 1)
    >>> reshape_nd(numpy.empty((2, 3)), 3).shape
    (1, 2, 3)
    >>> reshape_nd(numpy.empty((3, 4, 5)), 3).shape
    (3, 4, 5)

    """
    if image.ndim >= ndim:
        return image
    image = image.reshape((1,) * (ndim - image.ndim) + image.shape)
    return image
