12

In RGB model, each pixel is defined by 3 bytes, for R,G and B respectively. This gives a total of 224 colors, including 256 tones of grey.

It is very common to represent HSV/HSB/HSL models with floats (not bytes). Most descriptions describe hue as the "angle" in a cone, so it's sensible to treat it as a real number.

But how does this relate to the down-to-earth limit of 224 total colors..? How many distinct hues are available? More over, it seems to me that the number should depend on other parameters - saturation for instance..


Interesting reading: https://web.archive.org/web/20170622125306/http://www.dig.cs.gc.cuny.edu/manuals/Gimp2/Grokking-the-GIMP-v1.0/node52.html

Gabriel Devillers
  • 3,155
  • 2
  • 30
  • 53
emesx
  • 12,555
  • 10
  • 58
  • 91
  • 2
    The HSV/HSB model has less colors than RGB for the same amount of space used to represent colors, since there are values that map to the same color. – nhahtdh Nov 24 '12 at 08:02
  • I believe there are around 60k different hues in RGB. Do you need the exact value? – John Dvorak Nov 24 '12 at 08:04
  • Yes, perhaps there is a formula to calculate this? I'd appreciate every answer with more insight into the subject: overlapping colors, bit-efficiency etc. Moreover - 256 _tones_ of grey are quite separable by the human eye (on a standard LCD). Is it possible to differentiate 60k hues? – emesx Nov 24 '12 at 08:06
  • @elmes: You can try brute forcing? Try to find a library for such conversion, and try out all 2^24 values and count? – nhahtdh Nov 24 '12 at 08:09
  • there are only 3072 different hues with full saturation and lightness – John Dvorak Nov 24 '12 at 08:11
  • @nhahtdh due to floating-point arithmetic limitations I think this wouldn't be precise. This is why I ask.. :) – emesx Nov 24 '12 at 08:11
  • @elmes in you represent each channel with 8 bits you _must_ get fewer colors – John Dvorak Nov 24 '12 at 08:12
  • @JanDvorak where does this come from? In every HS* model? What about other saturations etc (I'd bet with saturation = 0 there are 256 'hue's :-) ) – emesx Nov 24 '12 at 08:12
  • @elmes with saturation = 0 the hue is undefined – John Dvorak Nov 24 '12 at 08:14
  • @JanDvorak - ok :-) Any chance to put it all to an answer? You know, with a formula.. :) – emesx Nov 24 '12 at 08:16
  • Hue is defined as `atan2(sqrt(3)(G-B), 2R-G-B)` – John Dvorak Nov 24 '12 at 08:16
  • so you need the number of simple fractions with numerator and denominator bounded in absolute value. That's not easy, but the density of pairs of coprime integers is roughly constant, so you can approximate – John Dvorak Nov 24 '12 at 08:18
  • @elmes: I don't think it has anything to do with floating point arithmetic. It's just the way we decide to do the mapping, and how we recognize them as different colors. If we decide that all valid colors must be restricted to RGB (RGB has a property that all colors are different if we map it to "analog" color), then the method I proposed is one way to count. (The converse must be adjusted accordingly, since different HSV may map to exactly the same "analog" color - black is the best example). – nhahtdh Nov 24 '12 at 08:22

4 Answers4

10

In HSV, the hue is defined as

H = atan2( sqrt(3)*(G-B), 2R-G-B )

(link). In each of the six sectors (R-Y, Y-G ...), there are equally many hues. Additionally, there are six hues at the boundary between the regions. So, 6 + 6 * huesRY.

In the red-yellow sector, R > G > B, so both arguments to atan2 are positive.

 count sqrt(3) * (G-B) / (2R-G-B)
=count (G-B) / (2R-G-B)
=count (G-B) / ((G-B) + (2R-2G))

since we can apply any linear transformation to the sets of [x,y] and not change the count of its ratios, x / (x+2y) == x / y

=count (G-B) / (R-G)

if we subtract the same value from all R,G,B, the ratio does not change, so assume B=0

=count G / (R-G)
=count G / R

so, there are six times as many hues as there are ratios between two positive integers that are both below 2^8 (assuming 8 bits per channel), and six more. There are as many ratios as there are pairs of coprime positive integers. The number of positive integers below n that are coprime with n is called the Euler's totient function. OEIS lists its partial sums. There are exactly 19948 pairs of coprime positive integers below 256.

