Use morphological closing along the x-axis to enhance baseline detection.
This commit is contained in:
parent
cb25753a75
commit
8bc5f06772
1 changed files with 2 additions and 1 deletions
|
|
@ -19,7 +19,7 @@ from collections import defaultdict
|
|||
|
||||
import numpy as np
|
||||
from scipy import ndimage
|
||||
from scipy.ndimage import filters
|
||||
from scipy.ndimage import filters, grey_closing
|
||||
|
||||
from .utils import cached_property, collect_iterable, pairwise, neighbourhood
|
||||
from .image import Image, combine, is_nonblank
|
||||
|
|
@ -158,6 +158,7 @@ class Line(PageObject):
|
|||
def baseline(self):
|
||||
"""Detect baseline height, relative to the top."""
|
||||
bitmap = self.image.bitmap
|
||||
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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue