Automatic page splitting
This commit is contained in:
1 parent
d4404e4c27
commit
78f3e4b2f0
13 files changed
+1959
-40
No files matched your search
@@ -93,7 +93,6 @@ def ruling_suppression(rgb: np.ndarray, dpi: float):
|
||||
matrix[:,2] -= origin
|
||||
image = cv2.warpAffine(rgb, matrix, tuple(size), borderValue=(255,255,255))
|
||||
dark = 255-image
|
||||
dark16 = dark.astype(np.int16)
|
||||
darkness = _maximum(dark)
|
||||
binary = cv2.adaptiveThreshold(_minimum(image), 255,
|
||||
cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV,
|
||||
@@ -119,7 +118,7 @@ def ruling_suppression(rgb: np.ndarray, dpi: float):
|
||||
support = _maximum(model) > 9
|
||||
if count:
|
||||
support &= bands > 0
|
||||
close = _maximum(np.abs(dark16-model.astype(np.int16))) < 40
|
||||
close = _maximum(cv2.absdiff(dark,model)) < 40
|
||||
sample = support & (darkness > 9) & close & ~thick
|
||||
# Neutral, red, green and blue line families are modelled separately so
|
||||
# a red margin rule cannot be mistaken for unusually dark blue writing.
|
||||
@@ -128,7 +127,10 @@ def ruling_suppression(rgb: np.ndarray, dpi: float):
|
||||
classes[second <= third] = 1
|
||||
classes[(first <= second) & (first <= third)] = 0
|
||||
classes[cv2.subtract(_maximum(model),_minimum(model)) < 25] = 3
|
||||
credible = np.zeros(binary.shape, bool)
|
||||
# Rejected classes have ceiling -1, below every uint8 darkness value.
|
||||
# Compute each class ceiling once, then test pixels by lookup instead
|
||||
# of subtracting and splitting full RGB images for every colour class.
|
||||
ceilings = np.full((4,3),-1,np.int16)
|
||||
for colour in range(4):
|
||||
selected = sample & (classes == colour)
|
||||
if selected.sum() < 100:
|
||||
@@ -143,9 +145,10 @@ def ruling_suppression(rgb: np.ndarray, dpi: float):
|
||||
# An isolated long fraction bar must not define its own paper colour.
|
||||
# The upper quantile admits darker major rules within an established
|
||||
# family while rejecting excess ink on most of its pixels.
|
||||
ceiling = np.floor(np.quantile(dark[selected],.99,axis=0)+25).astype(np.int16)
|
||||
credible |= ((classes == colour)
|
||||
& (_maximum(dark16-ceiling) <= 0))
|
||||
ceilings[colour] = np.floor(np.quantile(dark[selected],.99,axis=0)+25).astype(np.int16)
|
||||
credible = ((dark[:,:,0] <= ceilings[classes,0])
|
||||
& (dark[:,:,1] <= ceilings[classes,1])
|
||||
& (dark[:,:,2] <= ceilings[classes,2]))
|
||||
match = close & credible & (darkness > 9) & ~thick
|
||||
removed |= support & match
|
||||
protected |= support & ~match & (binary > 0)
|
||||
|
||||
Reference in new issue
Block a user