Extract dominant color palettes from any image to design themes.
Extracting a color palette isn't as simple as picking the most frequent pixels. A high-resolution image can have millions of unique colors.
To find the true "dominant" thematic colors, this tool uses a classic machine learning algorithm called K-Means Clustering.
OffscreenCanvas. This reduces the dataset from millions of pixels to a maximum of 40,000 without significantly altering the dominant visual colors.K-Means involves calculating the Euclidean distance between every single pixel and every centroid, multiple times per second.
To prevent this heavy math from causing the UI to stutter, the clustering loop is entirely offloaded to a background thread (image.worker.ts). This guarantees your browser remains perfectly responsive while the algorithm crunches the numbers locally.
No algorithm is perfect. K-Means groups colors into hard boundaries. If an image is mostly a smooth sunset gradient, the algorithm might result in arbitrary, harsh bands of color being selected as "dominant."
Additionally, because we downsample the image to 200px to maintain performance, colors that only appear in tiny details (like a 1px thin border) will be averaged out by the canvas scaling and completely ignored by the algorithm.
Why does the tool downsample the image to 200px before running the color extraction?