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 19th January 2005, 23:29   #1  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
variable blur 0.4: a gaussian/binomial/average variable radius blur

Get version 0.4 here: variableblur


from the readme:

VariableBlur version 0.4


Variableblur is a gaussian, binomial or average blur filter with a variable radius(variance).
The binomial filter part is based on a paper by Frederick M. Waltz and John W. V. Miller. An efficient algorithm for Gaussian blur using finite-state machines. SPIE Conf. on Machine Vision Systems for Inspection and Metrology VII page 3521-37

The gaussian filter uses fftw version 3(http://www.fftw.org) available from ftp://ftp.fftw.org/pub/fftw/fftw3win32mingw.zip and wouldn't run without it. If you have fft3ffilter or defreq installed you already have it.

Also includes an unsharp mask filter based on the gaussian filter meaning it is fast for big variance.


usage:

binomialBlur(float varY,float varC,int Y,int U,int V,bool usemmx)

binomialBlur works by repeating a 5x5 or 3x3 kernel based on pascals triangle multiple times to blur the image. With a variance above 1 the result is very close to a true gaussian blur and much faster (for variance below ~30).


varY,varC: variance to use. Remember variance=sd^2. The variance is rounded down to the nearest half integer(0.5,1.0,1.5 etc). Radius 1 in version <=0.2 is equal to variance 0.5. Default 1.5

Y,U,V: Controls which planes the filter is applied to. If set to 3 the plane will be filtered, if 2 the plane will be copied from the source, if 1 the plane will be ignored and from 0 to -255 the plane will be assigned the absolute value. Default Y 3,U=2, V=2

useMMX: If true MMX instructions will be used. Default true for variance>1 else false.


averageblur(int radY,int radC,int Y,int U,int V)

averageblur works by taken the average value of the pixels inside the radius.

radY,radC: radius of the kernel. default 3.

Y,U,V: same as binomialblur



gaussianblur(float varY,float varC,int border,bool integrate,int Y,int U,int V)

Gaussianblur works by converting the image to the frequency domain using fftw and complex multiplying it with the gaussian kernel in the frequency domain before converting the result back to the spatial domain
giving the same result as doing a convolution in the spatial domain just faster for large kernelsizes.

varY,varC: Variance to use. This will not be rounded. default 1.5

border: Setup how the border of the image is threated. Posible values:
-255 - 0: the area outside the image is filled with the absolute value
1: Wrap around. The right border will be blured with the left border and the top border with the bottom border. This is the default behaivior when doing convolution in the frequency domain so this will be the fastest option. Default value
2: Don't process borders.
3: fill the area outside the border with the border value. Slowest but produces the nicest result.

integrate: if true the coefficient used will be a mean value of the area the pixel covers. Use this if you consider each pixel to be made of an infinite number of infinite small pixels or if you like the result :-). If integration is used the image will be softer. Default false.

Y,U,V: same as binomialblur



unsharp(float varY,float varC,float strength,int border,bool integrate,int Y,int U,int V)

