Repository navigation
Pick Algorithm Weight automatically and make K-means repeatable - #248
Merged
Merged
Conversation
Remove the Algorithm Weight field. The intermediate palette size now follows a measured per-algorithm rule (src/lib/algorithmWeight.ts): Number of Colors for K-means and Wu, 4x clamped to 128-256 for Median-cut and 64-256 for Octree, at least 128 for Posterize, 64 for fixed palettes, and 256 when deleting a swatch. K-means now draws from a seeded mulberry32 stream instead of Math.random, so the same image and settings always give the same colors. Docs, the pipeline diagram and locales are updated in all 12 languages. Adds unit tests for the rule, pinned K-means goldens, and a browser smoke test that matches the Node golden. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Council round 1. Deleting a swatch from an image with 256 colors or fewer now skips the first stage, so only that color's pixels move for every algorithm (Posterize used to merge similar swatches); larger images keep the old 128. A selected palette that can't be resolved falls back to Auto's count, and deleting the last opaque swatch is a no-op. K-means++ setup now updates each color's nearest-centroid distance with only the newest centroid, which gives identical output in O(k*n), and yields while it works. Docs state the Median-cut, Octree and fixed-palette Posterize values in all 12 languages. Adds a Node test behind the browser golden and smoke tests for palette reset and Posterize Delete. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Council round 2. K-means reports progress while seeding, refining and building its lookup, and yields inside long scans; output is unchanged. The Posterize Delete smoke test now checks each stripe's exact color, which the old path failed. Docs scope the "choose None before Delete" advice to images with more than 256 colors in all 12 languages. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Council round 3. The swatch-operations diagram now says Delete moves only the deleted color's pixels up to 256 colors and to choose None above that, in all 12 languages. K-means reports progress inside each refinement pass. The Posterize Delete smoke test asserts that an image was recorded and that Undo brings the deleted swatch back. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Council round 4: the German, Spanish, Hindi and Bengali lines now name None and Eraser exactly as the controls do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
develop now opens on a drop zone (#247); load the sample the way the other specs do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
vycdev
force-pushed
the
t3/seeded-kmeans-auto-weight
branch
from
November 30, 2026 12:59
4daa058 to
e41595e
Compare
This was referenced Nov 30, 2026
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.
Cleaning up an image in 2D was cumbersome, and one reason was a setting nobody could use well. Algorithm Weight sets the size of an intermediate palette, but measurements showed the default of 128 made K-means and Wu results worse and slower than reducing straight to the target. Also, K-means started from
Math.random, so two Applies of the same settings could give different colors.This PR hides Weight and picks it per algorithm, and seeds K-means so results repeat. It's the first of the approved color-cleanup PRs.
Weight rule (
src/lib/algorithmWeight.ts)Delete on images with 256 colors or fewer now maps straight to the remaining swatches, so only the deleted color's pixels move, for every algorithm. Before, an image with more than 128 colors was first reduced to 128, and Posterize could merge two similar swatches nobody deleted.
Measured against the old default of 128 (line art 1600×1600 and a 1800×1350 photo, 8/16/32 colors):
Faster K-means. The k-means++ setup now updates each color's nearest-centroid distance incrementally. The output is byte-identical, and the goldens are unchanged.
It also reports progress while it seeds and refines, and yields to the page during long scans.
Results change for existing users in two ways: the new Weight values, and the seeded K-means.
Other changes:
idits label already pointed to.reducing-colorsguide and its pipeline and swatch-operations diagrams) and locales are updated in all 12 languages, and diagram measurements are regenerated.Note for #220: project files there save
quantize.weight. After this lands, #220 should keep reading the field for older files and ignore it.Deferred to the Delete rework (PR 4 of the plan): Delete's target palette is RGB-only, so two swatches with the same RGB and different alpha can't be told apart. This predates this PR, and the rework replaces Delete-by-requantize with a direct RGBA remap. Like every quantize run, Delete still makes partially transparent pixels opaque; the guide says so in its pipeline section.
Tests
countOpaqueColors.Math.random.@smokebrowser tests:Checks run locally: lint,
tsc -b,npm test(1312 pass),test:i18n,test:docs,check:i18n,test:e2e:allon port 47391: all suites passed after rebasing onto develop with #247 (smoke 199, docs 6, landing 19, privacy 13, terms 10, not-found 10, i18n 17, i18n build 4), with no port collisions.Council review
Rounds: 4
No third provider (Gemini or another) was enabled in this environment, so the council ran with two members.
Created with Claude Opus 5.5 in Claude Code (T3 Code). Reviews by Claude Opus 5.5 and GPT-6.2 Sol.