def extend_segment(segment, max_l, padding):
    """
    segment: segment start and end indices [x0,x1]
    max_l: maximum indice possible
    padding: percentage to extend
    """
    x0 = segment[0]
    x1 = segment[1]
    length = x1-x0
    ext = int(padding*length)
    return [max([0,x0-ext]), min([max_l,x1+ext])]