[#74] Economical-fidelity color default + painterly-grain detail level + postprocess perf#75
Merged
Merged
Conversation
…l + postprocess perf Detail-aware region merge: a small region merges into its nearest neighbour only when that neighbour is within a ΔE76 threshold (anti-alias / compression noise); a distinct-colour mark farther than it (a dot/stipple/texture drawn on purpose) is KEPT. Collapses noise for economy/speed while preserving designer-detail. - preprocess: _merge_small_regions(noise_de) + quantize_coverage(region_noise_de=) + PreprocessOptions.coverage_region_noise_de (default 0.0 = legacy, backward compat) - pipeline: coverage operating point becomes the faithful-economical default; COVERAGE_NOISE_DE maps the --detail dial to the threshold. --detail high disables flatten + raises the coverage path cap so painterly brush-grain survives. - postprocess: _consolidate short-circuits to identity when palette_threshold <= 0 (coverage path = a no-op) and lru_cache on RGB->LAB; a grain-rich convert drops ~110s -> ~12s with byte-identical output. Default color output now keeps deliberate detail and is economical (≈ reference-target bytes vs the old 8-13x); flat/simple art unchanged (corpus goldens byte-identical). Tests added for the noise_de gate, the detail->threshold ordering, and the threshold<=0 identity. Version 0.4.2 -> 0.5.0. Fixes #74 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #74. Version 0.4.2 → 0.5.0.
What
Makes the default color engine produce faithful yet economical SVGs — keeping the deliberate detail an artist drew (dots, stipple, fine texture) while collapsing only anti-alias/compression fringes — and adds an on-demand max-grain mode for painterly art. Plus a large postprocess speedup that benefits every colour-rich output.
1. Detail-aware region merge (economical fidelity)
In the coverage path a small region merges into its nearest neighbour only when that neighbour is within a ΔE76 threshold (anti-alias / compression noise); a distinct-colour mark farther than it (a dot/stipple/texture drawn on purpose) is kept. One lever delivers both economy and fidelity — no separate node-reduction pass, stipple gate, or complexity estimator.
preprocess._merge_small_regions(noise_de)+quantize_coverage(region_noise_de=)+PreprocessOptions.coverage_region_noise_de(default0.0= legacy merge-everything; fully backward compatible — all other callers/tests unaffected).pipelinecoverage operating point becomes the validated faithful-economical default;COVERAGE_NOISE_DEmaps the existing--detaildial to the threshold.2.
--detail high= painterly brush-grainAt
--detail highthe coverage path disables the pre-trace flatten and raises its path cap (_COVERAGE_MAX_PATHS_HIGH) so grain-rich output is kept rather than discarded to the baseline path. Lets textured art reach the reference target's grain density on demand (fidelity over economy). A misgated photo still explodes past the high cap and safely falls back.3. Postprocess perf (every colour-rich output)
_consolidateran an O(n²) pairwise ΔE scan and recomputed RGB→LAB on every comparison (~30 M calls / ~99 s on a grain-rich trace). Now: short-circuit to identity whenpalette_threshold <= 0(the coverage path, where consolidation is a guaranteed no-op) +lru_cacheon RGB→LAB. A max-fidelity textured convert: ~110 s → ~12 s, byte-identical output.Results (vs reference target, 21-image illustration set)
--detail high: full grain density (≈ reference) in ~12 s.Safety / no-regression
normal) color output byte-identical where unchanged — corpus goldens green.test_version_is_single_sourced(editable-metadata artifact; passes in CI).ruff check src testsclean.test_merge_small_regions_noise_de_keeps_distinct_marks,test_coverage_noise_de_dial_orders_detail_levels,test_palette_threshold_zero_merges_nothing.dist built +
twine checkPASSED (svgsmith-0.5.0).