| ▲ | Okmain: How to pick an OK main colour of an image(dgroshev.com) | |||||||||||||
| 66 points by dgroshev 4 days ago | 8 comments | ||||||||||||||
| ▲ | iamcalledrob 43 minutes ago | parent | next [-] | |||||||||||||
As a designer, I've built variants of this several times throughout my career. The author's approach is really good, and he hits on pretty much all the problems that arise from more naive approaches. In particular, using a perceptual colorspace, and how the most representative colour may not be the one that appears the most. However, image processing makes my neck tingle because there are a lot of footguns. PNG bombs, anyone? I feel like any library needs to either be defensively programmed or explicit in its documentation. The README says "Finding main colors of a reasonably sized image takes about 100ms" -- that's way too slow. I bet the operation takes a few hundred MB of RAM too. For anyone that uses this, scale down your images substantially first, or only sample every N pixels. Avoid loading the whole thing into memory if possible, unless this handled serially by a job queue of some sort. You can operate this kind of algorithm much faster and with less RAM usage on a small thumbnail than you would on a large input image. This makes performance concerns less of an issue. And prevents a whole class of OOM DoS vulnerabilities! As a defensive step, I'd add something like this https://github.com/iamcalledrob/saferimg/blob/master/asset/p... to your test suite and see what happens. | ||||||||||||||
| ||||||||||||||
| ▲ | llimllib 34 minutes ago | parent | prev | next [-] | |||||||||||||
OKPalette by David Aerne is my favorite tool for this, it chooses points sensibly but then also lets you drag around or change the number of colors you want: https://okpalette.color.pizza/ | ||||||||||||||
| ▲ | lemonad 31 minutes ago | parent | prev | next [-] | |||||||||||||
This is nice! I looked into this quite a lot some years back when I was trying to summarize IKEA catalogs using color and eventually wrote an R package if you want to look into an alternative to e.g. k-means: https://github.com/lemonad/colorhull (download https://github.com/lemonad/ikea-colors-through-time/blob/mas... for more details on how it works) | ||||||||||||||
| ▲ | seanwilson 26 minutes ago | parent | prev | next [-] | |||||||||||||
Nice article! Just curious, do people intuitively understand what a perceptual uniform color space is without much more explanation? I feel you really need to understand first that typical color spaces like HSL have counterintuitive flaws, like the lightness changing when you only change the saturation or hue sliders. As in, it's very surprising the color spaces most designers use are not perceptually uniform. | ||||||||||||||
| ▲ | latexr 2 hours ago | parent | prev [-] | |||||||||||||
I’d be interested in trying this out as a command-line tool. It would be useful on its own and the fastest way to evaluate results. | ||||||||||||||
| ||||||||||||||