In actual use of colors, changing the color of an image by changing the color value is a common method.
By changing the color value of the solid color, it is called the deflection of the solid color. For example, if the solid color (255, 0, 0) is bent clockwise 60, the solid color (255,255, 0) is obtained, and the solid color (255, 0, 255 ).
So what color does the solid color (127, 44, 0) Get from clockwise deflection? The followingArticleIt is about the calculation method.
In "Computer Color v -- quick calculation of the color phase value", the formula for calculating the color phase value H of a solid color is:
When G is greater than or equal to B, H = (255-r + G + B)/255 × 60 publicity 1
When G <B, H = 360-(255-r + G + B)/255 × 60 formula 2
Take ω as the deflection value, and define the positive value as clockwise deflection. The negative value is counterclockwise deflection. The value range of ω is [-180,180].
Then, the color value H '= H + ω after the deflection, H' has an overflow problem. I will discuss it later.
In "Computer Color vi-fast computing from the color phase value to the solid color,
The key to calculating the solid color is the angle θ between the solid color and the red color. When H <180, θ = H; when h> 180, θ = 360-h
Using formulas 1 and 2, we can see that θ = (255-r + G + B)/255 × 60
The solid color after deflection and the red angle θ '= θ + ω. At this time, ω is different from the above ω. On the right side of the six-color ring, the definition is the same as above; on the left side of the six-color ring, the definition is opposite to the previous one. It is a positive clockwise value and a negative clockwise value. Because of the symmetry between the left and right sides of the six-color ring.
λ '= θ'/60 × 255 = (θ + ω)/60 × 255 = [(255-r + G + B) /255 × 60 + ω]/60 × 255 = 255-r + G + B + ω/60 × 255
If ω '= ω/60 × 255, then λ' = 255-r + G + B + ω'
Consider the overflow problem of λ,
When λ '<0, it indicates that the color after deflection spans the Left and Right partitions (note: in the preceding section, the actual color is divided into the left and right partitions ). In this case, set λ ''=-λ'
When λ '> 765, it also indicates that the color after deflection spans the Left and Right partitions. In this case, make λ ''= 1530-λ'
Otherwise, λ ''= λ'
Then the solid color after deflection (R', G', B ')
R' = 510-λ ''; If R' <0, R' = 0; If R'> 255, R' = 255;
G' = λ ''; If G'> 255, G' = 255;
B '= λ ''-510; If B' <0; then B '= 0;
If the color after deflection is in the left half area, then G', B 'is switched'
How can we determine that the color after deflection is in the left half area, but the G' and B 'must be exchanged '?
If the primary color of G is greater than or equal to B in the right half, the partition is crossed. The solid color after deflection is in the left half. That is, λ '<0 or λ'> 765.
For G <B, the primary color is in the left half area, so there is no cross-partition case. The solid color after deflection is in the left half. Is 0 ≤ λ '≤ 765
Are there any unified expressions for these two situations?
When the (G <B) XOR (λ '<0 or λ'> 765) expression is true, G', B 'must be exchanged'
XOR indicates an exclusive or operation. If two logical expressions are true or false, true is obtained. Otherwise, false is obtained.
Okay. Let's sort out the above reasoning process. Solid color (R, G, B) how to calculate the deflection solid color (R', G', B ')
When G <B, ω =-ω
ω '= ω/60 × 255
λ '= 255-r + G + B + ω'
When λ '<0, set λ ''=-λ'
When λ '> 765, set λ ''= 1530-λ'
Otherwise, λ ''= λ'
Deflection component of solid color
R' = 510-λ ''; If R' <0, R' = 0; If R'> 255, R' = 255;
G' = λ ''; If G'> 255, G' = 255;
B '= λ ''-510; If B' <0; then B '= 0;
If (G <B) XOR (λ '<0 or λ'> 765) = true, the values of G' and B 'are exchanged.
(127, 44, 0) What is the color of clockwise Deflection? The answer is (0,255, 74)
(127, 44, 0) What is the color of the counterclockwise deflection? The answer is (255)