Stop an edge artefact and a speck filter from destroying a song
Olukainen juomukainen came out unusable, from two separate faults. The scanner left a dark line down the sheet edge, running the full height of every page but the first. Being taller than any bracket it won every overlap in anchor selection and swallowed the page into one system, so five pages of six proposed no cuts at all. A page's brackets and barlines are all about one system tall, so a stroke far taller than the typical one is not notation — relative to the page's own strokes, since a page holding one big system is legitimate. The trim then removed each system's bottom line of lyrics. It judged ink blobs by area, and a letter is nowhere near the threshold; a whole line of them is dozens of blobs, none of which qualifies. Measure ink per row and per column instead — a line of text carries plenty in total, and a fleck's row carries almost none, which is the case the filter was for. Detection now finds three systems on every page of that score, and every slice keeps all four voices' words.
This commit is contained in:
@@ -26,6 +26,7 @@ _SKEW_WORK_SCALE = 0.25
|
||||
_INK = 128 # below this is ink, above is paper
|
||||
_ANCHOR_KERNEL = 0.03 # vertical open kernel, as a fraction of page height
|
||||
_ANCHOR_MIN = 0.04 # a bracket is at least this tall, as a fraction of page
|
||||
_ANCHOR_MAX_RATIO = 2.0 # a stroke this much taller than the typical one is an artefact
|
||||
_PROFILE_FLOOR = 0.02 # ink-run threshold, as a fraction of the profile peak
|
||||
_EXPAND_REACH = 1.5 # how far past the bracket a system's ink reaches, in staff heights
|
||||
_STAFF_KERNEL = 0.05 # horizontal open kernel, as a fraction of page width
|
||||
@@ -123,6 +124,17 @@ def system_anchors(gray: np.ndarray) -> list[Anchor]:
|
||||
if stats[i, cv2.CC_STAT_HEIGHT] > h * _ANCHOR_MIN
|
||||
]
|
||||
|
||||
# A scanner leaves a dark line down the sheet edge — the binder shadow, the
|
||||
# glass, the page next to it — and it runs the whole height of the scan.
|
||||
# Being the tallest stroke on the page it wins every overlap below and
|
||||
# swallows every system into one. A page's brackets and barlines are all
|
||||
# about one system tall, so anything wildly taller than the typical stroke
|
||||
# is not notation. Relative, not an absolute fraction of the page: a page
|
||||
# holding one big system is legitimate and must survive.
|
||||
if len(tall) > 1:
|
||||
limit = float(np.median([a.bottom - a.top for a in tall])) * _ANCHOR_MAX_RATIO
|
||||
tall = [a for a in tall if a.bottom - a.top <= limit] or tall
|
||||
|
||||
# Tallest first, keeping only strokes that don't overlap one already kept:
|
||||
# a system's barlines all overlap its bracket, so each system yields one.
|
||||
# The kept stroke is the tallest, which is the bracket rather than a barline.
|
||||
|
||||
Reference in New Issue
Block a user