How to convert HSL (hue, saturation, lightness) to HSLum (hue, saturation, luminance) and HSLum/RGB?

时光毁灭记忆、已成空白 提交于 2021-02-07 09:15:23

问题


I want to convert some color values from well know HSL to less known HSLum how to do it?

hsl(0, 1.0, 0.5) - rgb red  is hslum(0, 1.0., 0.54)
hsl(120, 1.0, 0.5 - rgb green is hslum(0, 1.0, 0.80)
hsl(240, 1.0, 0.5) - rgb blue is hslum(0, 1.0, 0.44)

As far as I know luminance (not lightness) is calculate in such way:

Y = 0.2126 * R + 0.7152 * G + 0.0722 * B

I read some articles: Luminance (relative), 21296247, HSL and HSV, luma, Lightness, Munsell but not found solution?

As far I know CIELab 1976 formula is near Munsell:

1.16*(Y/Ymax)^1.16*(Y/Ymax)^(1.0/3.0)-0.16 where Y/Ymax > 0.01

Or better interpolation/

1.16*(Y/Ymax)^(1.0/3.0)-0.16 where Y/Ymax > (6/29)^3
1.16*(841.0/108.0)*(Y/Ymax)+(4.0/29.0)-0.16 where Y/Ymax <= (6/29)^3

How to do such conversions?

  1. HSL -> HSLum
  2. HSLum -> HSL
  3. HSLum -> RGB

Any hints will be welcome - algorithms suggestions.

Here is some tool doing HSLum.


回答1:


If you intend to generate and work with perceptually uniform colors you can use HSLuv, a library created by Alexei Boronine which is available in multiple programming languages.

It is based on the CIELUV colorspace and implements various color conversion routines, like rgbToHsluv, hsluvToRgb, hexToHsluv, hsluvToHex etc.

The library does not support direct conversion from HSL to HSLuv, but you can convert HSL to RGB as described here and afterwards use rgbToHsluv.




回答2:


You might find this link from Charles Poynton's Gamma FAQ interesting:

'22. What are the I, B, L, and V components in HSI, HSB, HLS, and HSV?

To conform with the definition of luminance as being proportional to physical power, the I component of HSI should represent a linear-light quantity. The CIE has defined no objective measure for brightness, but it is clearly a perceptual quantity. Lightness is a perceptual quantity that has been quite precisely defined by the CIE. The CIE has not defined Value, but several different definitions are in use, such as Munsell Value, and all have a perceptual basis and are comparable to lightness.

In most formulations of HSI, HSB, HLS, and HSV used in computer graphics, the quantities are computed from R, G, and B primary components but no reference is made to the nonlinearity in the primary components, that is, the relationship of the primaries to linear light. So it is impossible to determine whether the calculated HSI, HSB, HLS, or HSV represents a physical or a perceptual quantity.

The brightness component of HSI, HSB, HLS, and HSV should be based on luminance, computed as a properly-weighted sum of red, green, and blue. But in the usual formulations, the brightness component is computed as either the maximum of the three components, or the average of the minimum and the maximum of the three. This highly nonlinear calculation introduces spokes into the hue circle.

Finally, the color produced by an RGB triple translated from HSI, HSB, HLS, or HSV depends on the chromaticity of the RGB primaries, but none of the usual formulations of HSI, HSB, HLS, or HSV takes primary chromaticity into account.

For these reasons, any use in computer graphics of I, B, L, and V quantities is suspect. For detail, see Frequently Asked Questions about Color.

I take that to mean that in all cases, you must convert to RGB to go between any of these formulations, and further that these formulations are somewhat poorly defined.



来源:https://stackoverflow.com/questions/23699781/how-to-convert-hsl-hue-saturation-lightness-to-hslum-hue-saturation-lumin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!