Propose black and white points from the scan
Levels shipped at 0–255 unless someone moved the sliders, and Bicycle Race showed what that costs. Its ink is grey, not black — a scanned engraving, ink at 2–95, paper at 163–255 — and with alpha = 255 − luminance that greyness becomes transparency. No pixel in the exported bundle was even fully opaque, and the downscale to the song's width blended every stroke edge further. Nothing downstream can rescue it. So detection proposes levels too, like it proposes cuts and skew. Notation is two-tone, which makes Otsu's split the measurement wanted; the points sit halfway from it to each end of the range, so the ramp between them survives as antialiasing rather than going jagged. A page already scanned bilevel has no interior split — Otsu degenerates to 0 — and is left alone. Per page, with the median becoming the song's, so a near-blank page cannot set them.
This commit is contained in:
+15
-1
@@ -14,7 +14,12 @@ import numpy as np
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from noteman_slicer.detect import deskew, deskew_angle, detect_page # noqa: E402
|
||||
from noteman_slicer.detect import ( # noqa: E402
|
||||
deskew,
|
||||
deskew_angle,
|
||||
detect_page,
|
||||
ink_levels,
|
||||
)
|
||||
|
||||
W, H = 1000, 1400
|
||||
STAFF_GAP = 15 # → staff height 60, so expansion reaches 90px past a bracket
|
||||
@@ -71,6 +76,15 @@ def main() -> int:
|
||||
found = deskew_angle(deskew(page, angle))
|
||||
assert abs(found + angle) <= 0.15, f"skew {angle}: got {found}"
|
||||
|
||||
# Levels are proposed too. A grey scan left at 0–255 ships its wash to the
|
||||
# tablet, and the downscale to the song's width only blends it further.
|
||||
grey = np.full((H, W), 210, np.uint8) # paper, not white
|
||||
grey[200:400, 100:900] = 70 # ink, not black
|
||||
black, white = ink_levels(grey)
|
||||
assert black < 70 < white < 210, (black, white)
|
||||
# A page already bilevel has nothing between ink and paper to stretch.
|
||||
assert ink_levels(_page()) == (0, 255)
|
||||
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user