0

I am trying to convert my rgb image to hsv. I am able to find the value and saturation but got into problem while dealing with hue. I searched for the formula for finding the hue value and got one here.

How do you get the hue of a #xxxxxx colour?

But here also the accepted answer has discussed only 3 options.

  1. R is maximum
  2. G is maximum
  3. B is maximum

(So this is not a duplicate question)

But what about other cases such as

R >= G > B or 
B >= G > R or 
G >= B > R etc

.

Clearly here there is no one value which is the maximum. So for clearing my doubt I searched google and found the following page:

https://en.wikipedia.org/wiki/Hue

Here a table is given that is used for finding the hue value and 6 possible cases are also given. My question is

  1. what are the values 2,4 or 6 in the formula given in the table and how are they calculated?
  2. Why are only 6 cases possible(as shown in the table)? What about

    G >  B >= R or    
    G >= B >= R or     
    B >= R >  G or     
    B >= R >= G etc.
    
Community
  • 1
  • 1

1 Answers1

0

You could let ImageMagick (installed on most Linux distros and available for OSX and Windows) tell you the answer by creating a single pixel RGB image and converting to HSL colorspace:

convert xc:"#ffffff" -colorspace hsl -format "%[pixel:p{0,0}]" info:

hsl(0%,0%,100%)

or

convert xc:"rgb(127,34,56)" -colorspace hsl -depth 8 txt:

# ImageMagick pixel enumeration: 1,1,255,hsl
0,0: (96.0784%,57.6471%,31.7647%)  #F59351  hsl(96.0784%,57.6471%,31.7647%)
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432