Extract image clusters and check text contrast
Admin ·
Use a whole-image cluster analysis to extract a palette from several regions. Start with the small RGBA sample so the visible population and contrast are easy to check.
Count the visible pixels in the RGBA example
Select Load example. Keep Maximum clusters at 8 and the backdrop white. Extract the 4 × 2 image. Seven samples enter the calculation and each of the seven resulting colors has one sample. The fully transparent pixel is excluded.
Choose a black backdrop and extract again. The partially transparent sample appears darker. Opaque colors keep their original values.
Reduce the clusters and compare black or white text
Change Maximum clusters to 3 and extract again. K-means groups similar visible samples using distances between their RGB channels and reports each group’s rounded mean. Percentages use the total visible sample count.
Contrast uses the rounded swatch color as a solid background behind each text color. The thresholds in the table apply to normal text.
| Test | WCAG ratio | What it describes |
|---|---|---|
| AA normal text | 4.5:1 or higher | Contrast Minimum |
| AAA normal text | 7:1 or higher | Contrast Enhanced |
| Black text on white | 21:1 | A reference pair with maximum sRGB contrast |
Stuart Lloyd, Least Squares Quantization in PCMW3C WCAG 2.2, contrast and relative luminance
Export the rounded swatches and their evidence
Choose CSS variables and download dominant-colors.css. The file defines --palette-1 and subsequent variables in descending sample-count order. Sass and Tailwind v3 configuration export the same colors in their own formats.
Choose JSON evidence to save the sample dimensions, backdrop, population and contrast numbers. The cluster coordinates are derived from the current sample and can change if you adjust its backdrop or group count.
Common questions
Why might a swatch color be absent from the original file?
Each swatch represents the rounded mean of its assigned sampled colors. That mean can fall between colors present in the source.
Do the contrast ratings certify the finished artwork?
They measure opaque black and white text on each solid swatch. Check the actual text and background wherever you place them in a design.