def roi2rect(roi, inverse=False):
    """Convert ROI to rectangle coordinates or vice versa.

    :param list roi: list containing ROI corner coords ``[x0 , y0, x1, y1]``
        (input can also be tuple)
    :param bool inverse:  if True, input param ``roi`` is assumed to be of
        format ``[x0, y0, w, h]`` and will be converted into ROI
    :return:
        - tuple, (x0, y0, w, h) if param ``inverse == False``
        - tuple, (x0, y0, x1, y1) if param ``inverse == True``

    """
    x0, y0, x1, y1 = roi
    if not inverse:
        return x0, y0, x1 - x0, y1 - y0
    return x0, y0, x0 + x1, y0 + y1
