From a031d590b8426fcff1da09949a19d07e7431a545 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Thu, 30 Apr 2026 15:32:15 +0200 Subject: [PATCH] =?UTF-8?q?get=5Fmarginals():=20do=20allow=20both=20left?= =?UTF-8?q?=20and=20right=20point=20(f/u=204bdea39)=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (as there are valid cases where both left and right marginalia is present) follow-up 4bdea39 by re-allowing left point _and_ right point - but still score-based, and not if very asymmetric --- src/eynollah/utils/marginals.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/eynollah/utils/marginals.py b/src/eynollah/utils/marginals.py index 3ffcaa9..6e0fcdb 100644 --- a/src/eynollah/utils/marginals.py +++ b/src/eynollah/utils/marginals.py @@ -113,14 +113,17 @@ def get_marginals(text_mask, early_layout, num_col, slope_deskew, point_left = peaks_left[np.argmax(scores[peaks_left])] #point_right = last_nonzero point_right = width - 1 - elif scores[peaks_left].max() < scores[peaks_right].max(): - point_right = peaks_right[np.argmax(scores[peaks_right])] - #point_left = first_nonzero - point_left = 0 else: - point_left = peaks_left[np.argmax(scores[peaks_left])] - #point_right = last_nonzero - point_right = 0 + best_left = np.argmax(scores[peaks_left]) + best_right = np.argmax(scores[peaks_right]) + point_left = peaks_left[best_left] + point_right = peaks_right[best_right] + if scores[best_left] < 0.1 * scores[best_right]: + point_left = 0 + #point_left = first_nonzero + if scores[best_right] < 0.1 * scores[best_left]: + point_right = 0 + #point_right = last_nonzero main_mask_d[:, point_left: point_right] = 1 if not np.any(main_mask_d):