get_marginals(): fix height factor for mask resizing

This commit is contained in:
Robert Sachunsky 2026-04-30 15:44:46 +02:00
parent a031d590b8
commit 287bebde0d

View file

@ -19,42 +19,40 @@ def get_marginals(text_mask, early_layout, num_col, slope_deskew,
main_mask_d = np.zeros_like(text_mask_d) main_mask_d = np.zeros_like(text_mask_d)
height, width = main_mask_d.shape height, width = main_mask_d.shape
text_mask_d_eroded = cv2.erode(text_mask_d, kernel, iterations=5)
if height <= 1500: if height <= 1500:
pass pass
elif 1500 < height <= 1800: elif 1500 < height <= 1800:
# rs: why not / 1.5??? text_mask_d = resize_image(text_mask_d, int(height / 1.5), width)
text_mask_d = resize_image(text_mask_d, int(height * 1.5), width)
text_mask_d = cv2.erode(text_mask_d, kernel, iterations=5) text_mask_d = cv2.erode(text_mask_d, kernel, iterations=5)
# rs: and back to original size # rs: and back to original size
text_mask_d = resize_image(text_mask_d, height, width) text_mask_d = resize_image(text_mask_d, height, width)
else: else:
# rs: why not / 1.8??? text_mask_d = resize_image(text_mask_d, int(height / 1.8), width)
text_mask_d = resize_image(text_mask_d, int(height * 1.8), width)
text_mask_d = cv2.erode(text_mask_d, kernel, iterations=7) text_mask_d = cv2.erode(text_mask_d, kernel, iterations=7)
# rs: and back to original size # rs: and back to original size
text_mask_d = resize_image(text_mask_d, height, width) text_mask_d = resize_image(text_mask_d, height, width)
text_mask_d = cv2.erode(text_mask_d, kernel_hor, iterations=6) text_mask_d = cv2.erode(text_mask_d, kernel_hor, iterations=6)
text_mask_d_y = text_mask_d.sum(axis=0) text_mask_d_y = text_mask_d.sum(axis=0)
text_mask_d_y_eroded = text_mask_d_eroded.sum(axis=0) text_mask_d_y_eroded = text_mask_d.sum(axis=0)
max_text_thickness_percent = 100. * text_mask_d_y_eroded.max() / height max_text_thickness_percent = 100. * text_mask_d_y.max() / height
min_text_thickness = max_text_thickness_percent / 100. * height / 20. min_text_thickness = max_text_thickness_percent / 100. * height / 20.
# plt.figure() # plt.figure()
# ax1 = plt.subplot(2, 1, 1, title="text_mask_d_eroded") # ax1 = plt.subplot(2, 2, 1, title="text_mask_d")
# ax1.imshow(text_mask_d_eroded, aspect='auto') # ax1.imshow(text_mask_d, aspect='auto')
# ax2 = plt.subplot(2, 1, 2, title="text_mask_d_y_eroded", sharex=ax1) # ax2 = plt.subplot(2, 2, 3, title="text_mask_d_y", sharex=ax1)
# ax2.plot(list(range(width)), text_mask_d_y_eroded) # ax2.plot(list(range(width)), text_mask_d_y)
# ax2.hlines(int(0.14 * height), 0, width, # ax2.hlines(int(0.14 * height), 0, width,
# label='max_text_thickness=14%', colors='r') # label='max_text_thickness=14%', colors='r')
# ax2.hlines([min_text_thickness], 0, width, # ax2.hlines([min_text_thickness], 0, width,
# label='min_text_thickness', colors='g') # label='min_text_thickness', colors='g')
# ax2.scatter([np.argmax(text_mask_d_y_eroded)], # ax2.scatter([np.argmax(text_mask_d_y)],
# [text_mask_d_y_eroded.max()], color='r', # [text_mask_d_y.max()], color='r',
# label='max = %d%%' % max_text_thickness_percent) # label='max = %d%%' % max_text_thickness_percent)
# ax1 = plt.subplot(2, 2, 4, title="early layout")
# ax1.imshow(early_layout, aspect='auto')
# plt.legend() # plt.legend()
# plt.show() # plt.show()