def _get_roi_from_rect(rect):
    """
    Returns the ROI from a rectangle, the rectangle can have the top and bottom flipped.
    :param rect: Rect to get roi from
    :return: x, y, width, height of ROI
    """
    x_min = min(rect.topLeft().x(), rect.bottomRight().x())
    y_min = min(rect.topLeft().y(), rect.bottomRight().y())
    x_max = max(rect.topLeft().x(), rect.bottomRight().x())
    y_max = max(rect.topLeft().y(), rect.bottomRight().y())

    return x_min, y_min, x_max, y_max