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:
@@ -71,6 +71,14 @@ def main() -> int:
|
||||
found = deskew_angle(deskew(page, angle))
|
||||
assert abs(found + angle) <= 0.15, f"skew {angle}: got {found}"
|
||||
|
||||
# A scanner's edge line runs the whole height of the sheet. Being taller
|
||||
# than every bracket it used to win each overlap and swallow the page into
|
||||
# one system — Olukainen juomukainen, where five pages of six came out as a
|
||||
# single slice each.
|
||||
scanned = _page()
|
||||
scanned[10 : H - 10, W - 8 : W - 4] = 0
|
||||
assert len(detect_page(scanned).systems) == 2, "an edge artefact is not a bracket"
|
||||
|
||||
# No brackets: every ink run is its own system.
|
||||
bare = np.full((H, W), 255, np.uint8)
|
||||
for y in (200, 500, 800):
|
||||
|
||||
@@ -19,6 +19,7 @@ from noteman_slicer.pdf import open_source, page_raster # noqa: E402
|
||||
from noteman_slicer.project import Cut, Project, default_path # noqa: E402
|
||||
from noteman_slicer.render import ( # noqa: E402
|
||||
ALPHA_LEVELS,
|
||||
_ink_bbox,
|
||||
apply_levels,
|
||||
encode,
|
||||
pad_right,
|
||||
@@ -87,6 +88,19 @@ def main() -> int:
|
||||
assert rgba[:, :, 3].min() == 0, "paper must be fully transparent"
|
||||
assert len(np.unique(rgba[:, :, 3])) <= ALPHA_LEVELS
|
||||
|
||||
# Trim keeps a line of lyrics and drops a fleck. Each letter is its own
|
||||
# small blob, so judging blobs by area threw the whole line away and the
|
||||
# bottom voice lost its words; a fleck's row carries almost no ink at all.
|
||||
art = np.full((300, 800), 255, np.uint8)
|
||||
art[100:150, 50:750] = 0 # a staff
|
||||
for x in range(60, 700, 30): # lyrics: many small glyphs, one row
|
||||
art[200:220, x : x + 14] = 0
|
||||
art[5:9, 10:14] = 0 # a fleck in the far corner
|
||||
x0, y0, x1, y1 = _ink_bbox(art)
|
||||
assert (y0, y1) == (100, 220), f"lyrics kept, fleck dropped: {(y0, y1)}"
|
||||
assert (x0, x1) == (50, 750), (x0, x1)
|
||||
assert _ink_bbox(np.full((50, 50), 255, np.uint8)) is None, "blank slice has no box"
|
||||
|
||||
# Levels: a white point below the paper value wipes the paper out entirely.
|
||||
faint = np.full((10, 10), 200, np.uint8)
|
||||
assert apply_levels(faint, 0, 180).max() == 255
|
||||
|
||||
Reference in New Issue
Block a user