Line.baseline: fix detecting baselines at image boundaries.
This commit is contained in:
parent
6d2a6b325b
commit
4f621493e5
1 changed files with 4 additions and 2 deletions
|
|
@ -101,9 +101,11 @@ class Line(PageObject):
|
||||||
"""Detect baseline height, relative to the top."""
|
"""Detect baseline height, relative to the top."""
|
||||||
bitmap = self.image.bitmap.astype(np.float)
|
bitmap = self.image.bitmap.astype(np.float)
|
||||||
histogram = bitmap.sum(axis=1)
|
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()
|
# top = gradient.argmax()
|
||||||
bottom = gradient.argmin()
|
bottom = np.argmin(gradient)
|
||||||
return self.y + bottom
|
return self.y + bottom
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue