def _invert_selem(selem):
    """Change the order of the values in `selem`.

    This is a patch for the *weird* footprint inversion in
    `ndi.grey_morphology` [1]_.

    Parameters
    ----------
    selem : array
        The input structuring element.

    Returns
    -------
    inverted : array, same shape and type as `selem`
        The structuring element, in opposite order.

    Examples
    --------
    >>> selem = np.array([[0, 0, 0], [0, 1, 1], [0, 1, 1]], np.uint8)
    >>> _invert_selem(selem)
    array([[1, 1, 0],
           [1, 1, 0],
           [0, 0, 0]], dtype=uint8)

    References
    ----------
    .. [1] https://github.com/scipy/scipy/blob/ec20ababa400e39ac3ffc9148c01ef86d5349332/scipy/ndimage/morphology.py#L1285
    """
    inverted = selem[(slice(None, None, -1),) * selem.ndim]
    return inverted
