ExpertNoob1
ExpertNoob1

Reputation: 932

Color contrast formula ? (ImageMagick)

I reduced an image to 12 colors, annotated with some text (here it's color saturation, sorted) :

enter image description here

The text color is %[pixel:p{10,10}*2] (background *2) (I made a little script that I can share if you're interested).

As you can see, text is not very readable (contrast) in all cases (colors). Is there a smarter formula than a simple linear scaling to make text pop in all/most cases ?

Upvotes: 2

Views: 258

Answers (1)

ExpertNoob1
ExpertNoob1

Reputation: 932

As per Fred's suggestion, using luminosity is much better. Using black & white text depending on luminosity > 56 or not :

enter image description here

And for a not colorful image :

enter image description here

The text represents L component of HSL value. Notice the change from black to white when value crosses 56.

Upvotes: 2

Related Questions