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 8th January 2015, 19:13   #1  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
Masktools - disable clipping (e.g. allow luma 235 >>> 240)

Is it possible to set up in the Masktools something like coring off / disable clipping?
Stormborec is offline   Reply With Quote
Old 9th January 2015, 03:37   #2  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,558
Masktools2 (the "mt_" version) has no notion of clipping, it won't clip except to 0 and 255. No idea about old original MaskTools, no one's used that in ten years, but it should act the same way.
foxyshadis is offline   Reply With Quote
Old 9th January 2015, 20:59   #3  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
In that case, I don't understand why blue is stuck at "188 " , no matter how much I turn "x y 16 - 0.2 * +" ...

Code:
a=blankclip(color=$989898)
b=blankclip(color=$b1b1b1)
c=blankclip(color=$cacaca)
d=blankclip(color=$e4e4e4)

interleave(a,b,c,d).converttoyv12

y = converttoy8()
u = utoy8()
v = vtoy8()
y_scaled = y.bicubicresize(width(u), height(u))
y_adjusted = mt_lut(y,expr="x")
u_adjusted = mt_lutxy(u,y_scaled,expr="x y 16 -  0.2 * +")
v_adjusted = mt_lutxy(v,y_scaled,expr="x y 16 - -0.077 * +")
ytouv(u_adjusted,v_adjusted,y_adjusted)


converttorgb.rgbadjust(1.1,1,0.73772,analyze=true)

Last edited by Stormborec; 9th January 2015 at 21:06.
Stormborec is offline   Reply With Quote
Old 9th January 2015, 23:37   #4  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,558
Well, in your RGBAdjust, 0.73772 * 255 is 188, so I think you have your answer right there.

As for masktools, the maximum Y is 255, and your chroma is always neutral (128), so the maximum output of "(Y - 16) * 0.2 + 128" is 175.8. If you change 0.2 to 1, or you test with colored blank clips, you can easily get 255. Try:

Code:
orignum = stackvertical(y.subluma,StackHorizontal(u.subluma,v.subluma))
adjustednum = stackvertical(y_adjusted.subluma,StackHorizontal(u_adjusted.subluma,v_adjusted.subluma))

function subluma(clip c) {
  return ScriptClip(c, "Subtitle(String(AverageLuma))")
}

Last edited by foxyshadis; 9th January 2015 at 23:40.
foxyshadis is offline   Reply With Quote
Old 10th January 2015, 11:14   #5  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
I do not know if I understand exactly ...
But I already know what the problem is:

188 / 0.73772 >>> 255

converttorgb guilelessly cuts to 0 255 ...
Stormborec is offline   Reply With Quote
Old 11th January 2015, 04:55   #6  |  Link
Asmodian
Registered User
 
Join Date: Feb 2002
Location: San Jose, California
Posts: 4,406
Quote:
Originally Posted by Stormborec View Post
converttorgb guilelessly cuts to 0 255 ...
If I understand this isn't it as simple as the .rgbadjust(1.1,1,0.73772,analyze=true) converting the 255 output from ConvertToRGB to 188? This is what would have to happen as ConvertToRGB would convert to legal range RGB values (0-255) and 255*0.73772 = 188. You wouldn't expect a >255 value for blue out of ConvertToRGB would you?
Asmodian is offline   Reply With Quote
Old 11th January 2015, 06:06   #7  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 308
Adding on a bit to Asmodian's post, Avisynth natively supports only 8-bpc colour formats. With eight bits, a maximum of 256 values are valid, and by convention these are taken to be the integers between 0 and 255, inclusive.

If anywhere in your filter chain a filter produces a value that exceeds these limits, it has to either wrap or saturate. The former is generally not a very useful option in image processing, but either way, your pixel values will always lie between 0 and 255.

Taking a simple example, say you want to multiply every pixel's value by 2, then divide that by 2. If you do both steps within the same filter (e.g. mt_lut("x 2 * 2 /")) you end up with the original frame under some reasonable assumptions. But if you do the steps in different filters (e.g. mt_lut("x 2 *").mt_lut("x 2 /")), the values will have been clipped by the first filter and this will never produce a result greater than 127.
__________________
Say no to AviSynth 2.5.8 and DirectShowSource!
colours is offline   Reply With Quote
Old 11th January 2015, 11:20   #8  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
This is exactly what I wanted to ask ...
How Avisynth works internally in the chain of filters?
If I have e.g.:
avisource.tweak.coloryuv

is it:
clip(yuv=intiger values)
-> tweak -> clip(yuv=intiger values)
-> coloryuv -> clip(yuv=intiger values)

or:
clip(yuv=intiger values)
-> tweak -> (yuv=float/or something else values)
-> coloryuv -> clip(yuv=intiger values)
Stormborec is offline   Reply With Quote
Old 11th January 2015, 14:25   #9  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Code:
Tweak(clip clip [, float hue] [, float sat] [, float bright] [, float cont] [, bool coring] [, bool sse] [, float startHue] [, float endHue] [, float 
maxSat] [, float minSat] [, float interp] [, bool dither])
http://avisynth.nl/index.php/Tweak

