Esempio n. 1
0
def evaluate_textboxes(gt_boxes, boxes):
    """
    Evaluates the mean intersection-over-union between GT textboxes and the given ones.
    
    Parameters
    ----------
    gt_boxes : list of textboxes for each image, as described in W2 slides
    boxes : list of textboxes for each image, as described in W2 slides
    
    Returns
    -------
    mean_iou: mean intersection-over-union
    """
    assert len(gt_boxes) == len(boxes)

    iou = 0
    # compute IOU per image
    for i in range(len(boxes)):
        if len(boxes[i]) == 0 or len(gt_boxes[i]) == 0:
            continue

        max_dim = np.max(np.max(boxes[i]))
        shape = (max_dim, max_dim)
        # We compute the IOU by generating both masks with all given textboxes highlighted.
        gt_mask, mask = generate_text_mask(shape,
                                           gt_boxes[i]), generate_text_mask(
                                               shape, boxes[i])
        iou += compute_iou(gt_mask, mask)
    return iou / len(boxes)
Esempio n. 2
0
def _extract_image_and_mask_from_path(img_path, mask_path, textboxes, multiple):
    img = path2img(img_path)
    if mask_path is None:
        text_mask = 1 - generate_text_mask(img.shape[:2], textboxes) # returns all 1's if textboxes == None
        return [(img, text_mask), ]

    mask = path2mask(mask_path)
    text_mask = 1 - generate_text_mask(mask.shape, textboxes)
    if multiple:
        masks = extract_paintings_from_mask(mask)
        if masks is None or len(masks) == 0:
            return [(img, np.ones(img.shape[:2]).astype(np.uint8)), ]
        return [(img, ((text_mask != 0) & (m != 0)).astype(np.uint8)) for m in masks]
    return [(img, ((text_mask != 0) & (mask != 0)).astype(np.uint8)), ]
Esempio n. 3
0
 def _extract_features_from_path(_path, textboxes):
     img = path2img(_path)
     text_mask = 1 - generate_text_mask(
         img.shape[:2], textboxes)  # returns all 1's if textboxes == None
     return [
         extract_features_func(img, mask=text_mask),
     ]
Esempio n. 4
0
 def _extract_features_from_path_mask(_path, _path_mask, textboxes):
     img, mask = path2img(_path), path2mask(_path_mask)
     text_mask = 1 - generate_text_mask(mask.shape, textboxes)
     if multiple:
         masks = extract_paintings_from_mask(mask)
         #print(f"{_path_mask} - {len(masks)}")
         return [
             extract_features_func(img,
                                   mask=((text_mask != 0) &
                                         (m != 0)).astype(np.uint8))
             for m in masks
         ]
     return [
         extract_features_func(img,
                               mask=((text_mask != 0) & (mask != 0)).astype(
                                   np.uint8)),
     ]