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.

 Register FAQ Calendar Search Today's Posts Mark Forums Read

7th January 2011, 13:35   #1  |  Link
Dogway
Registered User

Join Date: Nov 2009
Posts: 1,954

Im trying to make a function for masking based on luma (from this post). I tried to convert it to masktools2 and inverse the mask effect (now it affects to bright areas). I would like to make a bool operator for chossing whether bright or dark areas, and another one where I can define by a string the filter I want to apply to chosen area.

Quote:
 function LumaMask(clip input, int "black", int "white", string "lumamask", string "filter"){ LO = string(default(black, 24)) HI = string(default(white, 48)) luma =lumamask filt = string(filter) darkM = input.mt_lut("x "+LO+" < 255 x "+HI+" > 0 255 x "+LO+" - 255 "+HI+" "+LO+" - / * - ? ?",U=2,V=2) brightM = input.mt_lut("x "+LO+" < 0 x "+HI+" > 255 0 x "+LO+" - 255 "+LO+" "+HI+" - / * - ? ?",U=2,V=2) filter = input.filt mt_merge(input, filter, luma, U=3,V=3) return last }
__________________
i7-4790K@Stock::GTX 1070] AviSynth+ filters and mods on GitHub + Discussion thread

Last edited by Dogway; 7th January 2011 at 13:50.

 7th January 2011, 14:35 #2  |  Link Didée Registered User   Join Date: Apr 2002 Location: Germany Posts: 5,393 You're thinking too complicated. To reverse the whole logic to "leave dark untouched, filter bright", you just swap the clip arguments of mt_merge. FitY2UV doesn't exist anymore. In exchange, mt_merge now has the toggle "luma=true/false". When true, luma mask is used for the UV channels, too. String evaluation is of course possible. But why? I don't see any benefit to declare filtersting="""MyFilter(with,"some",parameter)""" before, and use some doggerel result = Eval( string(clip) + filterstring ) in the function, when you can as well directly use a clip: filter=MyFilter(with,"some",parameter), and simply use result = filter in the function. (You need string evaluation if you want to apply a filter to something that is constructed only in the function. But not for a basic input clip that gets used as-is.) Code: ```function drkbrgtfltr(clip input, clip filtered, int "black", int "white", bool "darkfilt") { LO = string(default(black, 24)) HI = string(default(white, 48)) darkfilt = default(darkfilt,true) darkmask = input.mt_lut("x "+LO+" < 255 x "+HI+" > 0 255 x "+LO+" - 255 "+HI+" "+LO+" - / * - ? ?",U=1,V=1) darkfilt ? mt_merge(input, filtered, darkmask, luma=true, U=3,V=3) \ : mt_merge(filtered, input, darkmask, luma=true, U=3,V=3) return last }``` __________________ - We´re at the beginning of the end of mankind´s childhood - My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!) Last edited by Didée; 7th January 2011 at 15:14. Reason: on darkmask creation, U=1,V=1 is sufficient
 7th January 2011, 15:00 #3  |  Link Dogway Registered User   Join Date: Nov 2009 Posts: 1,954 Oh thanks for the input! looks I was close... :P the first thing I tried was swaping but I got a green screen that's why all the thinking afterwards. Yes, define the filter outside function might be better, less hassle I guess. __________________ i7-4790K@Stock::GTX 1070] AviSynth+ filters and mods on GitHub + Discussion thread
7th January 2011, 15:15   #4  |  Link
Gavino
Avisynth language lover

Join Date: Dec 2007
Location: Spain
Posts: 3,420
Quote:
 Originally Posted by Dogway Yes, define the filter outside function might be better, less hassle I guess.
I agree, but if you really want to pass in a filter string, the simplest way to do it would be to replace "clip filtered" by "string filterString" in the function definition, then at the start of the function, add
Code:
```input
filtered=Eval(filterString)```
__________________
GScript and GRunT - complex Avisynth scripting made easier