Code:
ColorYUV(clip [, float gain_y] [, float off_y] [, float gamma_y] [, float cont_y] [, float gain_u] [, float off_u] [, float gamma_u] [, float 
cont_u] [, float gain_v] [, float off_v] [, float gamma_v] [, float cont_v] [, string levels] [, string opt] [, boolean showyuv] [, boolean 
analyze] [, boolean autowhite] [, boolean autogain] [, boolean conditional])
http://avisynth.nl/index.php/ColorYUV

Although above ColorYUV parameters given as Float, that is only so that ColorYUV will not complain if you provide Float instead of Int,
Float parameters will accept Integer arguments, whereas if specified as Int parameters it would only accept Int and not float.
So for ColorYUV, args should be Integer values only but could be given as Floats. (eg 128 or 128.0 but not 128.5)
__________________
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; 11th January 2015 at 14:37.
StainlessS is offline   Reply With Quote
Old 11th January 2015, 15:11   #10  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
I think he asks about the output format of the filters. Every output of a filter is always in YUV [0,255] or RGB [0,255] (integer values for both, so it's the first scenario).

Last edited by Wilbert; 11th January 2015 at 15:14.
Wilbert is offline   Reply With Quote
Old 11th January 2015, 15:20   #11  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
OOps, thank you Wilbert.
__________________
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; 11th January 2015 at 15:32.
StainlessS is offline   Reply With Quote
Old 11th January 2015, 15:47   #12  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
uh, wanna avoid domain limit?
0-65535 should be enough to store 0-255 with some over/underflow?
use dither_lut16 on 8bpc clips wisely to do that dirty little work
here's an example,
let's separate x * 2 / 2 to x * 2 and x /2 and keep the result free from rounding errors
Code:
dither_convert_8_to_16 ()
dither_lut16 ("x 256 /")
dither_lut16 ("x 2 *")
dither_lut16 ("x 2 /")
dither_lut16 ("x 256 *")
ditherpost (mode=-1)
should be identical to
Code:
mt_lut ("x 2 * 2 /")
EDIT: example 2: how to deal with both overflow and underflow
Code:
dither_convert_8_to_16 ()
dither_lut16 ("x 256 / 128 - 32768 +")
#expressions here
dither_lut16 ("x 32768 - 128 + 256 *")
ditherpost (mode=-1)
EDIT2: you can always overcome domain issues if you can get some tools with domain large enough to work

Last edited by feisty2; 11th January 2015 at 16:14.
feisty2 is offline   Reply With Quote
Old 11th January 2015, 17:48   #13  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
Yes, I meant format, which gives one filter to the next in the chain ...


It follows that it is better to do much as possible in one step?
http://forum.doom9.org/showthread.ph...61#post1379661

So better than coloryuv(cont_u=1...).mt_lutxy(.....) ..... just mt_lutxy(x 128 - 1... * 128 + .....)


I found, that it let me go up to yuv 255,255,255 - this is also retained if I do compresion to xvid avi using virtualdub.

BlankClip(pixel_type="yv12",color=$ffffff)
mt_lut("x 500 +",u=3,v=3)

coloryuv(analyze=true)

Last edited by Stormborec; 11th January 2015 at 18:01.
Stormborec is offline   Reply With Quote
Old 11th January 2015, 17:57   #14  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
You can do things in several steps, but you need a large domain tool to store under/overflow values
Like I wrote at #12
feisty2 is offline   Reply With Quote
Old 11th January 2015, 18:41   #15  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
Yes it's clear. I try to do things as much simple as possible - then it's obviously fast and less rounded ..
Stormborec is offline   Reply With Quote
Old 11th January 2015, 23:00   #16  |  Link
Stormborec
Registered User
 
Join Date: Feb 2013
Posts: 161
Your advice in one script :

Code:
function x( clip last, float "ou", float "ov", float "su", float "sv", float "thr", float "str" )

{

ou   = default(ou, 0.0)
ov   = default(ov, 0.0)
su   = default(su, 1.0)
sv   = default(sv, 1.0)
thr  = default(thr, 0.5)
str  = default(str, 1.51)

y = converttoy8()
u = utoy8()
v = vtoy8()
y_scaled = y.bilinearresize(width(u), height(u))
y_adjusted = mt_lutxy(y,y.blur(thr),"x x y - abs 4 / 1 4 / ^ 4 * "+string(str)+" * x y - x y - abs 1.001 + / * +",U=2,V=2)
u_adjusted = mt_lutxy(u,y_scaled,expr="x 128 - "+string(su)+" * 128 + y 16 - "+string(ou)+" * + ")
v_adjusted = mt_lutxy(v,y_scaled,expr="x 128 - "+string(sv)+" * 128 + y 16 - "+string(ov)+" * + ")
ytouv(u_adjusted,v_adjusted,y_adjusted)

return last

}
Stormborec is offline   Reply With Quote
Reply

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 13:11.


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