A filter is a shader that transform the current displayed texture. Since shaders cannot be easily serialized within the GPU, they have to be well structured on the python side such that we can possibly merge them into a single source code for both vertex and fragment. Consequently, there is a default code for both vertex and fragment with specific entry points such that filter knows where to insert their specific code (declarations, functions and call (or code) to be inserted in the main function).
Spatial interpolation filter classes for OpenGL textures.
Each filter generates a one-dimensional lookup table (weights value from 0 to ceil(radius)) that is uploaded to video memory (as a 1d texture) and is then read by the shader when necessary. It avoids computing weight values for each pixel. Furthemore, each 2D-convolution filter is separable and can be computed using 2 1D-convolution with same 1d-kernel (= the lookup table values).
Available filters:
Nearest (radius 0.5) Bilinear (radius 1.0) Hanning (radius 1.0) Hamming (radius 1.0) Hermite (radius 1.0) Kaiser (radius 1.0) Quadric (radius 1.5) Bicubic (radius 2.0) CatRom (radius 2.0) Mitchell (radius 2.0) Spline16 (radius 2.0) Spline36 (radius 4.0) Gaussian (radius 2.0) Bessel (radius 3.2383) Sinc (radius 4.0) Lanczos (radius 4.0) Blackman (radius 4.0)
Nearest (radius 0.5)
Bilinear (radius 1.0)
Hanning (radius 1.0)
Hamming (radius 1.0)
Hermite (radius 1.0)
Kaiser (radius 1.0)
Quadric (radius 1.5)
Bicubic (radius 2.0)
CatRom (radius 2.0)
Mitchell (radius 2.0)
Spline16 (radius 2.0)
Spline36 (radius 4.0)
Gaussian (radius 2.0)
Bessel (radius 3.2383)
Sinc (radius 4.0)
Lanczos (radius 4.0)
Blackman (radius 4.0)
Note:
Weights code has been translated from the antigrain geometry library available at http://www.antigrain.com/
vispy.glsl.build_spatial_filters.
Bessel
Bases: vispy.glsl.build_spatial_filters.SpatialFilter
vispy.glsl.build_spatial_filters.SpatialFilter
Bessel filter (radius = 3.2383).
besj
Function BESJ calculates Bessel function of first kind of order n Arguments:
x - value at which the Bessel function is required n - an integer (>=0), the order
C++ Mathematical Library Converted from equivalent FORTRAN library Converted by Gareth Walker for use by course 392 computational project All functions tested and yield the same results as the corresponding FORTRAN versions.
If you have any problems using these functions please report them to M.Muldoon@UMIST.ac.uk
Documentation available on the web http://www.ma.umist.ac.uk/mrm/Teaching/392/libs/392.html Version 1.0 8/98 29 October, 1999 ——————– Adapted for use in AGG library by
Andy Wilk (castor.vulgaris@gmail.com)
Nicolas P. Rougier (Nicolas.Rougier@inria.fr)
weight
Return filter weight for a distance x.
x
Distance to be used to compute weight.
Bicubic
Bicubic filter (radius = 2.0).
Weight function:
w(x) = 1/6((x+2)^3 - 4*(x+1)^3 + 6*x^3 -4*(x-1)^3)
pow3
Bilinear
Bilinear filter (radius = 1.0).
w(x) = 1 - x
Blackman
Blackman filter (radius = 4.0).
CatRom
Catmull-Rom filter (radius = 2.0).
| 0 ≤ x < 1: 0.5*(2 + x^2*(-5+x*3)) w(x) = | 1 ≤ x < 2: 0.5*(4 + x*(-8+x*(5-x))) | 2 ≤ x : 0
Gaussian
Gaussian filter (radius = 2.0).
w(x) = exp(-2x^2) * sqrt(2/pi)
This filter does not seem to be correct since: x = np.linspace(0, 1.0, 100 ) f = weight z = f(x+1)+f(x)+f(1-x)+f(2-x) z should be 1 everywhere but it is not the case and it produces "grid effects".
Hamming
Hamming filter (radius = 1.0).
w(x) = 0.54 + 0.46 * cos(pi * x)
Hanning
Hanning filter (radius = 1.0).
w(x) = 0.5 + 0.5 * cos(pi * x)
Hermite
Hermite filter (radius = 1.0).
w(x) = (2*x-3)*x^2 + 1
Kaiser
Kaiser filter (radius = 1.0).
w(x) = bessel_i0(a sqrt(1-x^2)* 1/bessel_i0(b)
bessel_i0
Lanczos
Lanczos filter (radius = 4.0).
..
!! processed by numpydoc !!
Mitchell
Mitchell-Netravali filter (radius = 2.0).
| 0 ≤ x < 1: p0 + x^2*(p2 + x*p3) w(x) = | 1 ≤ x < 2: q0 + x*(q1 + x*(q2 + x*q3)) | 2 ≤ x : 0
Nearest
Nearest (=None) filter (radius = 0.5).
w(x) = 1
code
filter functions code
Quadric
Quadric filter (radius = 1.5).
| 0.0 ≤ x < 0.5: 0.75 - x*x w(x) = | 0.5 ≤ x < 1.5: 0.5 - (x-1.5)^2 | 1.5 ≤ x : 0
Sinc
Sinc filter (radius = 4.0).
SpatialFilter
Bases: object
object
call_code
filter_code
kernel
Spline16
Spline16 filter (radius = 2.0).
| 0 ≤ x < 1: ((x-9/5)*x - 1/5)*x + 1 w(x) = | | 1 ≤ x < 2: ((-1/3*(x-1) + 4/5)*(x-1) - 7/15 )*(x-1)
Spline36
Spline36 filter (radius = 3.0).
| 0 ≤ x < 1: ((13/11*x - 453/209)*x -3/209)*x +1 w(x) = | 1 ≤ x < 2: ((-6/11*(x-1) - 270/209)*(x-1) -156/209)*(x-1) | 2 ≤ x < 3: (( 1/11*(x-2) - 45/209)*(x-2) + 26/209)*(x-2)
main