Repository navigation
Keep detail and a palette gap note for fixed palettes - #253
Merged
Merged
Conversation
Keep detail (off by default) solves the palette assignment for all source colors at once: Σ n·ΔE² plus λ times the edge contrast lost between touching colors, plus a penalty for flipping which side is lighter, solved with deterministic ICM sweeps (prototype B3, λ 12). With it off, mapping is byte-identical to before. After an Apply with a fixed palette, a note in Quantization Settings says how much of the image is more than ΔE 20 from every enabled palette color, and which tone most of it is, once that reaches a quarter of the image. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e note to the palette's colors - Keep detail solves at most 1024 colors with a dense boundary table and cached palette distances, and yields while indexing and solving. - The palette gap is counted inside mapImageToPalette from each color's nearest palette color instead of in a separate synchronous pass. - Duplicate palette entries no longer use up Keep detail's candidates. - The gap note also hides when the selected palette's enabled colors change. - The Reset arrow's modified state ignores Keep detail while Auto is selected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Palette-pair distances are tabled only for palettes of up to 256 colors. - Candidate setup, indexing and writeback yield, also across transparent pixels. - The nearest cache entry is built with its gap verdict in one literal. - The guide says which colors Keep detail solves together and what the gap percentage counts; Keep detail's output is pinned by a golden hash. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… even split Co-Authored-By: Claude Opus 5.5 <[email protected]>
vycdev
force-pushed
the
t3/palette-keep-detail
branch
from
November 30, 2026 15:25
a495ea9 to
ccb3be2
Compare
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.
For fixed palettes (built-in, supplier or custom; not Auto):
mapImageToPalettepicks the palette color for all source colors together instead of each one's nearest. Energy: Σ nᵢ·ΔE² + λ × the edge contrast lost between colors that touch + a penalty for flipping which side of an edge is lighter. It is solved with ICM sweeps in a fixed order (pixel count, then first appearance), and ties keep the current color, so it is deterministic. It uses prototype B3's parameters: λ 12, μ 4, candidates within nearest + 22 ΔE (at most 5), contrast cap 30, min edge 4. It solves at most the 1,024 most common colors; the rest take their nearest palette color, which only happens with Algorithm None on a photo.With Keep detail off, the output is byte-identical to develop. SHA-256 goldens from origin/develop cover three synthetic palettes, rocco raw and rocco K-means 64 → Bambu. Asking for the gap does not change the pixels either.
Persistence: Algorithm and Number of Colors are plain session state; only the Palette selection is saved. Keep detail matches them: session state, turned off by the Reset arrow. No Strength control: λ is fixed at the research default of 12, and the approved UI is one switch. In the B3 sweep, a higher λ only helped a palette-starved case: λ 120 moved the jacket's skirt to gray, and λ 400 overreached. Adding the missing filament fixes that case better, which is what the gap note suggests.
Before / after
Source after K-means 64 | nearest (today) | Keep detail, Bambu Lab PLA Basic. Each crop is the 300×300 window where the two results differ most.
Synthetic scene: Keep detail keeps the faint hair strands.
rocco photo: more fur detail and the green rim survive, but the gray beak area picks up specks of nearby palette colors. That is the trade-off of turning it on for busy photos, and the guide says so.
The research measured 81% → 92% on the full jacket image. The 25% threshold sits between the palettes that suit an image (19% or less) and the jacket (32% on the full image, 36–47% on the crop).
Timing (Node, Bambu PLA Basic, whole mapping step):
Every phase yields, so the longest event-loop block is about 33 ms. A synthetic 12 MP image with 8.7M distinct colors is slow (5–8 s) in today's nearest path too; that path stays byte-identical, so it is left alone.
Coordination
mapImageToPalette's new options (keepDetail,onPaletteGap).Tests
tests/paletteMapping.test.ts, 17 tests:tests/e2e/quantize-determinism.spec.ts(@smoke): with the 4-gray palette (nothing darker than 20% L) and Algorithm None, the note reads "40% … mostly dark tones. Consider adding a dark filament."; nearest merges the stripes and Keep detail keeps them apart; Undo and another palette hide the note; Reset turns the switch off.tsc -b,npm test,test:i18n,test:docs,check:i18n,test:e2e:all(KROMACUT_E2E_PORT=50177).Docs:
reducing-colors.md(the table and the fixed-palette section) in all 12 languages; UI strings in all 12 locales; CHANGELOG.Council review
Gemini isn't reachable from this environment (only Claude and Codex are enabled), so the council had two members.
Rounds: 5
Fixed:
Declined:
🤖 Generated with Claude Code