2

In this article about sRGB (https://en.wikipedia.org/wiki/SRGB) is stated, that the gamma transformation has a linear portion near zero, to "avoid having an infinite slope at K = 0, which can cause numerical problems". I'd like to know what's the problem with that.

Andi Cox
  • 25
  • 5

1 Answers1

2

There are two answers, as is usual for gamma. The modern variant is:

The problem is that with an infinite slope you need "infinite" resolution (many bits of storage) in order to arrive at a linear representation that is invertible to gamma-encoded without loss. In other words, it allows for a small lookup table to produce an invertible linear encoding (8bit -> 10 bit -> 8 bit).

The numerical problem is most easily understood on the first step (8 bit -> 10 bit). With an infinite slope near zero, you need a much bigger encoding range to stay faithful and reversible, i.e. you'd need more than 16 bit (assuming integer coding, halfs do not have this problem).

The linear equivalent of #010101 or 1/255th with square (gamma = 2.0) coding is 1/(255*255)th. You would need 16 bits to represent that faithfully, and using 2.2 not 2.0 as an exponent would make it worse. These quite small numbers are just a corollary of the coding function, and in practice you don't need much resolution in a lightness range that is, roughly, black. So the linear segment helps coding by not wasting resolution to detail around black (or near zero).

The slightly older answer, taken from

http://www.poynton.com/notes/colour_and_gamma/GammaFAQ.html#gamma_correction

is that in some equipment this linear segment will be less sensitive to noise. This is probably mostly true of the analog signal path.

Simon Thum
  • 576
  • 4
  • 15
  • to the first answer: still don't get it. isn't a lookup table of a fixed size anyway? i somehow get the hint regarding linear approximation – a infinite coefficient could be hard to handle, but how does it apply here? isn't the lookup table created by calculating f(n) for each integer? i've some bell with the name taylor on it ringing in the back of my head though... but can't really remember. the second answer i dont get at all. the sensor noise should be unaffected by what you do with the signal later. but i could somehow guess that infinite slopes do very well play a role in analogue amps. – Andi Cox Aug 09 '15 at 20:29
  • Well you'd have two lookup tables, one with 256 entries, 10 bit each and one with 1024 entries, 8 bit each. The point is they're fixed AND relatively small. The linear equivalent of #010101 or 1/255th with sqaure coding is 1/(255*255)th. You would need 16 bits to represent that faithfully, and using 2.2 not 2.0 as an exponent would make it worse. These quite small numbers are just a corollary of the coding function, and in practice you don't need much resolution in a lightness range that is, roughly, black. So the linear segment helps coding. – Simon Thum Aug 10 '15 at 12:47
  • Regarding the analog path, yes, sensor noise is unaffected. But how visible noise actually is depends on the signal path and its encoding as well. I do not have more details, unfortunately, but I'm quite sure in Charles Pontyon's works you can find them. – Simon Thum Aug 10 '15 at 12:51
  • Hi I tried to make it a bit more accessible, please let me know what you think. – Simon Thum Aug 11 '15 at 08:13
  • I think I got it now. An infinite slope is as bad as a slope of zero, as the transformation is ambivalent there. With a steep slope you get a vertical function even earlier, because the resolution is not infinite. So, as you can encode 4 times more values with 10 bit than with 8 bit, the slope can be 4, but if it's steeper you'll lose information because the first some bits all get coded to 0 and are lost. As your source states the slope is actually 4.5 – this still happens to some extent? Where did you get those "10 bits" from? Is this an ADC standard in digital cameras? – Andi Cox Mar 11 '16 at 13:08
  • Sorry for the very late answer, I appreciate your effort. – Andi Cox Mar 11 '16 at 13:08
  • Hi Andi, no prob. The 10 bits are the lowest number of bits you need to represent faithfully linear sRGB encoded data. Even if the slope is 4.5 not 4 will not save you bits, at least not in practice. There might be a standard behind that choice of slope 4.5/~10 bits, but I don't know it. Some monitors and ADCs claim 10 bits per channel. sRGB was never to become a "pro" standard, I guess it was just the most agreeable option. – Simon Thum Mar 12 '16 at 21:41
  • What do you mean, save you bits? What I meant was: if you divide one axis by 2^10 and the other by 2^8, you'll get a slope of 4 (or 1/4 depending on perspective) if you encode linearly. So, a steeper slope will mean you lose information as there are vertical segments in that rasterized line. So actually 10 bits wouldn't be the lowest number, right? – Andi Cox Mar 13 '16 at 22:46
  • Yes, that is correct. I did implement this in my diploma thesis and IIRC, in practice the 10 bits suffice for a lossless de/encoding step. Also I read that a LUT of 1024/10 bits was a design criterion, but I'm not sure where. So if you really want to know for sure, you'll have to implement it and put it to the test. I faintly recall I had to be accurate with rounding for that to work. – Simon Thum Mar 15 '16 at 13:12