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. |
|
|
Thread Tools | Search this Thread | Display Modes |
15th March 2019, 23:55 | #1 | Link |
Registered User
Join Date: Feb 2013
Posts: 161
|
Gamma settings - in YUV with preservation of saturation
How to set gamma correctly in YUV, without convert to RGB (less rounding errors, without banding)
Code:
levels(0,1.32,255,0,255) tweak(sat...) The right way but converting to RGB: Code:
converttorgb32 levels(0,1.32,255,0,255) converttoyv12 Code:
converttorgb32 RGBAdjust(rg=...,gg =...,bg=...) converttoyv12 There are 2 ways: 1) convert to "deeper bit" (or float) RGB -> change gamma -> convert back to YUV (slow) 2) make it all "in one step" = stay in YUV: a) change gamma in luma b) change "saturation" of chroma "adaptively", in relation to each pixel value of luma (lower luma means higher saturation lost by gamma change) something like this (but it's still not ok): Code:
y = converttoy8() u = utoy8() v = vtoy8() y_adjusted = mt_lut("x 16 - 219 / 1 1.32 / ^ 219 * 16 +", chroma="copy") y_scaled = y.bilinearresize(width(u),height(u)) u_adjusted = mt_lutxy(u,y_scaled,"x 128 - y 16 - 219 / 1 1.32 / ^ 219 * 16 + y / * 128 +") v_adjusted = mt_lutxy(v,y_scaled,"x 128 - y 16 - 219 / 1 1.32 / ^ 219 * 16 + y / * 128 +") ytouv(u_adjusted,v_adjusted,y_adjusted) In a nutshell: We take the gamma adjusted luma value of each pixel and divide it by the original luma value of each pixel. This gives a coefficient for each pixel to multiply the saturation adjustment according to the gamma change. The greater the luma change, the greater the saturation lost. Last edited by Stormborec; 17th March 2019 at 15:01. |
16th March 2019, 03:22 | #2 | Link | ||
Registered User
Join Date: Jul 2011
Location: Tennessee, USA
Posts: 266
|
Quote:
Quote:
|
||
16th March 2019, 11:38 | #4 | Link | |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Well I know that you are familiar with ColorYUV2 (as you have posted about it before), but here anyways in case you forgot:- https://forum.doom9.org/showthread.p...ight=colorYUV2
Groucho also has 64 bit build of it, in his stuff. Also RgbAdapt has RPow/SPow stuff. https://forum.doom9.org/showthread.p...light=RgbAdapt EDIT: And demo of the iMin, iMax, OMin, OMax stuff (mask creation or whatever) [EDIT: Grid turned off]. EDIT: Also, VirtualDub2 has some kind of 6 axis RGB adjustment function thingy. EDIT: Quote:
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 16th March 2019 at 22:33. |
|
16th March 2019, 12:20 | #6 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Nobody knows how to do it properley in YUV, Gamma is an RGB concept.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? |
4th September 2022, 00:56 | #7 | Link |
French Registered User
Join Date: Aug 2016
Location: France
Posts: 333
|
Hello,
I don't know if I am on the right topic, but I want to change the input levels of a video (don't ask why please, because you don't want to know ), but I would like the exact same result than the VirtualDub filter "levels" with "operate in luma instead of RGB" checked. Apparently, the AviSynth version only expects to have an RGB source and scales the chroma too, not only the luma with YUV sources (the result is colors that are too saturated). How can I avoid this with YUV sources please? Thanks for your help! Sorry, I know that I am an eternal noob |
4th September 2022, 08:50 | #8 | Link |
Registered User
Join Date: Aug 2017
Location: Italy
Posts: 115
|
Not sure if it helps, but http://avisynth.nl/index.php/Ylevels processes only luma
__________________
A channel on S-VHS / VHS capture and AviSynth restoration https://www.youtube.com/channel/UCMs...h1MmNAs7I8nu4g |
4th September 2022, 17:35 | #10 | Link |
French Registered User
Join Date: Aug 2016
Location: France
Posts: 333
|
I don't understand how to use YLevels
I donwloaded the MaskTools2 plugin as it's written, but VirtualDub show me this : Script error: There is no function named 'Ylevels'. In fact, I'm always a bit lost when there is no DLL for a plugin. I just thought that we can use the "YLevels" function the same way that we use the "Levels" function. |
4th September 2022, 18:34 | #11 | Link |
Registered User
Join Date: Mar 2012
Location: Texas
Posts: 1,666
|
Aside from the required plugin you also need the script. You can either save it as an avsi file and put it in the autoload folder. You can also save it and load it manually with Import("ylevels.avs") or you can copy the entire script and put it in the script you are working in.
|
4th September 2022, 19:08 | #12 | Link |
French Registered User
Join Date: Aug 2016
Location: France
Posts: 333
|
OK! Thanks!
So this one? Code:
function Ylevels(clip clp, int a, float gamma, int b, int c, int d) { wicked="x "+string(a)+" - "+string(b)+" "+string(a)+" - / 1 "+string(gamma)+" / ^ "+string(d)+" "+string(c)+" - * "+string(c)+" +" # Reminder: Yexpr = "x a - b a - / 1 gamma / ^ d c - * c +" # return( clp.subtitle(wicked) ) return( clp.YV12LUT(Yexpr = wicked, U=2,V=2) ) } function YlevelsG(clip clp, int a, float gamma, int b, int c, int d) { wicked = gamma > 1.0 \ ? "x "+string(a)+" - "+string(b)+" "+string(a)+" - / 1 "+string(gamma)+" / ^ "+string(d)+" "+string(c)+" - * "+string(c)+" + x * x 255 x - * + 255 /" \ : "x "+string(a)+" - "+string(b)+" "+string(a)+" - / 1 "+string(gamma)+" / ^ "+string(d)+" "+string(c)+" - * "+string(c)+" + 255 x - * x x * + 255 /" return( clp.YV12LUT(Yexpr = wicked, U=2,V=2) ) } function YlevelsS(clip clp, int a, float gamma, int b, int c, int d) { wicked="x "+string(a)+" - "+string(b)+" "+string(a)+" - / 1 "+string(gamma)+" / ^ "+string(d)+" "+string(c)+" - * "+string(c)+" + x 162,97466 / sin 255 * * x 255 x 162,97466 / sin 255 * - * + 255 /" return( clp.YV12LUT(Yexpr = wicked, U=2,V=2) ) } Last edited by SuperLumberjack; 4th September 2022 at 19:11. |
4th September 2022, 19:22 | #13 | Link |
French Registered User
Join Date: Aug 2016
Location: France
Posts: 333
|
It's better but I have this now
Code:
Script error: There is no function named 'YV12LUT'. (C:\Program Files (x86)\AviSynth+\plugins+/YLevels.avsi, line 5) Thank you a lot! Last edited by SuperLumberjack; 4th September 2022 at 19:27. |
4th September 2022, 19:35 | #14 | Link | |
Registered User
Join Date: Mar 2012
Location: Texas
Posts: 1,666
|
Quote:
Here's a link to the wiki: http://avisynth.nl/index.php/Ylevels |
|
Tags |
gamma correction |
Thread Tools | Search this Thread |
Display Modes | |
|
|