View Full Version : Filtering part of a frame - how can I shorten this?
Comatose
27th March 2008, 13:15
It's not long, it's just messy.
overlay(Crop(390,520,-230,-350).fft3dfilter(sigma=8,plane=4),x=390,y=520)
I'd like to shorten that into something like FilterPart(fft3dfilter(sigma=8,plane=4),390,520,-230,-350) but I'm not sure how to make it run the filter on just that part.
I came up with this, but it runs the filter on the entire image and then crops, which is obviously inefficient:
function FilterPart(clip c, clip filter, int left, int top, int right, int bottom) {
return c.overlay(filter.crop(left,top,right,bottom),x=left,y=top)
}
Gavino
27th March 2008, 17:42
Try something like this:
function FilterPart(clip c, string filter, string args, int left, int top, int right, int bottom) {
part = Crop(c, left, top, right, bottom)
filtered = Eval(filter+"(part,"+args+")")
return Overlay(c, filtered, x=left, y=top)
}
Then for your example use:
FilterPart("fft3dfilter","sigma=8,plane=4",390,520,-230,-350)
The arguments to the underlying filter are passed all together as a string which is evaluated inside FilterPart. This leads to a couple of quirks (not a problem in your example though):
1) if any argument is itself a string literal, you would need to use triple quotes for the argument list, eg
FilterPart("Invert", """channels="Y"""", ... )
2) any variables used in the list must be global ones, eg to use
FilterPart("fft3dfilter","sigma=s,plane=4", ...)
s must be global, or else you need to change it to
FilterPart("fft3dfilter","sigma="+string(s)+",plane=4", ...)
which is getting back to being, well, messy. :)
Gavino
28th March 2008, 22:13
Just realised my earlier attempt can be improved, using a single string parameter to hold both the filter name and its arguments.
function FilterPart(clip c, string filter, int left, int top, int right, int bottom) {
Crop(c, left, top, right, bottom)
filtered = Eval(filter) # using implicit 'last'
return Overlay(c, filtered, x=left, y=top)
}
Then Comatose's example becomes simply:
FilterPart("fft3dfilter(sigma=8,plane=4)",390,520,-230,-350)
more like originally requested.
Comatose
29th March 2008, 00:22
Woo, thanks! :D
The first thing I did was think of an eval function, but sadly the wiki doesn't say anything about it (http://avisynth.org/mediawiki/Eval) so I thought it doesn't exist. (I just added it)
stickboy
29th March 2008, 07:11
The documentation that comes with AviSynth is generally of better quality and is more complete than the wiki.
gzarkadas
29th March 2008, 09:02
@Comatose,
The wiki does say about Eval (http://avisynth.org/mediawiki/Internal_functions/Control_functions), only that it does it in another section, inside the AviSynth syntax (as the official documentation that comes with AviSynth does also).
When you can't find something at Internal filters (http://avisynth.org/mediawiki/Internal_filters) look for it at Internal functions (http://avisynth.org/mediawiki/Internal_functions) ;).
TSchniede
29th March 2008, 13:57
I think overlay is slow for merely copying a small clip into the other. I use this:
function insertXY(clip wholeClip, clip insertclip, int x, int y, int "x1",int "y1",int "x2",int "y2"){
w=insertclip.width()
h=insertclip.height()
x1=default(x1,0)
x2=default(x2,0)
y1=default(y1,0)
y2=default(y2,0)
wholeClip
return stackvertical(crop(x1,y1,-x2,y),stackhorizontal(crop(x1,y,x,h),insertclip,crop(x+w,y,-x2,h)),crop(x1,y+h,-x2,-y2))
}
Gavino
2nd April 2008, 21:54
I think overlay is slow for merely copying a small clip into the other. I use this:
function insertXY(clip wholeClip, clip insertclip, int x, int y, int "x1",int "y1",int "x2",int "y2"){
w=insertclip.width()
h=insertclip.height()
x1=default(x1,0)
x2=default(x2,0)
y1=default(y1,0)
y2=default(y2,0)
wholeClip
return stackvertical(crop(x1,y1,-x2,y),stackhorizontal(crop(x1,y,x,h),insertclip,crop(x+w,y,-x2,h)),crop(x1,y+h,-x2,-y2))
}
Note that this won't work when either x or y is zero.
First rule of function testing: check the boundary cases!
TSchniede
9th April 2008, 18:00
I know, I just haven't found a way to do that isn't quite elaborate and my usual application (logo-removal) works even in it's current simple way.
To be precise, no crop may have a width or height less than 1 or 2 depending on color format.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.