def iou(box1, box2):
    """ Calculate intersection over union between two boxes 
    """
    x_min_1, y_min_1, width_1, height_1 = box1
    x_min_2, y_min_2, width_2, height_2 = box2
    assert width_1 * height_1 > 0
    assert width_2 * height_2 > 0
    x_max_1, y_max_1 = x_min_1 + width_1, y_min_1 + height_1
    x_max_2, y_max_2 = x_min_2 + width_2, y_min_2 + height_2
    area1, area2 = width_1 * height_1, width_2 * height_2
    x_min_max, x_max_min = max([x_min_1, x_min_2]), min([x_max_1, x_max_2])
    y_min_max, y_max_min = max([y_min_1, y_min_2]), min([y_max_1, y_max_2])
    if x_max_min <= x_min_max or y_max_min <= y_min_max:
        return 0
    else:
        intersect = (x_max_min-x_min_max) * (y_max_min-y_min_max)
        union = area1 + area2 - intersect
        return intersect / union