yashlamba / yashlamba/handwrite

Bug: pngToBmp threshold checks alpha instead of blue channel (pngtosvg.py:73)

Open Beginner friendly
#92 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Feed a scan with any transparency, e.g. pixel (255, 255, 255, 0) (transparent white background).
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.