6 * 19948 + 6 = 119 694

There are exactly 119 694 different hues in the HSV model that correspond to a color in the 8-bit RGB model. Note that they are not spaced evenly.

If 8 bits per channel are used in the HSV model, then there are less colors than in the RGB model with 8 bits per channel simply because some HSV triples map to the same color while every RGB triple defines a different color.

emesx
  • 12,555
  • 10
  • 58
  • 91
John Dvorak
  • 26,799
  • 13
  • 69
  • 83
0

IN RGB color the hues can be calculated from (2^3*depth-2^depth/Luminance)/3= so 15 bit color has 341 distinct hues

24bit color has 21845 Distinct Hues

if there were 119000 hues the remaing colors All hues-Red hues of the red hue would be 256,X,Y around 2^16 which means there are less green and blue hues than red?

0

RGB<0,128,255> is the named color, Azure, Hue 210 deg.

For RGB<0,n,128> n can only be 0 or 255 to be a distinct hue, which would be either Navy Blue or Spring Green.

RGB<0,64,128> is a shade of Azure, still 210 deg. It is not a distinct hue.

For RGB<0,n,245> again, n can only be 0 or 255, which would be either a blue shade at 240 deg. or a cyan shade at 177.65 deg.

Floating point was introduced as a distinction between HSL and RGB (which must be byte valued integers.) My answer to the original post is a count of distict RGB hues, very focused, and not unproven.

The order of my loops is not arbitrary; it loads an array with the 1,530 unique hues of the full spectrum. Write it up in C++ or C#, then loop, drawing a line from the top to the bottom of the screen and you will see the full spectrum of unique hues. I would upload a bitmap, but the denials have kept me from the points I would need for the privilege, and it would probably need to be as a fractalized jpg which ruins the idea, anyway.

-1

'There are 1,530 Hues in RGB(256,256,256) It really is straightforward. 'This effectively reveals the "resolution" of RGB, since to be a distinct hue, one of rgb must be 255, another 0, and the third has 256 values to increment through, less duplicates at the extremes. Everything else is a tint, tone or shade. So, let's add them up in the six combinations of 0 and 255, and also count them up as I, as we go:

Dim I As Integer
Dim R, G, B As Byte
Dim Spectrum(0 to 1529) as Long
I = -1       'Incremented before each use
R = 255: B = 0   'G inc  RED
For G = 0 To 255         '256
    I = I + 1: Spectrum(I) = RGB(R, G, B)
Next
G = 255: B = 0   'R dec  YELLOW
For R = 254 To 0 Step -1 '255
    I = I + 1: Spectrum(I) = RGB(R, G, B)
Next
R = 0: G = 255   'B inc  GREEN
For B = 1 To 255         '255
    I = I + 1: Spectrum(I) = RGB(R, G, B)
Next
R = 0: B = 255   'G dec  CYAN
For G = 254 To 0 Step -1 '255
    I = I + 1: Spectrum(I) = RGB(R, G, B)
Next
G = 0: B = 255   'R inc  BLUE
For R = 1 To 255         '255
    I = I + 1: Spectrum(I) = RGB(R, G, B)
Next
R = 255: G = 0   'B dec  MAGENTA
For B = 254 To 1 Step -1 '254
    I = I + 1: Spectrum(I) = RGB(R, G, B)
Next
'I = 1,529 = 256+255+255+255+255+254 No duplicates
'Hue = I * 0.23529411764705882353°
'0° is Red at I = 0, so I=0 counts as 1 so, 1 + 1,529 = 1530
Community
  • 1
  • 1
Steven
  • 1
  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 16 '21 at 21:07
  • The statement in this answer is not true. When using integer math, `0,n,255` does not define the maximum number of hues in the triangle of `0,0,0` and `0,0,255` and `0,255,255`. Consider `0,128,255`. What is n for that same hue at `0,n,128`? Here n is 64.5, so technically the hues of the set `0,n,255` are different from the set `0,n,245` and on down — Note that I am not even getting into some of the psychophysical aspects of color perception. Also, the OP specifically indicated using FLOAT, in which case the argument in this answer does not apply even further. – Myndex Jan 23 '22 at 06:21