Skip to content

Commit

Permalink
Filter out mask segments with larger area than textline
Browse files Browse the repository at this point in the history
  • Loading branch information
thatDudo committed Nov 20, 2023
1 parent 0d2cb7b commit 18a5329
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions manga_translator/mask_refinement/text_mask_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,25 @@ def complete_mask(img: np.ndarray, mask: np.ndarray, textlines: List[Quadrilater
# print(textlines[tl_idx].pts, cc_pts, '->', overlapping_area, min(area1, area2), '=', overlapping_area / min(area1, area2), '|', polys[tl_idx].distance(cc_poly))

avg = np.argmax(ratio_mat[label])
# print('overlap:', ratio_mat[label, avg],'<=', keep_threshold)
# print('overlap:', ratio_mat[label, avg], '<=', keep_threshold)
area2 = polys[avg].area
if area1 >= area2:
continue
if ratio_mat[label, avg] <= keep_threshold:
avg = np.argmin(dist_mat[label])
area2 = polys[avg].area
unit = min([textlines[avg].font_size, w1, h1])
# if area1 < 0.4 * w1 * h1:
# # ccs is probably angled
# unit /= 2
# if avg == 9:
# if avg == 0:
# print('no intersect', area1, '>=', area2, dist_mat[label, avg], '>=', 0.5 * unit)
if area1 >= area2 or dist_mat[label, avg] >= 0.5 * unit:
if dist_mat[label, avg] >= 0.5 * unit:
continue

textline_ccs[avg][y1:y1+h1, x1:x1+w1][labels[y1:y1+h1, x1:x1+w1] == label] = 255
# if avg == 9:
# # print(avg)
# if avg == 0:
# print(avg)
# cv2.imshow('ccs', image_resize(textline_ccs[avg], height = 800))
# cv2.waitKey(0)
textline_rects[avg, 0] = min(textline_rects[avg, 0], x1)
Expand Down

0 comments on commit 18a5329

Please sign in to comment.