Reverse sRGB Transformation
by AdamStanislav - uploaded on July 11, 2021, 11:17 pm
The sRGB color space is non-linear. This is the formula to convert an sRGB color into plain linear (and mostly abstract) RGB space. It is derived from the formula shown on Wikipedia: https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation_(sRGB_to_CIE_XYZ)
It is called “reversed” because the “forward” formula converts the abstract linear RGB to sRGB (in this case, as other color spaces exist), while the “reverse” formula (marked by the -1 over the Greek letter gamma shown on the left of this formula) reverts the transformation back to the abstract RGB space.
Please note that the u in the formula is the luminosity of a channel (usually red, green, blue) of a color scaled in such a way that black (or the darkest possible luminosity) equals 0 and white (or the brightest possible luminosity) equals 1. And “brightest possible” is relative to the device producing the light of some color, such as a computer monitor or a movie projector, not the absolutely brightest light in the Universe.
Comments
@philx
2021-07-12 11:44:06+00I have no idea what any of it means. but Im glad you do :-)
@AdamStanislav
2021-07-12 14:55:21+00@philx It means that when you make a bitmap and save it as a PNG or such, each pixel will have three channels (red, green, and blue) and the color will be represented as a value from 0 to 255, where 0 is the darkest and 255 is the lightest. But when software processes it, it will convert these values to 0 as the darkest nd 1 as the lightest, but the colors will most likely not be straight RGB, where, for example, 0.5 is 5 times brighter than 0.1, but it will be in the sRGB color space and to convert it to a linear brightness (with 0.5 being exactly 50% as bright as 1.0, for example), you have to use this formula, which states that if the sRGB value is less than or equal to 0.04045, you just divide it by 12.92 to get its linear RGB value. But if it is greater than 0.04045 you use the formula in the second line, so you add 0.055 to the sRGB value, then divide the result by 1.055, then raise the result to the power of 2.4, and then you will have the linear value.
And the reason why computers tend to use sRGB instead of just linear RGB is the way video monitors work. They are not linear (due to the physical limitations of making a display), so when you throw an sRGB image at them, the physical hardware will display it so what you see is the linear representation (as if the hardware applied this formula). And technically, our eyes also do not see in a linear fashion but our brains adjust whatever the optic nerves send them, so when something appears twice as bright to us it is not physically reflecting twice as many photons to our eyes.
But the reason software may need to apply this transformation is in image and video processing it is best to use the math on linear RGB pixel values, so the software has to transform the sRGB values to RGB, then pass the result on to whatever routine (or perhaps a plugin) does some effect (such as changing the brightness or contrast or saturation...). After the effect is applied, the software will typically convert it back to sRGB or a similar color space so it can be displayed on a monitor the way the artist intended.
@philx
2021-07-13 12:24:04+00i do math, sort of. but you do MATH. I actually understood your comment and could probably code it (since you explained it well...), but then i can code things that i only vaguely understand. it was a living :-)
@AdamStanislav
2021-07-13 15:33:55+00@philx :-)
Log in to comment.