1.3.3 interchange Formulas Between HSB and RGB and similarities and differences between HSL and HSV on color attributes
First, HSL and HSV define H in the same way. The formula is as follows:
Max = min means that the values of R, G, and B are always equal. They can only be white, gray, or black. In this case, the color and Phase values have no meaning, so make it equal to 0.
Then, the HSB mode divides the color ranges into three intervals of 120 degrees (Figure 1.28 ).
Figure 1.28 interval distribution of color ranges
[300,360] U [60,180] indicates the red interval, [180,300] indicates the green interval, and [] indicates the blue interval. It is also very easy to determine which color range the H value of the RGB color is located. You only need to check which channel reflects the maximum color. Red is divided into two sides, so when the color is located in the red interval, add a condition, but it is not complex, because the H axis itself is a ring structure, the left side and the right side are actually overlapped, therefore, this step is only to standardize the calculated angle, so that it falls within the range of [0,360] without a negative number. Therefore, when max = R, the formula can be merged as follows:
1 (60*(g-b)/(max-min)+360)%360。
However, when writing a program, it is generally processed by judgment, because the execution efficiency of the remainder is relatively poor.
Then let's take a look at the L and S Calculation Methods in HSL:
It can be seen that only when Max and Min get the maximum value of the channel, that is, when r = G = B = 255 is required, the brightness reaches the maximum. In other words, in HSL mode, only white is the biggest brightness, which is consistent with the HSL color space.
Max = min or L = 0 means R = G = B. At this time, the color is only white, gray, black, and naturally there is no saturation.
The formula for calculating V and S in HSV is as follows:
As the physical value is the brightness V, which has a lower requirement to reach the maximum value than the HSL mode. If one of the three RGB channels reaches 255, the brightness will reach the maximum value. Such a difference may lead to different results in different descriptions of the two colors. That is, the colors A and B appear l (a)> L (B), but V (a) <V (B.
The saturation is defined as 0, and there is no difference between the two modes. The calculation rules of saturation are also determined by the difference of the R, G, and B channel values, divide the result by the brightness. Then, due to the difference in brightness calculation, the color change range of L is twice as large as that of V. Therefore, the division of the HSL model must be equal to twice the brightness to offset it, there is no consensus between HSV and HSL on saturation. The S formula of the HSL model must be written into a piecewise function.
The conversion from HSV/HSL to RGB is the inverse operation from RGB to HSV/HSL. Although this operation is not reversible under some extreme conditions, you can rest assured that, these problems will not affect your use of colors.
For example, h250, s60, l100, H300, S50, and l100, the conversion to RGB is r255, g255, and b255. At this time, HSL is H0, S0, and l100, and the value is changed, however, the result values are always white. This is very similar to the longitude and latitude processing of the Earth at the pole position.