Skip to content

[#71] perf: ~2x faster coverage quant (byte-identical) + lossy-input denoise (pigeon 17→12 colours)#72

Merged
realproject7 merged 1 commit into
mainfrom
task/perf-tier2-and-denoise
Jun 24, 2026
Merged

[#71] perf: ~2x faster coverage quant (byte-identical) + lossy-input denoise (pigeon 17→12 colours)#72
realproject7 merged 1 commit into
mainfrom
task/perf-tier2-and-denoise

Conversation

@realproject7

Copy link
Copy Markdown
Owner

Two optimizations for the Tier 2 coverage engine. Both leave clean (PNG) output byte-identical to 0.4.0 (verified by md5 on logo/gradient/flat).

Perf — ~2× faster coverage quantization, output unchanged

The LAB-bin histogram used np.unique(..., axis=0), whose lexsort dominated runtime on large inputs. Encode each (L,a,b) bin into one integer key (L highest-order; a/b offset into range) and dedup with a 1-D np.unique. The key is monotonic in (L,a,b), so bins/inverse/counts are bit-for-bit identical to the lexsort.

image 0.4.0 0.4.1 output
17-gradient (1024×1536) 4.4s 2.4s identical
12-sticker 2.6s 1.1s identical
16-gradient 2.2s 1.1s identical
pigeon 1.4s 1.0s identical

Denoise (#71) — cut lossy-input palette inflation

On lossy (JPEG/MPO) sources, compression noise inflates the CIELAB volume so coverage emits near-duplicate colours (pigeon 17 vs the reference's ~10). A stronger flatten paradoxically inflates the palette further (measured), so for lossy inputs the coverage path swaps its default bilateral-flatten for a lighter edge-preserving bilateral (sigma_color=0.02):

  • pigeon 17 → 12 colours, outlines stay continuous, SSIM unchanged (0.896 → 0.895), bytes smaller. The JPEG-noise beak artifact is removed.
  • Gated strictly to lossy sources — clean PNG/flat inputs never enter it and are byte-identical (the source format is re-attached after load_image's convert() drops it).
  • coverage_denoise_lossy=False is the safe-revert.

Note: the denoise bake-off initially favoured an additive bilateral pre-filter, but end-to-end testing showed that is redundant with the existing flatten (no effect in the real pipeline); the working fix is to replace flatten with the lighter bilateral for lossy inputs only.

Verification

  • Regression test asserts the gate is load-bearing (clean PNG identical with the option on vs off) + _is_lossy_source classification.
  • Full suite green; ruff clean. Comparison render: z-design/.../test-v0.4.0/denoise-proto/pigeon_final_0.4.1.png.

Version 0.4.0 → 0.4.1. Closes #71.

…nflation

Two optimizations for the Tier 2 coverage engine, both verified to leave clean
(PNG) output byte-identical to 0.4.0.

PERF — perceptual-coverage quantization built its LAB-bin histogram with
np.unique(..., axis=0), whose lexsort dominated runtime on large inputs. Encode
each (L,a,b) bin into one integer key (L highest-order, a/b offset into range) and
dedup with a 1-D np.unique. The key is monotonic in (L,a,b) so bins/inverse/counts
are bit-for-bit identical to the lexsort — output is unchanged, ~2x faster
(17-gradient 4.4s -> 2.4s, 12-sticker 2.6s -> 1.1s; all corpus images byte-identical).

DENOISE (#71) — on lossy (JPEG/MPO) sources, compression noise inflates the CIELAB
volume so coverage emits near-duplicate colours (pigeon 17 vs the reference's ~10).
A *stronger* flatten paradoxically inflates the palette further, so for lossy inputs
the coverage path swaps its default bilateral-flatten for a lighter, edge-preserving
bilateral pre-filter (sigma_color 0.02): pigeon 17 -> 12 colours, outlines stay
continuous, SSIM unchanged (0.896 -> 0.895), bytes smaller. Gated strictly to lossy
sources — clean PNG/flat inputs never enter it and are byte-identical (verified by
md5 on logo/gradient/flat). The source format is re-attached after load_image's
convert() drops it. coverage_denoise_lossy=False is the safe-revert.

Regression test asserts the gate is load-bearing (clean PNG identical with the
option on vs off) and _is_lossy_source classification. Full suite green; ruff clean.
Version 0.4.0 -> 0.4.1.

Closes #71.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@realproject7 realproject7 merged commit 405819f into main Jun 24, 2026
4 checks passed
@realproject7 realproject7 deleted the task/perf-tier2-and-denoise branch June 24, 2026 05:53
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.

[quality] Edge-preserving pre-quant denoise for lossy inputs (coverage palette count)

1 participant