View Full Version : Convert to Linear Gamma for processing ?
butterw2
18th July 2020, 11:14
I occasionnaly read people recommending re-converting to linear gamma to perform image/video processing, but I don't think I've seen it actually being done.
When does it apply ?
How best to test whether the processing is correct ?
My own application is realtime effects/filters in video players.
Input: encoded video (mp4: x264, x265), typ: 720p, 1080p
Video player (mpc-hc)
Output LCD display, typ: 1080p
proposed Pixel shader in mpc-hc (.hlsl):
// overhead for gamma conversion: 9 arithmetic ops
#define Gamma 2.2
color = pow(color, Gamma); //color is rgb float(32, 32, 32) in range [0, 1]
// Do color processing
return pow(color, 1./Gamma);
wonkey_monkey
18th July 2020, 13:21
I usually approximate gamma in my filters by squaring every value before processing and then taking the square root at the end. It makes for nicer blends and blurs and so on.
butterw2
30th July 2020, 20:50
I was trying out an encoder GUI with some HDR content (with the goal of doing HDR passthrough) and the default avisynth script did the resize to 1080p without any reference to converting to linear and back. I guess it musn't have too much of an impact in this case ?
In areas where linear gamma processing is critical (3D rendering/lighting) a sRGB-888 gpu framebuffer may be used. Reads/Writes from the framebuffer are converted transparently to linear gamma/sRGB in hardware (not approximation) in order to perform fast accurate processing and to preserve accuracy with multiple passes. A higher bitdepth framebuffer would be required to keep the intermediate steps in linear before the final conversion to sRGB.
wonkey_monkey
30th July 2020, 21:18
The impact depends on the content. If, for some reason, you've got a sharp boundary between bright green and bright magenta then you'll get a noticeable dark line between them - but that just doesn't happen very often. But given that the encoder can't know what'll be thrown at it, it should ideally take gamma into account.
foxyshadis
1st August 2020, 11:58
White surrounded by dark is the poster child for how non-linear darkens everything during a resize. Starscapes, night shots, lens flare, you can see it anywhere there's a point light source. You might get used to it, or never notice, but it's always there. IM has an excellent example:
https://www.imagemagick.org/Usage/resize/earth_lights_direct.png
vs
https://www.imagemagick.org/Usage/resize/earth_lights_colorspace.png
Prior to resizing, the image (http://eoimages.gsfc.nasa.gov/ve//1438/earth_lights_4800.tif) looked like the lower one, but the top is what all generic non-linear resizers will give you.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.