colour.conversions.rgb2hsl¶
- colour.conversions.rgb2hsl(rgb: Tuple[float, float, float]) Tuple[float, float, float]¶
Convert RGB representation towards HSL.
- Parameters
r – Red amount (float between 0 and 1)
g – Green amount (float between 0 and 1)
b – Blue amount (float between 0 and 1)
- Return type
3-uple for HSL values in float between 0 and 1
This algorithm came from: http://www.easyrgb.com/index.php?X=MATH&H=19#text19
Here are some quick notion of RGB to HSL conversion:
>>> from colour import rgb2hsl
Note that if red amount is equal to green and blue, then you should have a gray value (from black to white).
>>> rgb2hsl((1.0, 1.0, 1.0)) (..., 0.0, 1.0) >>> rgb2hsl((0.5, 0.5, 0.5)) (..., 0.0, 0.5) >>> rgb2hsl((0.0, 0.0, 0.0)) (..., 0.0, 0.0)
If only one color is different from the others, it defines the direct Hue:
>>> rgb2hsl((0.5, 0.5, 1.0)) (0.66..., 1.0, 0.75) >>> rgb2hsl((0.2, 0.1, 0.1)) (0.0, 0.33..., 0.15...)
Having only one value set, you can check that:
>>> rgb2hsl((1.0, 0.0, 0.0)) (0.0, 1.0, 0.5) >>> rgb2hsl((0.0, 1.0, 0.0)) (0.33..., 1.0, 0.5) >>> rgb2hsl((0.0, 0.0, 1.0)) (0.66..., 1.0, 0.5)
Regression check upon very close values in every component of red, green and blue:
>>> rgb2hsl((0.9999999999999999, 1.0, 0.9999999999999994)) (0.0, 0.0, 0.999...)
Of course:
>>> rgb2hsl((0.0, 2.0, 0.5)) Traceback (most recent call last): ... ValueError: Green must be between 0 and 1. You provided 2.0.
And: >>> rgb2hsl((0.0, 0.0, 1.5)) # doctest: +ELLIPSIS Traceback (most recent call last): … ValueError: Blue must be between 0 and 1. You provided 1.5.