Tweak baseline detection: look for baselines only in the bottom half of the line.

This commit is contained in:
Andrey Golovizin 2014-08-26 22:53:53 +02:00
parent 8b95460f10
commit ef6369f10e

View file

@ -159,14 +159,15 @@ class Line(PageObject):
@cached_property
def baseline(self):
"""Detect baseline height, relative to the top."""
bitmap = self.image.bitmap
skip = self.height // 2
bitmap = self.image.bitmap[skip:, :]
bitmap = grey_closing(bitmap, (0, 10), mode='constant')
histogram = bitmap.sum(axis=1)
gradient = list(filters.correlate1d(histogram, [-1, 1], axis=0, mode='constant'))
gradient[0] = histogram[0]
gradient.append(-histogram[-1])
# top = gradient.argmax()
bottom = np.argmin(gradient)
bottom = np.argmin(gradient) + skip
return self.y + bottom
@property