Tweak baseline detection: look for baselines only in the bottom half of the line.
This commit is contained in:
parent
8b95460f10
commit
ef6369f10e
1 changed files with 3 additions and 2 deletions
|
|
@ -159,14 +159,15 @@ class Line(PageObject):
|
||||||
@cached_property
|
@cached_property
|
||||||
def baseline(self):
|
def baseline(self):
|
||||||
"""Detect baseline height, relative to the top."""
|
"""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')
|
bitmap = grey_closing(bitmap, (0, 10), mode='constant')
|
||||||
histogram = bitmap.sum(axis=1)
|
histogram = bitmap.sum(axis=1)
|
||||||
gradient = list(filters.correlate1d(histogram, [-1, 1], axis=0, mode='constant'))
|
gradient = list(filters.correlate1d(histogram, [-1, 1], axis=0, mode='constant'))
|
||||||
gradient[0] = histogram[0]
|
gradient[0] = histogram[0]
|
||||||
gradient.append(-histogram[-1])
|
gradient.append(-histogram[-1])
|
||||||
# top = gradient.argmax()
|
# top = gradient.argmax()
|
||||||
bottom = np.argmin(gradient)
|
bottom = np.argmin(gradient) + skip
|
||||||
return self.y + bottom
|
return self.y + bottom
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue