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 27th March 2008, 13:15   #1  |  Link
Comatose
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'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:
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)
}
Comatose is offline   Reply With Quote
Old 27th March 2008, 17:42   #2  |  Link
Gavino
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)
}
Then for your example use:
Code:
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
Code:
FilterPart("Invert", """channels="Y"""", ... )
2) any variables used in the list must be global ones, eg to use
Code:
FilterPart("fft3dfilter","sigma=s,plane=4", ...)
s must be global, or else you need to change it to
Code:
FilterPart("fft3dfilter","sigma="+string(s)+",plane=4", ...)
which is getting back to being, well, messy.
Gavino is offline   Reply With Quote
Old 28th March 2008, 22:13   #3  |  Link
Gavino
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)
}
Then Comatose's example becomes simply:
Code:
FilterPart("fft3dfilter(sigma=8,plane=4)",390,520,-230,-350)
more like originally requested.
Gavino is offline   Reply With Quote
Old 29th March 2008, 00:22   #4  |  Link
Comatose
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)
Comatose is offline   Reply With Quote
Old 29th March 2008, 07:11   #5  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
The documentation that comes with AviSynth is generally of better quality and is more complete than the wiki.
stickboy is offline   Reply With Quote
Old 29th March 2008, 09:02   #6  |  Link
gzarkadas
Registered User
 
gzarkadas's Avatar
 
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 ]
gzarkadas is offline   Reply With Quote
Old 29th March 2008, 13:57   #7  |  Link
TSchniede
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))
}
TSchniede is offline   Reply With Quote
Old 2nd April 2008, 21:54   #8  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by TSchniede View Post
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))
}
Note that this won't work when either x or y is zero.

First rule of function testing: check the boundary cases!
Gavino is offline   Reply With Quote
Old 9th April 2008, 18:00   #9  |  Link
TSchniede
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.
TSchniede 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 23:29.


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