NHacker Next
  • new
  • past
  • show
  • ask
  • show
  • jobs
  • submit
Okmain: How to pick an OK main colour of an image (dgroshev.com)
seanwilson 12 minutes ago [-]
Nice article! Just curious, but do people intuitively understand what a perceptual 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.

lemonad 17 minutes ago [-]
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)
iamcalledrob 29 minutes ago [-]
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.

latexr 25 minutes ago [-]
> I've built variants of this several times throughout my career.

Got any to share? A self-contained command-line tool to get a good palette from an image is something I’d have a use for.

llimllib 20 minutes ago [-]
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/
latexr 2 hours ago [-]
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.
woodrowbarlow 55 minutes ago [-]
looks like it's a rust lib with a python wrapper. making a CLI tool should be just a few lines of code.
latexr 34 minutes ago [-]
True, but I very much dislike Python (no judgement to those who do, you do you) and dependencies, so the prospect of working with a language I don’t like to get a setup I don’t like, to check if this works in a way I like… Maybe I can find something else.

However, a CLI tool built in Rust (which I’m not too versed in) would make perfect sense and be the fastest entry point.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact
Rendered at 13:04:13 GMT+0000 (Coordinated Universal Time) with Vercel.