Line.baseline: fix detecting baselines at image boundaries.

This commit is contained in:
Andrey Golovizin 2014-08-25 15:30:10 +02:00
parent 6d2a6b325b
commit 4f621493e5

View file

@ -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