Sign in to follow this  
Acharis

Checking if colour is "too similar"

Recommended Posts

Let's say we want to draw a map with countries, each country has a colour. How to assure that the colours of neighbour countries are not "too similar" (like both are some shade of yellow or yellow next to light orange or two greens next to each other)?

Basically, I look for a function to test if colour A is "too similar" to colour B.

 

For starters, should I attempt it by comparing RGB or HSI would be better?

 

 

 

Share this post


Link to post
Share on other sites

From my artistic point of view, using HSB is much more reliable.

 

If the saturation is really low, it means the only component to take in account to check the difference is the brightness.

 

If the saturation is medion-high, then you check based on HUE.

 

If the saturation is medion-high and the HUE is really close for two colors, then you check for the brightness.

 

RGB is a poor measure of color (in artistic terms). Good to represent color on monitors, poor in actual biological meaning (perception).

Share this post


Link to post
Share on other sites

By HSB you mean HSI? (I'm not extremelly familiar with the terminology) Also, HSI=HSL=HSB (just called differently)?

 

Well, brightness probably would be always similar (artistic wise, since those represent same type of thing (country) then it should have similar brightness (so fro example I can safely use black text over it becuse I would assume the foreground is light)). So, I think I should check against HUE and SATURATION mostly/only?

 

OK, HUE would be easy, if less than 0.25 difference in hue then assume it's "too similar. But how (and if I should) throw SATURATION to the mix as well? Like if same HUE could look different if SATURATION differs greatly (just guessing, I know only basics of colour theory)?

Share this post


Link to post
Share on other sites


By HSB you mean HSI? (I'm not extremelly familiar with the terminology) Also, HSI=HSL=HSB (just called differently)?

Some of these means the same thing, some don't.

The two most common are HSL (also called HLS) and HSV (also called HSB). There's the third HSI (which you mentioned), but I rarely see it around.

 

I have a function to convert RGB-HSB/HSB-RGB here:

https://github.com/felipefs/libpixpaint/blob/master/pixpaint.c

 


Well, brightness probably would be always similar (artistic wise, since those represent same type of thing (country) then it should have similar brightness (so fro example I can safely use black text over it becuse I would assume the foreground is light)). So, I think I should check against HUE and SATURATION mostly/only?

If you are going to use black text, then yeah. HUE and saturation are the ones you will check mostly.


OK, HUE would be easy, if less than 0.25 difference in hue then assume it's "too similar. But how (and if I should) throw SATURATION to the mix as well? Like if same HUE could look different if SATURATION differs greatly (just guessing, I know only basics of colour theory)?

If the two countries have colors with low saturation (S), then both are gray-ish, and they are the same color (you don't even need to check HUE). Else, if saturation is medium-high, then check HUE.

SwzF2CL.png

Share this post


Link to post
Share on other sites

From an artistic perspective, RGB is possibly the worst color scheme out there.  You're far better off comparing in practically any other color space.  If you wanted to be super accurate about it, you'd want to find a color space that better represents the colors people can actually see.  This is outside my expertise, but I know that people can generally see more shades of green than any other, for instance, so you'd want to put less weight on that than other colors.

Share this post


Link to post
Share on other sites
Better to use LAB color space

This, most definitively. Not only was it designed for the purpose of being "perceptual", it also has the immense advantage of automatically solving the problem of color weakness/blindness for you. This is otherwise an extremely hard problem.

Deuteranomaly? Deuteranopia? No problem because red and green are on the opposite sides of the a axis. Protanomaly or protanopia? No problem because, you guessed it, blue and yellow are on the opposite sides of the b axis. For any colors to be used on adjacent areas, choose a pair of colors that are significantly different on these (or alternatively have a significantly different L), and you have both deficiencies covered. Try doing the same in RGB, it's a sheer unsolvable nightmare.

Edited by samoth

Share this post


Link to post
Share on other sites

 

Boring answer: since any 2D planar map can be uniquely painted using only four colors, all you have to do is manually choose four you like!

It's that kind of thinking that led to CGA's black/white/cyan/magenta, what is sometimes called the worst colour palette ever inflicted on mankind.

 

 

Oh I don't know, I quite like the old black/white/cyan/magenta look of things... but then again I'm pretty weird. And in terms of Color I would agree that using LAB offers probably the best (or one of at least) ways to do color comparisons

Share this post


Link to post
Share on other sites

if (color1.x-color2.x<0.1&&color1.y-color2.y<0.1&&color1.z-color2.z<0.1)color2=rngcolor();

If every rgb value is within 0.1 of the original, then reroll the color

Edited by Melley

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this