get_marginals(): reduce indentation

This commit is contained in:
Robert Sachunsky 2026-04-27 00:02:03 +02:00
parent c18deb0722
commit 9571ce3474

View file

@ -58,9 +58,10 @@ def get_marginals(text_mask, early_layout, num_col, slope_deskew,
# plt.legend()
# plt.show()
if max_text_thickness_percent >= 14:
text_mask_d_y_rev = np.max(text_mask_d_y) - text_mask_d_y
if max_text_thickness_percent < 14:
return
text_mask_d_y_rev = np.max(text_mask_d_y) - text_mask_d_y
region_sum_0 = gaussian_filter1d(text_mask_d_y, 1)
first_nonzero = region_sum_0.nonzero()[0][0] # outer left
last_nonzero = region_sum_0.nonzero()[0][-1] # outer right
@ -81,9 +82,12 @@ def get_marginals(text_mask, early_layout, num_col, slope_deskew,
if num_col == 1:
peaks_right = peaks[peaks > mid_point]
peaks_left = peaks[peaks < mid_point]
if num_col == 2:
elif num_col == 2:
peaks_right = peaks[peaks > mid_point + one_third_right]
peaks_left = peaks[peaks < mid_point - one_third_left]
else:
# should not happen, anyway
return
if len(peaks_left) == 0:
if len(peaks_right) == 0:
@ -172,3 +176,6 @@ def get_marginals(text_mask, early_layout, num_col, slope_deskew,
# plt.imshow(early_layout)
# plt.show()
# if there was no main text, then relabel marginalia as main
if not np.any(early_layout == label_text):
early_layout[early_layout == label_marg] = label_text