Sharpens the image using unsharp filtering (http://homepages.inf.ed.ac.uk/rbf/HIPR2/unsharp.htm for an explanation).

strength: Strength of the sharpener best values is between 0(no sharpen) to 1(more sharpen). Values outside this will produce strange results.

Rest of the options is the same as for gaussianblur



Example:

binomialBlur(radY=0.5,RadC=0.5) #nearly the same as Blur(1)



#Unsharpen (it will sharpen the image)

function unsharpen(clip c,float variance,float k)
{
blr=gaussianblur(c,vary=variance,varc=2,Y=3,U=2,V=2,border=1)
return yv12lutxy(blr,c,"y x - "+string(k)+" * y +",y=3,u=2,v=2)
}

Changelog:

0.1 Initial release

0.2 optimization of the gaussian blur (now uses a 5x5 mask instead of 3x3) and the average blur(smarter algorithm resulting in a factor 20 to 100 speed increase)

0.3 GaussianBlur is included old gaussian is renamed to binomialblur.

0.4 Fixed bug with converting float to unsigned char without proper clamping. Also included an unsharp filter and optional integrated gaussian coefficients

License:
This filter is released under GPL se copying.txt

Last edited by tsp; 24th May 2005 at 22:47.
tsp is offline   Reply With Quote
Old 19th January 2005, 23:59   #2  |  Link
E-Male
mad computer-scientist
 
Join Date: Mar 2002
Posts: 1,375
good, my try was ran very slow...
E-Male is offline   Reply With Quote
Old 20th January 2005, 06:24   #3  |  Link
Macanudo
Registered User
 
Join Date: Jun 2002
Location: Texas
Posts: 59
tsp,

First of all thanks for the filter. I have been hoping someone would create a variable radius gaussian blur filter.

I am either applying it incorrectly or there is a bug, because when I use either of the following scripts my output is greyscale only.
Code:
LoadPlugin("C:\Program Files\AviSynth 2.5\Filters\variableblur.dll")
a=AviSource("C:\boats.avi")
b=a.VariableBlur(radY=6)
return b

or

LoadPlugin("C:\Program Files\AviSynth 2.5\Filters\variableblur.dll")
a=AviSource("C:\boats.avi")
b=a.VariableBlur(radY=6, RadC=6)
return b
I am using Avisynth 2.55.

Edit: I figured it out. I added ConverttoYV12() and it works great.


Thanks Again,
Macanudo

Last edited by Macanudo; 20th January 2005 at 07:46.
Macanudo is offline   Reply With Quote
Old 20th January 2005, 10:19   #4  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,547
yeah! i nearly missed this thread

glad to finally see a plugin to do this (though i'm not ready to ditch yv12convolution yet, as i can put in any impulse i like here).

will test as soon as possible.

[edit]

the radii for gaussian don't seem to be behaving properly. the blur seems much smaller than average blur.
__________________
sucking the life out of your videos since 2004

Last edited by Mug Funky; 20th January 2005 at 10:26.
Mug Funky is offline   Reply With Quote
Old 20th January 2005, 12:31   #5  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
it's because a gaussian blur is weaker than an average blur. Remember the weight for the centerpixel is much heigher in gaussian blur compaired to an average blur(where it has the same weight as all the other pixels)
you will see the same if you use yv12convolution with mask 1 1 1 compaired to 1 2 1
tsp is offline   Reply With Quote
Old 20th January 2005, 19:20   #6  |  Link
rfmmars
Registered User
 
Join Date: Feb 2004
Posts: 743
Can this filter be made to do the opposite, in other words sharping to correct non flat focus field of lenes use on many 8mm / Super 8mm Home movie cameras and projectors?

richard
photorecall.net
rfmmars is offline   Reply With Quote
Old 20th January 2005, 20:11   #7  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
rfmmars:

You can use the supplied function unsharp (se the readme). But I think you will have to combine it with a circular gradient mask if you only wants to sharpen the periphery of the image(I don't know I I understand the problem correct?). se
this thread how to do that (although they try the reverse, just use a sharpening filter(not necessarily unsharp) instead of a blur.)

Last edited by tsp; 20th January 2005 at 20:22.
tsp is offline   Reply With Quote
Old 20th January 2005, 21:00   #8  |  Link
rfmmars
Registered User
 
Join Date: Feb 2004
Posts: 743
This is what I need . No or liitle shaping at center but increasing sharping moving out from the center to the edges both Horz. & Vert.

Maybe with your filter I can do this now.

richard
rfmmars is offline   Reply With Quote
Old 20th January 2005, 21:04   #9  |  Link
E-Male
mad computer-scientist
 
Join Date: Mar 2002
Posts: 1,375
i somehow daubt he'll use the gradient mask maker plug-in
E-Male is offline   Reply With Quote
Old 20th January 2005, 21:48   #10  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
be aware that this filter uses an iterativ (rad times) 3x3 mask to approximate the gaussian blur meaning some artifact can appear with high radius(although I haven't seen some yet) due to rounding error though not as severe as using blur multiple times.
tsp is offline   Reply With Quote
Old 21st January 2005, 00:02   #11  |  Link
rfmmars
Registered User
 
Join Date: Feb 2004
Posts: 743
Don't pay attention to the above poster, he knows nothing about me or what he speaks.

richard
photorecall.net
rfmmars is offline   Reply With Quote
Old 21st January 2005, 00:28   #12  |  Link
E-Male
mad computer-scientist
 
Join Date: Mar 2002
Posts: 1,375
i trust in tsp's and everyone else's judgement not to listen to that
E-Male is offline   Reply With Quote
Old 21st January 2005, 00:48   #13  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,293
@rfmmars and E-Male,

Could you stop with this nonsense?
Wilbert is offline   Reply With Quote
Old 21st January 2005, 00:57   #14  |  Link
E-Male
mad computer-scientist
 
Join Date: Mar 2002
Posts: 1,375
sorry, i shouldn't have taken this here
E-Male is offline   Reply With Quote
Old 21st January 2005, 02:58   #15  |  Link
rfmmars
Registered User
 
Join Date: Feb 2004
Posts: 743
All will be quiet........Peace

..................................

tsp...........can the 3x3 matrix be setup for radial sharping in the sourse code?

richard
rfmmars is offline   Reply With Quote
Old 21st January 2005, 09:09   #16  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
Quote:
Originally posted by rfmmars
Can this filter be made to do the opposite, in other words sharping
Erh ... for that we have UnSharpMask() from the big WarpSharp package, singe ... ages, or so. Welcome back on earth, Richard
__________________
- 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!)
Didée is offline   Reply With Quote
Old 21st January 2005, 17:16   #17  |  Link
rfmmars
Registered User
 
Join Date: Feb 2004
Posts: 743
Didee........had a good landing........will give WarpSharp package a try.

richard
rfmmars is offline   Reply With Quote
Old 24th January 2005, 20:38   #18  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
rfmmars You can try this script and see if it gives the desired effect:
Code:
a=AVISource("G:\pf.avi").converttoyv12()
a.pointresize(440,400)
GraMaMa(1,4,last.width/2,last.height/2,330)
sharpmask=bilinearresize(a.width,a.height)
Overlay(a, a.unsharp(100), mask=sharpmask, mode="blend", opacity=1.0)


Function Unsharp(clip clip,int radius)
{ 
Blur=VariableBlur(clip,radY=radius,RadC=radius)
blurmask=subtract(Blur,clip)
return subtract(clip,blurmask)
}
you can change unsharp(100) to another sharpener (blur(-1) or WarpSharp)
tsp is offline   Reply With Quote
Old 24th January 2005, 21:06   #19  |  Link
rfmmars
Registered User
 
Join Date: Feb 2004
Posts: 743
Thanks for the script.will try as soon as possible.

richard
rfmmars is offline   Reply With Quote
Old 24th January 2005, 22:32   #20  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
updated variableblur to version 0.2 Mainly optimization of the gaussian blur (now uses a 5x5 mask instead of 3x3) and the average blur(smarter algorithm resulting in a factor 20 to 100 speed increase). I'm thinking about renaming the gaussian blur to binomial blur because it works like that. With higher radius it aproaches the true gaussian blur more. With radius = 2 it's closest to a gaussian blur with SD=1 and with radius=7 it's closest to SD=2.
tsp 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 19:34.


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