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 14th September 2015, 11:43   #1  |  Link
~ VEGETA ~
The cult of personality
 
~ VEGETA ~'s Avatar
 
Join Date: May 2013
Location: Planet Vegeta
Posts: 94
masking dark areas

I'd like to ask about masking dark areas, like the following mask:

Code:
 mask = Invert().Levels(128,1,191,0,255,coring=true)
If not inverted, would it affect bright areas rather than dark ones? I guess that it will.

But isn't it the same as doing this:

Code:
 mask = Levels(50,1,80,255,0,coring=true)
here it gives 255 to 50 or below (dark, isn't it?) and 0 (no filtering) to 80 or above... and it is a graduate in between.

Am I right or not? please explain if there are better methods.
~ VEGETA ~ is offline   Reply With Quote
Old 14th September 2015, 11:59   #2  |  Link
~ VEGETA ~
The cult of personality
 
~ VEGETA ~'s Avatar
 
Join Date: May 2013
Location: Planet Vegeta
Posts: 94
I want to see just the mask itself, how is that done via masktools2? I saw some lutxy examples but no images.

something like an edge mask, but the output video should just show the pixels affected/included by the mask. as well as other types of masks.
~ VEGETA ~ is offline   Reply With Quote
Old 14th September 2015, 14:08   #3  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,656
Quote:
Originally Posted by ~ VEGETA ~ View Post
Code:
 mask = Invert().Levels(128,1,191,0,255,coring=true)
If not inverted, would it affect bright areas rather than dark ones? I guess that it will.

But isn't it the same as doing this:

Code:
 mask = Levels(50,1,80,255,0,coring=true)
A and B below are same (EDIT: for Luma)
Code:
Avisource("E:\v\xmen2.avi")
A = Invert().Levels(128     ,1 ,191        ,0,255,coring=False)
B =          Levels(255-128 ,1 ,255-191    ,0,255,coring=False)
L=StackVertical(A,B)
D=Subtract(A,B)
R=StackVertical(D,D)
StackHorizontal(L,R)
ALWAYS use coring=False when doing those kind of manipulations with Levels().
__________________
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; 17th September 2015 at 13:11.
StainlessS is offline   Reply With Quote
Old 14th September 2015, 23:17   #4  |  Link
~ VEGETA ~
The cult of personality
 
~ VEGETA ~'s Avatar
 
Join Date: May 2013
Location: Planet Vegeta
Posts: 94
In this line:

Code:
B =          Levels(255-128 ,1 ,255-191    ,0,255,coring=False)
the input_low equals 127 and the input_high is 64 which is inverted. How will levels map the 0 and 255 values to them in this case? I mean, what is the reason for putting values like this?

Why using coring = false always?

what about doing this:

Code:
B = Levels(64 ,1 ,128 ,255, 0 ,coring=False)
here it puts 255 to 64 and below, and 0 to 128 and above, meaning: process dark areas right? Will your line do the same? This is what I want to understand.


And, what about my previous question about showing masked pixels only (in above post)?

What is the purpose of stackvertical/subtract/stackhorizontal lines that you wrote here?

thanks

Last edited by ~ VEGETA ~; 14th September 2015 at 23:19.
~ VEGETA ~ is offline   Reply With Quote
Old 15th September 2015, 00:33   #5  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,656
Quote:
In this line:

Code:

B = Levels(255-128 ,1 ,255-191 ,0,255,coring=False)

the input_low equals 127 and the input_high is 64 which is inverted. How will levels map the 0 and 255 values to them in this case? I mean, what is the reason for putting values like this?
That does exactly as you wrote, only the Invert() is done via the 255-x thing.
Plot input_lo,output_lo and input_hi,output_hi and join points with a straight line to visualize result.

Quote:
Why using coring = false always?
Because coring=true, first subtracts 16 from input levels, does the calculations and then adds 16 back to results, ie it messes with your carefully
chosen numbers and does it's own thing, I dont like that, do it if you wish but results depend somewhat on pot luck. http://forum.doom9.org/showthread.ph...12#post1722512

Quote:
What is the purpose of stackvertical/subtract/stackhorizontal lines that you wrote here?
Purpose to show results are identical, why did you not try it yourself, then you would not have to ask.

Previous snippets were not creating a binary mask, but eg this would

Code:
    Levels(127,1.0,128,0,255,coring=false)
where everything 127 and below -> 0, everything 128 and above -> 255.

As for the rest, you really need to say what you are trying to achieve, perhaps in a new thread
(EDIT: In avisynth usage/newbie section of forum).

EDIT: Fixed above, was "Plot input_lo,output_hi and input_hi,output_hi"
Link given by Gavino (2 posts below) is better link than one given above.
__________________
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; 15th September 2015 at 13:41.
StainlessS is offline   Reply With Quote
Old 15th September 2015, 05:24   #6  |  Link
~ VEGETA ~
The cult of personality
 
~ VEGETA ~'s Avatar
 
Join Date: May 2013
Location: Planet Vegeta
Posts: 94
Quote:
That does exactly as you wrote, only the Invert() is done via the 255-x thing.
Plot input_lo,output_hi and input_hi,output_hi and join points with a straight line to visualize result.
you mean it is equal to this:

Code:
B = Levels(64 ,1 ,128 ,255, 0 ,coring=False)
If so, then it is better to easier this way. I mean rather than using invert(), put 255,0 to make 64 and below 255 and so on. I know about binary masks, I use mt_binarize for it.

No need really for a new thread because it is about masktools2. I need to make masks for dark,bright areas... I know how to do it but wanted to verify the Levels thing above. I also want to be able to see the pixels only affected by the mask... to see if it is good or not.
~ VEGETA ~ is offline   Reply With Quote
Old 15th September 2015, 09:40   #7  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
Quote:
Originally Posted by StainlessS View Post
Because coring=true, first subtracts 16 from input levels, does the calculations and then adds 16 back to results, ie it messes with your carefully
chosen numbers and does it's own thing, I dont like that, do it if you wish but results depend somewhat on pot luck. http://forum.doom9.org/showthread.ph...12#post1722512
See also post #49 from the same thread.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 15th September 2015, 13:52   #8  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,656
Quote:
Originally Posted by ~ VEGETA ~ View Post
you mean it is equal to this:

Code:
B = Levels(64 ,1 ,128 ,255, 0 ,coring=False)
Yes, except that 255-128 is 127 not 128.

Gavino provided link above provides probably the best description of Levels 'weirdness' that is available on-site.
__________________
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 ???
StainlessS is offline   Reply With Quote
Old 15th September 2015, 14:18   #9  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 312
The hell are you people doing, posting Levels in a MaskTools thread?

Just use mt_lut. It's faster, more flexible, and the syntax isn't retarded.
__________________
Say no to AviSynth 2.5.8 and DirectShowSource!
colours is offline   Reply With Quote
Old 15th September 2015, 15:13   #10  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,656
Colours is correct, recent posts from #564 could be moved to a new thread (to Usage, if a moderator could oblige).
Also last three posts could be removed (incl this one).

Most posts in this thread should not actually be here in the developer section, MVTools (EDIT: MaskTools) should also have a section in Avisynth Usage,
but a bit late to suggest that now.
__________________
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 September 2015 at 10:18.
StainlessS is offline   Reply With Quote
Old 15th September 2015, 16:02   #11  |  Link
~ VEGETA ~
The cult of personality
 
~ VEGETA ~'s Avatar
 
Join Date: May 2013
Location: Planet Vegeta
Posts: 94
Quote:
Originally Posted by StainlessS View Post
Yes, except that 255-128 is 127 not 128.

Gavino provided link above provides probably the best description of Levels 'weirdness' that is available on-site.
hhh ok it is 127...

Code:
The hell are you people doing, posting Levels in a MaskTools thread?

Just use mt_lut. It's faster, more flexible, and the syntax isn't retarded.
ok, type the mt_lut equivalent of the previous levels() line, this would be good help.
~ VEGETA ~ is offline   Reply With Quote
Old 15th September 2015, 16:48   #12  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,084
Quote:
Originally Posted by ~ VEGETA ~ View Post
ok, type the mt_lut equivalent of the previous levels() line, this would be good help.
Use YLevels.
Reel.Deel is offline   Reply With Quote
Old 16th September 2015, 05:31   #13  |  Link
~ VEGETA ~
The cult of personality
 
~ VEGETA ~'s Avatar
 
Join Date: May 2013
Location: Planet Vegeta
Posts: 94
Quote:
Originally Posted by Reel.Deel View Post
Use YLevels.
I read this in its page:

Quote:
It lets you choose different gamma curves, e.g. to boost dark areas without washing out bright ones.
So it processes only luma which is what we want right? it says in the quote "boost dark areas without washing out bright ones"... now what does this mean?

I mean, it depends on the chosen values. I can use it with dark areas, and bright ones.

__

My other question: Is there a way to see the areas/pixels only affected by a mask?

i.e, doing an edge mask/dark areas mask and wants to see just the affected pixels from it... this is to refine the mask options and stuff.

~ VEGETA ~ is offline   Reply With Quote
Old 16th September 2015, 09:02   #14  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 312
Depends on what you want the not-masked areas of the picture to look like. Maybe try mt_merge(blankclip(source), source, mask, luma=true)? Or heck, just check the mask clip on its own, and have a separate tab for the original video so you can quickly flip back and forth.
__________________
Say no to AviSynth 2.5.8 and DirectShowSource!
colours is offline   Reply With Quote
Old 17th September 2015, 15:10   #15  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,656
Here a simple script to show differences between original and modified clip:
Code:
Avisource("E:\V\StarWars.avi")
########### Config
AMP   = True     # AMP/Show difference clip is Amplified if True
SHOW  = False    # AMP/Show difference clip shows dimmed original background if True
    
TARGET= 180      # Y = (Y >= TARGET) ? SWAP : Y
SWAP  = 180      #
###########
ORG=Last
S = RT_string("(x>=%d) ? %d : x",TARGET,SWAP)               # RT_Stats required to construct string (infix notation)
P = MT_Polish(S)                                            # Convert Infix notation to RPN for Masktools 
Changed = MT_lut(P,U=2,V=2)                                 # Change Y: Above TARGET->SWAP : Chroma untouched

D1=ClipDelta(ORG,Changed)
D2=ClipDelta(ORG,Changed,Amp=AMP,Show=SHOW)

Top= StackHorizontal(ORG.SubTitle("Original"),Changed.SubTitle("Changed"))
Bot= StackHorizontal(D1.Subtitle("Subtract(ie difference)"),D2.Subtitle("AMP/Show"))
Return StackVertical(Top,Bot)


# Return Clip Difference of input clips (amp==true = Amplified, show==true = show background)
Function ClipDelta(clip clip1,clip clip2,bool "amp",bool "show") {
    amp=Default(amp,false)
    show=Default(show,false)
    c2=clip1.levels(128-32,1.0,128+32,128-32,128+32).greyscale()
    c1=clip1.subtract(clip2)
    c1=(amp)?c1.levels(127,1.0,129,0,255):c1
    return (show)?c1.Merge(c2):c1
}
EDIT: Alternative to RT_String without RT_Stats requirement
Code:
S = "(x>=" + String(TARGET) + ") ? " + String(SWAP) + " : x"
__________________
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; 17th September 2015 at 20:13.
StainlessS is offline   Reply With Quote
Old 18th September 2015, 13:43   #16  |  Link
~ VEGETA ~
The cult of personality
 
~ VEGETA ~'s Avatar
 
Join Date: May 2013
Location: Planet Vegeta
Posts: 94
I've been trying to make a good edge mask, but I am not satisfied yet. I want to make a very fine sharp edge mask (mask1) and another edge mask which expands to include the noise near the edges (mask2).

then use mask1 for say sharpening, and make then subtract mask1 from mask2 (so the areas of near noise still in the result) and do some denoising there.

If there is a good suggestion, please give it to me.
~ VEGETA ~ is offline   Reply With Quote
Old 19th September 2015, 04:23   #17  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,656
Perhaps this might assist, lets you view various edge masks. Change Name to one of supplied Mt_Edge Mode names.

Code:
Avisource("E:\v\StarWars.avi")

# Mt_edge available modes
# "sobel", "roberts", "laplace", "hprewitt", "prewitt", "cartoon","min/max"

#Name="sobel"
#Name="roberts"
#Name="laplace"
#Name="hprewitt"
Name="prewitt"
#Name="cartoon"
#Name="min/max"

TestEdge(Name)    

return Last


Function TestEdge(clip c,String "Name") {   # Uses only default args apart from mode Name
    Name=Default(Name,"sobel")
    edge    = c.Mt_Edge(Mode=Name,U=-128,V=-128)
    expand  = edge.Mt_Expand(U=-128,V=-128)
    inpand  = edge.Mt_InPand(U=-128,V=-128)
    inflate = edge.Mt_Inflate(U=-128,V=-128)
    deflate = edge.Mt_deflate(U=-128,V=-128)
    Stack6(c,expand,inflate,edge,inpand,deflate,"Original","Expand","Inflate",Name,"Inpand","Deflate")
}

Function Stack2(clip c1,clip c2,string "s1",string "s2") {
    c1 = (s1.defined)?c1.Subtitle(s1):c1    c2 = (s2.defined)?c2.Subtitle(s2):c2  return StackHorizontal(c1,c2)
}

Function Stack4(clip c1,clip c2,clip c3,clip c4,string "s1",string "s2",string "s3",string "s4") {
    c1 = (s1.defined)?c1.Subtitle(s1):c1    c2 = (s2.defined)?c2.Subtitle(s2):c2
    c3 = (s3.defined)?c3.Subtitle(s3):c3    c4 = (s4.defined)?c4.Subtitle(s4):c4
    return StackVertical(StackHorizontal(c1,c2),StackHorizontal(c3,c4))
}

Function Stack6(clip c1,clip c2,clip c3,clip c4,clip c5, clip c6,string "s1",string "s2",string "s3",string "s4",string "s5",string "s6") {
    c1 = (s1.defined)?c1.Subtitle(s1):c1    c2 = (s2.defined)?c2.Subtitle(s2):c2
    c3 = (s3.defined)?c3.Subtitle(s3):c3    c4 = (s4.defined)?c4.Subtitle(s4):c4
    c5 = (s5.defined)?c5.Subtitle(s5):c5    c6 = (s6.defined)?c6.Subtitle(s6):c6
    return StackVertical(StackHorizontal(c1,c2,c3),StackHorizontal(c4,c5,c6))
}
EDIT: Changed clip order.
__________________
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; 19th September 2015 at 04:33.
StainlessS is offline   Reply With Quote
Old 8th November 2015, 13:31   #18  |  Link
~ VEGETA ~
The cult of personality
 
~ VEGETA ~'s Avatar
 
Join Date: May 2013
Location: Planet Vegeta
Posts: 94
StainlessS: I tried ClipDelta, but it doesn't do what I want, perhaps I didn't explain well. I wanted something very simple like this:

Quote:
ffvideosource("....")

ORG=Last
Changed = ORG.SMDegrain().Gradfun3(thr=2) #trial only


return Changed.subtract(org)
this is to show the difference between clip 1 and clip 2, meaning, what has changed when I filter clip 1? or what is the difference between original and encoded video. << like that.

but this subtract function shows grey background all the times unless I REALLY change saturation... I wanted a more accurate one. One that shows the colored pixels and details... like when you show the pixels affected by an edgemask for example.
~ VEGETA ~ is offline   Reply With Quote
Old 8th November 2015, 17:19   #19  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,377
Quote:
Originally Posted by ~ VEGETA ~ View Post
but this subtract function shows grey background all the times unless I REALLY change saturation... I wanted a more accurate one.
Try this 1 weird trick...

Code:
Colorbars
BilinearResize(Width/4, Height/4)
ConvertToYV12
org=Last.Letterbox(8, 8, 8, 8)
Changed1=org.Tweak(sat=1.01)
Changed2=org.Tweak(hue=1)

return StackVertical(
\ StackHorizontal(
\    org,
\    Changed1.Subtitle("Tweak(sat=1.01)"),
\    Changed1.subtract(org)
\            .Subtitle("Diff x 1"),
\    Changed1.subtract(org)
\            .ColorYUV(cont_u=f2cuv(10), cont_v=f2cuv(10))
\            .Subtitle("Diff x 10")
\   ),
\ StackHorizontal(
\    org,
\    Changed2.Subtitle("Tweak(hue=1)"),
\    Changed2.subtract(org)
\            .Subtitle("Diff x 1"),
\    Changed2.subtract(org)
\            .ColorYUV(cont_u=f2cuv(10), cont_v=f2cuv(10))
\            .Subtitle("Diff x 10")
\   )
\ )

## rescale "normal" arguments for ColorYUV
function f2cuv(float f) {
    return Round((f - 1.0) * 256.0) 
}

Last edited by raffriff42; 17th March 2017 at 00:00. Reason: (fixed image link)
raffriff42 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 03:13.


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