绕过RGB步骤将YUV转换为HSL或HSV [英] Convert YUV into HSL or HSV bypassing the RGB step

查看:913
本文介绍了绕过RGB步骤将YUV转换为HSL或HSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

维基百科和大量在线资源为从/到RGB的各种颜色空间转换提供了详细而丰富的帮助.我需要的是直接YUV-> HSL/HSV转换.

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.

实际上,我需要的只是色调(对饱和度或亮度亮度/值"不太在意).换句话说,我只需要计算给定YUV颜色的色角"即可.

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.

使用任何语言的代码就足够了,尽管我更喜欢C风格的语法.

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

请注意,YUV特指Y'UV,也称为YCbCr(如果有区别的话).

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

推荐答案

YUV-> RGB颜色空间转换是线性的(与可以表示为矩阵运算"相同)是RGB-> HSL 不是.因此,不可能将两者合并为一个操作.

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.

感谢凯尔·索拉尔(Kel Solaar)为我确认这一点.

Thank you Kel Solaar for confirming this for me.

供参考:

  • YUV(YCbCr)->RGB conversion
  • RGB->HSL conversion

请注意,在数学上,色相的计算是分段编写的,因为底角"取决于颜色所在的扇区,而主要颜色"由max(R, G, B)表达式驱动.

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.

这篇关于绕过RGB步骤将YUV转换为HSL或HSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