VariableBlur version 0.4

by Tonny Petersen(C)2005 (tsp@person.dk)

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

