def calculate_iou(proposals, label):
    """
    Calculate the intersection over union between bounding boxes of selective search and labels
    This code is adapted from https://gist.github.com/meyerjo/dd3533edc97c81258898f60d8978eddc

    :param proposals: A region proposal bounding box
    :param label: Bounding box of label
    """
    # determine the (x, y)-coordinates of the intersection rectangle
    xA = max(proposals[0], label[0])
    yA = max(proposals[1], label[1])
    xB = min(proposals[2], label[2])
    yB = min(proposals[3], label[3])

    # compute the area of intersection rectangle
    interArea = abs(max((xB - xA, 0)) * max((yB - yA), 0))

    proposalsArea = abs((proposals[2] - proposals[0]) * (proposals[3] - proposals[1]))
    labelArea = abs((label[2] - label[0]) * (label[3] - label[1]))
    unionArea = proposalsArea + labelArea - interArea

    iou = interArea / float(unionArea)

    return iou