Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
26th July 2019, 14:38 | #1 | Link |
Registered User
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
|
Converting to "Linear Light" and back
I want to try some processing in linear light.
How can I convert YV12 or other YUV video to "linear light" (no gamma correction) 16-bit RGB in Avisynth+? Then, how do I reverse the operation and convert the 16-bit "linear light" RGB back to YUV video? |
26th July 2019, 17:19 | #2 | Link |
Registered User
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
|
I found this Dithertools example:
Code:
# Y'Cb'Cr' input in 16 bits Dither_convert_yuv_to_rgb (matrix="709", output="rgb48y", lsb_in=true) Dither_y_gamma_to_linear (tv_range_in=false, tv_range_out=false, curve="709", sigmoid=true) Dither_resize16nr (1280, 720, kernel="spline36") Dither_y_linear_to_gamma (tv_range_in=false, tv_range_out=false, curve="709", sigmoid=true) r = SelectEvery (3, 0) g = SelectEvery (3, 1) b = SelectEvery (3, 2) Dither_convert_rgb_to_yuv (r, g, b, matrix="709", lsb=true) # Y'Cb'Cr' output in 16 bits |
26th July 2019, 17:24 | #3 | Link |
Registered User
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,587
|
I port that to work with avs26/avs+ in ResizeX (still not use it in ResizeX functions though)
y_gamma_to_linear = Dither_y_gamma_to_linear y_linear_to_gamma = Dither_y_linear_to_gamma from what I read you should use it with 8 < bits (10 bits or more) even if it work with 8bit
__________________
See My Avisynth Stuff Last edited by real.finder; 26th July 2019 at 17:27. |
26th July 2019, 18:20 | #4 | Link | |
Registered User
Join Date: Jul 2018
Posts: 450
|
Quote:
Code:
z_ConvertFormat(pixel_type="RGBPS",colorspace_op="709:709=>rgb:linear",resample_filter_uv="spline36") z_ConvertFormat(pixel_type="YV12",colorspace_op="rgb:linear=>709:709",resample_filter_uv="spline36",dither_type="error_diffusion") |
|
26th July 2019, 20:23 | #5 | Link | |
Registered User
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
|
Quote:
I'll give this a shot. |
|
26th July 2019, 20:43 | #6 | Link |
Registered User
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,587
|
they available but no other functions use them
I did update the ResizeX now, added sigmoid_inverse and sigmoid_direct and make y_gamma_to_linear and y_linear_to_gamma deal with PlanarRGB smartly edit: Example Code:
convertbits(16) ConvertToPlanarRGB y_gamma_to_linear() resizex(width/2,height/2) y_linear_to_gamma() ConvertToyuv420
__________________
See My Avisynth Stuff Last edited by real.finder; 26th July 2019 at 21:05. |
27th July 2019, 13:40 | #10 | Link |
Registered User
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
|
I have some video footage from a live performance DVD that has incorrect black levels, specifically they're boosted up quite a bit. I've found that if I adjust the black levels down the footage seems to need a gamma adjustment to look right.
I had the idea that perhaps if I converted it to linear light, then adjusted the black levels, and then converted it back the gamma would self correct. I didn't realize how tiny the black level adjustment would need to be when the footage is in linear light which appears to make it impractical to work this way. Maybe what I was hoping to do in linear light would work better in a log video mode. However, converting to log video doesn't appear to be reversible with avsresize. What I mean is just converting to a log mode (like 100:1) and then back from that mode results in a significant change to the original footage shifting the video levels significantly. Code:
z_ConvertFormat(resample_filter="bicubic", filter_param_a=1/3, filter_param_b=1/3, pixel_type="RGBP16", colorspace_op="170m:601:170m:l=>rgb:log100:170m:l", dither_type="error_diffusion") z_ConvertFormat(resample_filter="bicubic", filter_param_a=1/3, filter_param_b=1/3, pixel_type="YUV420P16", colorspace_op="rgb:log100:170m:l=>170m:601:170m:l", dither_type="error_diffusion") |
29th July 2019, 21:55 | #11 | Link |
Registered User
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 805
|
The point (or one of the points?) of the gamma correction is that each step is perceived to be about equal to the eye, so all of the 256 levels (8bit) are worth the same. Converting to linear light will greatly stretch the bright end of the scale and compress the dark, so that a lot of bits are wasted on bright areas (lots of levels unused) and information is lost in dark areas because too many levels are squeezed into too few boxes. That's why the conversion is done in 16 bits, to increase the number of "boxes" so that information isn't lost. You could of course convert that into regular 8bit RGB for testing purposes, to have more compatible filters available, but remember that heavy banding will appear in dark areas because the effective bitdepth there is reduced.
|
7th May 2021, 07:21 | #12 | Link |
Registered User
Join Date: Feb 2021
Location: Florida Miami
Posts: 3
|
This is very interesting. Thanks a lot for sharing. In general, I really like to read new information from different forums, articles, and sites because, in this way, I develop multilaterally and find things that help me in my daily life. For example, looking for something new to read, I found out about amazon night light, and I was amazed because it works great. Why? Because it automatically adjusts itself according to the brightness of the rooms, so I don't have to turn my head to turn it off or on, which is really perfect.
Last edited by Dressy; 10th May 2021 at 20:14. |
Tags |
linear light |
|
|