logoalt Hacker News

useftmlytoday at 2:55 PM1 replyview on HN

The performance concern is real but there's another footgun that surprises people in practice: images with large white or transparent backgrounds — product photos on e-commerce sites are the classic case — where the dominant color ends up being white or near-white, which is useless for any branding or UI purpose.

The fix that works best is to either filter out near-white and near-black pixels before the clustering step, or to look at the distribution tail rather than the mode. The most visually interesting color in an image is often not the most frequent one — it's the one that would be chosen as an accent color by a designer. That's a harder problem than it looks because 'visually interesting' is partly about contrast and saturation relative to the rest of the palette.


Replies

dgroshevtoday at 3:06 PM

Picking the best colour is a difficult problem, I don't think there's a good general answer short of ML magic. I assembled an adversarial collection of images:

https://github.com/si14/okmain/blob/main/test_images/IMG_134...

https://github.com/si14/okmain/blob/main/test_images/pendant...

https://github.com/si14/okmain/blob/main/test_images/pendant...

https://github.com/si14/okmain/blob/main/test_images/red_moo...

https://github.com/si14/okmain/blob/main/test_images/supremu...

For every heuristic, I can think of an image that breaks it. On the other hand, I just wanted to do better than the 1x1 trick, and I think the library clears that bar.

show 1 reply