def compute_iou(groundtruth_box, detection_box):
    """
    Return a float intersection pixel area of two
    bounding boxes divided by the union of the two

    :param list groundtruth_box: xmin, g_xmax, ymin, ymax
    x_leftmost_corner, x_rightmost_corner, y_leftmost_corner, y_rightmost_corner
    :param list detection_box: xmin, g_xmax, ymin, ymax
    x_leftmost_corner, x_rightmost_corner, y_leftmost_corner, y_rightmost_corner
    :return float iou intersection pixel area of two
    bounding boxes divided by the union of the two
    """
    if groundtruth_box == detection_box:
        return 1.0
    g_xmin, g_xmax, g_ymin, g_ymax = tuple(groundtruth_box)
    d_xmin, d_xmax, d_ymin, d_ymax = tuple(detection_box)

    xa = max(g_xmin, d_xmin)
    ya = max(g_ymin, d_ymin)
    xb = min(g_xmax, d_xmax)
    yb = min(g_ymax, d_ymax)

    boxAArea = (g_xmax - g_xmin + 1) * (g_ymax - g_ymin + 1)
    boxBArea = (d_xmax - d_xmin + 1) * (d_ymax - d_ymin + 1)
    intersection = max(0, xb - xa + 1) * max(0, yb - ya + 1)

    if boxAArea + boxBArea == intersection:
        return 1.0

    iou = float(intersection) / float(boxAArea + boxBArea - intersection)
    return iou