User:Pete k 1948/Sandbox

TSL is a color space that is based on Tint, Saturation, and Luminance.

The transformation from RGB to TSL is:

$$S = \sqrt{\frac{9}{5}\left( r'^2 + g'^2 \right)}$$

$$T = \begin{cases} \frac{1}{2\pi} \arctan{\frac{r'}{g'}} + \frac{1}{4}, & \mbox{if}~g' \neq 0 \land \frac{r'}{g'} > 0 \\ \frac{1}{2\pi} \arctan{\frac{r'}{g'}} + \frac{3}{4}, & \mbox{if}~g' \neq 0 \land \frac{r'}{g'} < 0 \\ \frac{1}{2},                                        & \mbox{if}~g'=0 \\ \end{cases} $$

$$L = 0.299R + 0.587G + 0.114B$$

where:

$$r' = r - \tfrac{1}{3}$$

$$g' = g - \tfrac{1}{3}$$

$$r = \tfrac{R}{R+G+B}$$

$$g = \tfrac{G}{R+G+B}$$

An earlier version of the formula for T used the sign of $$ g'$$ to determine whether to add $$ \tfrac{1}{4}$$ or $$ \tfrac{3}{4}$$ to $$ \tfrac{1}{2\pi} $$ arctan $$ {\tfrac{r'}{g'}}$$. That formula generates a discontinuity in the calculated T values for $$ g'$$ near zero; using the sign of $$ \tfrac{r'}{g'}$$ gives a continuous value of $$ \tfrac{1}{2}$$ for for $$ g'$$ near zero.