View Full Version : masking dark areas
~ VEGETA ~
14th September 2015, 11:43
I'd like to ask about masking dark areas, like the following mask:
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:
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 ~
14th September 2015, 11:59
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.
StainlessS
14th September 2015, 14:08
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:
mask = Levels(50,1,80,255,0,coring=true)
A and B below are same (EDIT: for Luma)
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().
~ VEGETA ~
14th September 2015, 23:17
In this line:
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:
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
StainlessS
15th September 2015, 00:33
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.
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.php?p=1722512#post1722512
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
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.
~ VEGETA ~
15th September 2015, 05:24
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:
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.
Gavino
15th September 2015, 09:40
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.php?p=1722512#post1722512
See also post #49 (http://forum.doom9.org/showpost.php?p=1722885&postcount=49) from the same thread.
StainlessS
15th September 2015, 13:52
you mean it is equal to this:
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.
colours
15th September 2015, 14:18
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.
StainlessS
15th September 2015, 15:13
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. :(
~ VEGETA ~
15th September 2015, 16:02
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...
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.
Reel.Deel
15th September 2015, 16:48
ok, type the mt_lut equivalent of the previous levels() line, this would be good help.
Use YLevels (http://avisynth.nl/index.php/Ylevels).
~ VEGETA ~
16th September 2015, 05:31
Use YLevels (http://avisynth.nl/index.php/Ylevels).
I read this in its page:
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.
:thanks:
colours
16th September 2015, 09:02
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.
StainlessS
17th September 2015, 15:10
Here a simple script to show differences between original and modified clip:
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
S = "(x>=" + String(TARGET) + ") ? " + String(SWAP) + " : x"
~ VEGETA ~
18th September 2015, 13:43
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.
StainlessS
19th September 2015, 04:23
Perhaps this might assist, lets you view various edge masks. Change Name to one of supplied Mt_Edge Mode names.
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.
~ VEGETA ~
8th November 2015, 13:31
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:
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.
raffriff42
8th November 2015, 17:19
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... :)
https://www.dropbox.com/s/4wo5a6rlieffb98/Diff-x10.png?raw=1
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)
}
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.