def get_bboxes(<EOL>img,<EOL>mask,<EOL>nb_boxes=<NUM_LIT:100>,<EOL>score_thresh=<NUM_LIT:0.5>,<EOL>iou_thresh=<NUM_LIT>,<EOL>prop_size=<NUM_LIT>,<EOL>prop_scale=<NUM_LIT>,<EOL>):
min_size = int(img.shape[<NUM_LIT:0>] * prop_size * img.shape[<NUM_LIT:1>] * prop_size)<EOL>scale = int(img.shape[<NUM_LIT:0>] * prop_scale)<EOL>img_lbl, regions = selectivesearch.selective_search(<EOL>img, scale=scale, sigma=<NUM_LIT>, min_size=min_size<EOL>)<EOL>rect = [None] * nb_boxes<EOL>max_iou = -<NUM_LIT:1> * np.ones(nb_boxes)<EOL>mask = <NUM_LIT:1.0> * (mask > score_thresh)<EOL>for region in regions:<EOL><INDENT>left, top, width, height = region["<STR_LIT>"]<EOL>intersection = mask[top : top + height, left : left + width].sum()<EOL>union = height * width + mask.sum() - intersection<EOL>iou = intersection / union<EOL>idx = np.argmin(max_iou)<EOL>if iou > max_iou[idx]:<EOL><INDENT>max_iou[idx] = iou<EOL>rect[idx] = region["<STR_LIT>"]<EOL><DEDENT><DEDENT>remove_indexes = max_iou == -<NUM_LIT:1><EOL>bboxes = []<EOL>filtered_ious = []<EOL>for idx in np.argsort([-x for x in max_iou]):<EOL><INDENT>if remove_indexes[idx]:<EOL><INDENT>break<EOL><DEDENT>if len(bboxes) == <NUM_LIT:0>:<EOL><INDENT>if max_iou[idx] > iou_thresh:<EOL><INDENT>bboxes += [rect[idx]]<EOL>filtered_ious += [max_iou[idx]]<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if not any(<EOL>[do_intersect(rect[idx], bboxes[k]) for k in range(len(bboxes))]<EOL>):<EOL><INDENT>if max_iou[idx] > iou_thresh:<EOL><INDENT>bboxes += [rect[idx]]<EOL>filtered_ious += [max_iou[idx]]<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return bboxes, filtered_ious<EOL>
Uses selective search to generate candidate bounding boxes and keeps the
ones that have the largest iou with the predicted mask.

:param img: original image
:param mask: predicted mask
:param nb_boxes: max number of candidate bounding boxes
:param score_thresh: scre threshold to consider prediction is True
:param iou_thresh: iou threshold to consider a candidate is a correct region
:param prop_size: selective search parameter
:param prop_scale: selective search parameter, larger prop_scale favorizes
    large boudning boxes
:return: list of bounding boxes and ious, boudning boxes are tuples (left,
    top, width, height)