Image color palette and quantization error
Find representative coordinates and quantization error from an anonymous color-frequency table
Enter a table of color coordinates and frequencies rather than an image file. Distance is three-dimensional Euclidean distance in the selected coordinate system.
Set k no higher than the number of distinct colors with positive frequency. The calculation yields a local solution; a Lab mean is not a universally optimal perceptual color.
Results
—
- Weighted RMSE (coordinate distance)
- —
- Total frequency
- —count
- Iterations
- —count
- Changes in final assignments
- —
- Center shift in final iteration
- —
Enter the values, then select Calculate.
Method, applicability and sources
Calculation method
In one color space, d²(x,c)=Σⱼ(xⱼ−cⱼ)². Assign to the smallest d², breaking ties by the smaller color number. Centers are c=Σᵢwᵢxᵢ/Σᵢwᵢ. J=Σᵢwᵢ d²(xᵢ,c_{assigned}), RMSE=√(J/Σwᵢ); center shift is the maximum distance between old and new centers in the final iteration. Initialization uses weighted k-means++ with a fixed seed. Lloyd iterations converge when assignments stop changing and every cluster is nonempty. Empty clusters are replenished deterministically using an eligible point with the largest weighted error. Zero frequency contributes nothing to the objective. Values are not finalized if iteration, operation or time limits are reached or calculation is canceled.
Worked example (hypothetical values)
Hand-calculated example: with sRGB (0,0,0) and (10,0,0) each occurring once, k=1 gives center (5,0,0), J=1×25+1×25=50 and RMSE=5. With k=2, both colors become centers and J=0.
Applicability and limitations
Frequency tables of RGB coordinates in sRGB (D65, each 0–255), or CIELAB L*a*b* coordinates defined with one shared white point. Does not upload photos or PNG files, automatically convert RGB and Lab, clip gamut, use CIEDE2000, provide universally perceptual optimization or guarantee a global optimum.
Methods used
- Weighted k-means (v1): scope Shared three-dimensional coordinates and integer frequencies; local optimum; region global
Method and sources
Method: Independent weighted k-means++ initialization / Lloyd v1 (2026-11-14). Data recorded: 2026-11-14.