3 ms·
I incorporated logic for finding dominant colors into a program I had written, and from my research clustering algorithms were the best way to get the dominant
by missingrib 3y ago
I incorporated logic for finding dominant colors into a program I had written, and from my research clustering algorithms were the best way to get the dominant color in a way that most users would expect.
K-means clustering seems to have a good tradeoff between performance and results. Interestingly, I found that when doing this in the RGB color space you'd get dominant colors that seemed off. They were usually too dark or muddled.
The best option I found was using k-means clustering in the LAB color space. So you convert the image to RGB, convert that to LAB, run k-means, then pull out the biggest clusters. I don't know enough about color theory to really explain why this works so well, but there are plenty of papers and research on it.
I was also considering using DBSCAN or a different algorithm, but most other clustering algorithms are significantly slower. I personally wonder what programs like Spotify and iTunes use to find the dominant color for something like album art, but I assume they cache the result of the best clustering algorithm they have, potentially even including human input at some point in the process.
- _nalply 3y ago> I don't know enough about color theory to really explain why this works so well, but there are plenty of papers and research on it. Color is complicated. - RGB is as simple but error-prone model for human color reception - Human color reception is not linear and extremely lossy - Color reception strongly depends on lighting and our vision autocorrects distortions - Monitors and prints have their own quirks As far as I know LAB color space tries to account for these facts. It doesn't surprise me that you found out that it worked better than other color models.