From 4f621493e5a46ca4ecbe997cb09d1de7d7d95db4 Mon Sep 17 00:00:00 2001 From: Andrey Golovizin Date: Mon, 25 Aug 2014 15:30:10 +0200 Subject: [PATCH] Line.baseline: fix detecting baselines at image boundaries. --- pixelocr/page.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pixelocr/page.py b/pixelocr/page.py index 6064fe1..fbf2cb5 100644 --- a/pixelocr/page.py +++ b/pixelocr/page.py @@ -101,9 +101,11 @@ class Line(PageObject): """Detect baseline height, relative to the top.""" bitmap = self.image.bitmap.astype(np.float) histogram = bitmap.sum(axis=1) - gradient = filters.correlate1d(histogram, [-1, 1], axis=0) + gradient = list(filters.correlate1d(histogram, [-1, 1], axis=0, mode='constant')) + gradient[0] = histogram[0] + gradient.append(-histogram[-1]) # top = gradient.argmax() - bottom = gradient.argmin() + bottom = np.argmin(gradient) return self.y + bottom @property