Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm for parsing hex into color family

Tags:

c#

hex

colors

Does an algorithm exists that will input a color's hex value and output what color family that value belongs to? For example if i input 3333FF it would identify that as being a shade of blue. I would need to be able to input any hex value and narrow it down to one of the 24 colors on a standard color wheel plus black, white, and grey. (i would consider black all grey values up to #151515, and white all values down to #F1F1F1)

like image 227
BigPete Avatar asked Dec 29 '25 03:12

BigPete


1 Answers

One way would be to convert the hex code to HSV and then split up the hue value into regions. So you just check the hue, if it's between these two values it's red, if it's between these it's yellow, etc. You can also check saturation and lightness to determine what to call white, grey, and black. Those thresholds will be all up to you.

like image 196
Tesserex Avatar answered Dec 30 '25 16:12

Tesserex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!