def _calculate_fill_sim(ri, rj, imsize):
    """
        Fill similarity measures how well ri and rj fit into each other.
        BBij is the bounding box around ri and rj.

        fill(ri, rj) = 1 − [size(BBij) − size(ri) − size(ri)] / size(image)
    """
    bbsize = (max(ri['box'][2], rj['box'][2]) - min(ri['box'][0], rj['box'][0])
        ) * (max(ri['box'][3], rj['box'][3]) - min(ri['box'][1], rj['box'][1]))
    return 1.0 - (bbsize - ri['size'] - rj['size']) / imsize
