yashlamba / yashlamba/handwrite
Bug: pngToBmp threshold checks alpha instead of blue channel (pngtosvg.py:73)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 543
- Forks
- 52
- PR merge metrics
- No merged PRs in 30d
Description
Problem
pngToBmp converts to RGBA then thresholds on channels [0], [1], [3] — that's R, G, Alpha. Blue channel pix[2] is skipped and alpha is (incorrectly) treated as a color.
Cite
handwrite/pngtosvg.py line 73 (branch dev):
img = Image.open(path).convert("RGBA").resize((100, 100))
...
if pix[0] >= threshold and pix[1] >= threshold and pix[3] >= threshold:
data.append((255, 255, 255, 0))
else:
data.append((0, 0, 0, 1))
Steps
- Feed a scan with any transparency, e.g. pixel
(255, 255, 255, 0)(transparent white background). - Run
handwrite sheet.png out/.
Expected
Transparent/white background stays background (white).
Actual
Alpha=0 fails pix[3] >= 200, so the pixel is classified as ink (0, 0, 0, 1). Background gets vectorized as glyph fill.
Secondary failure: bright but low-blue pixels (e.g. yellow pen (255, 255, 0, 255)) pass the check and are dropped as background even though they carry stroke.
Fix: replace pix[3] with pix[2] (check B, not A).
Environment
From setup.py: handwrite==0.3.1, Pillow (unpinned), Python >=3.7. dev branch HEAD.
Thanks for maintaining yashlamba/handwrite!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open handwrite/pngtosvg.py at line 73 and inspect the RGBA threshold used by pngToBmp. Run handwrite sheet.png out/ with transparent and colored sample pixels, then verify that the blue channel is checked and transparent or white backgrounds remain background rather than becoming ink.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, computer-vision
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100