def _border_trim_slice(n, ps, pstr):
    """
        Helper function for remove_borders. Produce slices to trim t_n pixels
        along an axis, t_n//2 at the beginning and t_n//2 + t_n%2 at the end.
    """

    t_n = (n - ps) % pstr
    t_start, t_end = t_n // 2, t_n // 2 + t_n % 2
    assert t_start < n - t_end
    return slice(t_start, n - t_end)