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. |
27th March 2008, 13:15 | #1 | Link |
Registered User
Join Date: Dec 2007
Posts: 639
|
Filtering part of a frame - how can I shorten this?
It's not long, it's just messy.
Code:
overlay(Crop(390,520,-230,-350).fft3dfilter(sigma=8,plane=4),x=390,y=520) I came up with this, but it runs the filter on the entire image and then crops, which is obviously inefficient: Code:
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) } |
27th March 2008, 17:42 | #2 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Try something like this:
Code:
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) } Code:
FilterPart("fft3dfilter","sigma=8,plane=4",390,520,-230,-350) 1) if any argument is itself a string literal, you would need to use triple quotes for the argument list, eg Code:
FilterPart("Invert", """channels="Y"""", ... ) Code:
FilterPart("fft3dfilter","sigma=s,plane=4", ...) Code:
FilterPart("fft3dfilter","sigma="+string(s)+",plane=4", ...) |
28th March 2008, 22:13 | #3 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Just realised my earlier attempt can be improved, using a single string parameter to hold both the filter name and its arguments.
Code:
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) } Code:
FilterPart("fft3dfilter(sigma=8,plane=4)",390,520,-230,-350) |
29th March 2008, 00:22 | #4 | Link |
Registered User
Join Date: Dec 2007
Posts: 639
|
Woo, thanks!
The first thing I did was think of an eval function, but sadly the wiki doesn't say anything about it so I thought it doesn't exist. (I just added it) |
29th March 2008, 09:02 | #6 | Link |
Registered User
Join Date: Sep 2005
Location: 100011110010001000001 10000011111111000001
Posts: 221
|
@Comatose,
The wiki does say about Eval, 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 look for it at Internal functions .
__________________
AVSLib, a free extension library for Avisynth. Current version: 1.1.0 (beta), 14/05/2007. [ Home page | Download page ] |
29th March 2008, 13:57 | #7 | Link |
Registered User
Join Date: Aug 2006
Posts: 77
|
I think overlay is slow for merely copying a small clip into the other. I use this:
Code:
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)) } |
2nd April 2008, 21:54 | #8 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
First rule of function testing: check the boundary cases! |
|
9th April 2008, 18:00 | #9 | Link |
Registered User
Join Date: Aug 2006
Posts: 77
|
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. |
Thread Tools | Search this Thread |
Display Modes | |
|
|