Tuesday, June 11, 2019

color - Why do I have to use a gamma of 2.2 when using a JPEG picture?


During the rendering process, the texture file has a gamma of 2.2. But the plain colors do not need this gamma correction, especially if the RGB values are from a spectral characterization.


So why do I have to use a gamma of 2.2 in my texture files? Why do we use a gamma of 2.2 in the CG world? Why don't we use a gamma of 1 for images with real colors?



Answer



TL;DR; Because your monitor does not display color linearily


Its a cultural problem


It would be wasteful to use a gamma of 1. The human eye is not linearly sensitive so the data is biased so that there is more data where your eye is more sensitive. More bang for the buck as to speak. So monitors and output devices have been setup with the assumption that colors are not linear in nature. Gamma 2.2 is what sRGB uses, as well as what Windows assumes. (apple often uses a different gamma setting).



However, if you want to calculate on top of the image you may want to use a linear space as it makes it easier to sum values together. Now if you assume the image is linear then your result is wrong when displayed on a monitor that assumes a gamma other than 1. So you need to compensate the image again. This means that systems that are more concerned of their computation engines might assume preprocessing to make the load smaller.


There is no reason why this could not be handled automatically


It just isnt commonly done in 3D graphics apps*. If you render 3D graphics your more concerned with the computation. Where the question whether the image actually was gamma corrected or not is often hard to know. There's no real way to read this info from the pictures metadata as they would erroneously report that the image is corrected even when a method was used that assumed linear application. This often happens with synthetic images like bump maps or other processed images. Because you need to go from corrected too linear and back you would end up with 2 times the error if you handled this wrong. Worse most asset creators would have no idea what I'm talking about even after repeated attempts to explain this. So better to handle manually.


2.2 isn't the end run of this gamma discussion but its the most common setting. You could also use profile translation to more accurate than gamma corrections. But it depends on how your system is set up.


Mathematical explanation


This is a simpler explanation. Your monitor has a display error of g(x) which is no problem if your data is conforming to g(x), however if you want to calculate


a+b+c+d


and a, b, c, d, conform to the error of g(x) you would actually need to calculate.


g(g-1(a)+g-1(b)+g-1(c)+g-1(d))


You would need to do this for each sub element over and over again. Therefore instead of running the transform each time you transform all once to linear and then once back. Problem: not all sources need to be covered some are inherently linear.



* this is slowly changing. But the problem remains that you dont know if the image needs to be compensated or not. Not all sources are created equal.


No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...