Skip to content

fix: a small bright change in a tile is not lost in the tile average - #69

Open
bluzername wants to merge 1 commit into
awlevin:mainfrom
bluzername:fix-tile-small-bright-change
Open

bluzername wants to merge 1 commit into
awlevin:mainfrom
bluzername:fix-tile-small-bright-change

Conversation

@bluzername

Copy link
Copy Markdown

Fixes part of #58 (bug 4, "The OCR cache misses one new digit").

tile_changed only compared the mean pixel difference of a tile on the 1/8 thumbnail. A new digit on a display is a handful of pixels inside a 256 px tile, so even a sharp black-to-white change moves the tile's mean by well under TILE_DIFF (6.0). The tile read as unchanged, and the OCR cache kept its old reading of that region for the rest of the run - this is what hid the Calculator display's first digits in #58.

Fix: a tile also counts as changed when one thumbnail pixel moved by more than a new TILE_PEAK_DIFF (32). Uniform noise moves every pixel a little and none by much, so it still reads as no change (see the existing test_faint_noise_does_not_count_as_a_change); a small sharp patch does not.

I re-derived this independently from the bug report rather than taking the diff there as-is; the shape ended up close to it, but the threshold name, value, and test are my own.

Test: added test_a_small_bright_change_is_not_lost_in_the_tile_average to tests/test_ocr_cache.py - paints a 12x12 patch in one 256 px tile (measured mean diff ~0.5, peak diff ~225). It fails on main (changed_tiles returns no tiles) and passes with this fix.

Ran before opening:

uv run ruff check . && uv run ruff format --check .
uv run pytest -q

731 passed, 2 skipped, 1 xfailed (one more pass than main's 730, the new test).

🤖 Generated with Claude Code

tile_changed only looked at the tile's mean pixel difference. A new
digit on a display is a handful of pixels inside a 256 px tile: on the
1/8 thumbnail the patch is tiny, so even a sharp black-to-white change
moves the tile's mean by well under TILE_DIFF (6.0), and the tile read
as unchanged. The OCR cache then kept its old reading of that region for
the rest of the run.

Now a tile also counts as changed when one thumbnail pixel moved by more
than TILE_PEAK_DIFF (32). Uniform noise moves every pixel a little and
none by much, so it still reads as no change; a small sharp patch does
not.

Added a test that paints a 12x12 patch in one tile (mean diff ~0.5,
peak diff ~225): it failed before this fix (changed_tiles returned no
tiles) and passes now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant