5

Wikipedia and plethora of online resources provide detailed and abundant help with various color space conversions from/to RGB. What I need is a straight YUV->HSL/HSV conversion.

In fact what I need is just the Hue (don't care much for the Saturation or the brightness Lightness/Value). In other words I just need to calculate the "color angle" for a given YUV color.

Code in any language would suffice, though my preference is C-style syntax.

Note that by YUV I mean specifically Y′UV, a.k.a. YCbCr (if that makes any difference).

YePhIcK
  • 5,816
  • 2
  • 27
  • 52
  • You should know that we cannot recommend any library or software to do this. We can help with code you wrote but we can't write it for you either. – Rob Sep 28 '17 at 18:55
  • @Rob Would you recommend to move this into a different SE site? If so - which one? (I can write the code myself, no biggie. I need help with the algorithm for color space conversion) – YePhIcK Sep 28 '17 at 18:57
  • Good question. There is a Graphics SE and a Math one. I'd be interested in this solution myself though I have a few algorithms stashed away that I've not looked at in decades. – Rob Sep 28 '17 at 19:01
  • I have thought of both (plus the "photo/video") but none seemed appropriate, TBH. Which is why this question ended up here - where I hoped I'd have a better chance at attracting people that are "interested in this solution" themselves, much like what you said above. – YePhIcK Sep 28 '17 at 19:03
  • Look at the Gaming one. Some of the same people there. I don't know if the other SE sites have the same restrictions on recommendations. – Rob Sep 28 '17 at 19:04
  • So I checked all the suggested sites and (simply based on the available tags) none of them is as close a fit for this question as SO. I'll keep it here for now since I can't find a better fit for it :( – YePhIcK Sep 28 '17 at 19:49
  • 1
    There are multiple non-linear conversions in the chain from Y'CbCr to HSV, none of them is a linear colourspace, so you will not find an affine transform mapping the twos. – Kel Solaar Sep 29 '17 at 02:54
  • @KelSolaar Thank you! That reasoning "non-linear transfomrs" is exactly the one I myself have arrived at a few hours ago. Was just hoping I was wrong... – YePhIcK Sep 29 '17 at 17:27
  • You were correct! – Kel Solaar Sep 29 '17 at 20:24

2 Answers2

1

While YUV->RGB colorspace conversion is linear (same as "can be expressed as a matrix operation") the RGB->HSL is not. Thus it is not possible to combine the two into a single operation.

Thank you Kel Solaar for confirming this for me.

For reference:

Note that mathematically the calculation for Hue is written piecewise as the "base angle" depends on which sector the color is in and the "major color" is driven by the max(R, G, B) expression.

YePhIcK
  • 5,816
  • 2
  • 27
  • 52
  • 2
    I would like to add that even though the relationship between Y'CbCr and RGB is linear, the transformation is actually Y'CbCr to R'G'B'. The primes are here to denote the non-linearity of the components being transformed and. The Y' of Y'CbCr is for Luma, not Luminance. This imply that you might also want to decode your non-linearly encoded R'G'B' colours to linear RGB colours before converting to HSV. – Kel Solaar Sep 29 '17 at 20:22
0

I think they are from the different worlds of interest. Here is a google patent
https://patents.google.com/patent/CN105847775A/en

nerkn
  • 1,867
  • 1
  • 20
  • 36
  • Just read the patent and... how is it different from a lookup table? ;-) Which also makes its space requirements unpractical in any application with limited RAM – YePhIcK Dec 19 '20 at 04:22