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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 26th July 2019, 14:38   #1  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,396
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?
Stereodude is offline   Reply With Quote
Old 26th July 2019, 17:19   #2  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,396
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
The problem here is that rgb48y is not a normal color format supported by other plugins. I think it's basically the same thing as AVIsynth+'s PlanarRGB in 16 bits, but I don't know how to convert rgb48y <--> RGBP16.
Stereodude is offline   Reply With Quote
Old 26th July 2019, 17:24   #3  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,379
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.
real.finder is offline   Reply With Quote
Old 26th July 2019, 18:20   #4  |  Link
StvG
Registered User
 
Join Date: Jul 2018
Posts: 252
Quote:
Originally Posted by Stereodude View Post
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?
avsresize?
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")
StvG is offline   Reply With Quote
Old 26th July 2019, 20:23   #5  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,396
Quote:
Originally Posted by real.finder View Post
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
So are they available in a release somewhere?

Quote:
Originally Posted by StvG View Post
avsresize?
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")
I'll give this a shot.
Stereodude is offline   Reply With Quote
Old 26th July 2019, 20:43   #6  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,379
Quote:
Originally Posted by Stereodude View Post
So are they available in a release somewhere?
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.
real.finder is offline   Reply With Quote
Old 26th July 2019, 22:33   #7  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,396
I got the conversions working both ways with avsresize, but it looks like the processing idea that I wanted to try in linear light doesn't work quite the way I was expecting.

Oh well...
Stereodude is offline   Reply With Quote
Old 27th July 2019, 10:21   #8  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,958
Quote:
Originally Posted by Stereodude View Post
How can I convert YV12 or other YUV video to "linear light" (no gamma correction) 16-bit RGB in Avisynth+?
You can try my HDRTools here.
__________________
My github.
jpsdr is offline   Reply With Quote
Old 27th July 2019, 11:38   #9  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,627
Quote:
Originally Posted by Stereodude View Post
it looks like the processing idea that I wanted to try in linear light doesn't work
Maybe if you told us your idea we could help you with that.
videoh is offline   Reply With Quote
Old 27th July 2019, 13:40   #10  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,396
Quote:
Originally Posted by videoh View Post
Maybe if you told us your idea we could help you with that.
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")
Stereodude is offline   Reply With Quote
Old 29th July 2019, 21:55   #11  |  Link
ajp_anton
Registered User
 
ajp_anton's Avatar
 
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 795
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.
ajp_anton is offline   Reply With Quote
Old 7th May 2021, 07:21   #12  |  Link
Dressy
Registered User
 
Dressy's Avatar
 
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.
Dressy is offline   Reply With Quote
Reply

Tags
linear light

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:58.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.