vispy.glsl.build_spatial_filters module#
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)
Linear (radius 1)
Hanning (radius 1)
Hamming (radius 1)
Hermite (radius 1)
Kaiser (radius 1)
Quadric (radius 1.5)
Cubic (radius 2)
CatRom (radius 2)
Mitchell (radius 2)
Spline16 (radius 2)
Spline36 (radius 4)
Gaussian (radius 2)
Bessel (radius 3.2383)
Sinc (radius 4)
Lanczos (radius 4)
Blackman (radius 4)
Note:
Weights code has been translated from the antigrain geometry library
available at http://www.antigrain.com/
- class vispy.glsl.build_spatial_filters.Bessel#
Bases:
SpatialFilter
Bessel filter (radius = 3.2383).
- besj(x, n)#
Function BESJ calculates Bessel function of first kind of order n.
- Parameters:
- x: int
value at which the Bessel function is required
- nint
an integer (>=0), the order
Notes
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)
- Adapted for use in vispy library by
Nicolas P. Rougier (Nicolas.Rougier@inria.fr)
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- class vispy.glsl.build_spatial_filters.Blackman#
Bases:
SpatialFilter
Blackman filter (radius = 4).
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- class vispy.glsl.build_spatial_filters.CatRom#
Bases:
SpatialFilter
Catmull-Rom filter (radius = 2).
Weight function:
| 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
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- class vispy.glsl.build_spatial_filters.Cubic#
Bases:
SpatialFilter
Cubic filter (radius = 2).
Weight function:
w(x) = 1/6((x+2)^3 - 4*(x+1)^3 + 6*x^3 -4*(x-1)^3)
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- class vispy.glsl.build_spatial_filters.Gaussian#
Bases:
SpatialFilter
Gaussian filter (radius = 2).
Weight function:
w(x) = exp(-2x^2) * sqrt(2/pi)
Note:
This filter does not seem to be correct since: x = np.linspace(0, 1, 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".
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- class vispy.glsl.build_spatial_filters.Hamming(radius=1)#
Bases:
SpatialFilter
Hamming filter (radius = 1).
Weight function:
w(x) = 0.54 + 0.46 * cos(pi * x)
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- class vispy.glsl.build_spatial_filters.Hanning(radius=1)#
Bases:
SpatialFilter
Hanning filter (radius = 1).
Weight function:
w(x) = 0.5 + 0.5 * cos(pi * x)
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- class vispy.glsl.build_spatial_filters.Hermite(radius=1)#
Bases:
SpatialFilter
Hermite filter (radius = 1).
Weight function:
w(x) = (2*x-3)*x^2 + 1
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- class vispy.glsl.build_spatial_filters.Kaiser(b=6.33)#
Bases:
SpatialFilter
Kaiser filter (radius = 1).
Weight function:
w(x) = bessel_i0(a sqrt(1-x^2)* 1/bessel_i0(b)
- bessel_i0(x)#
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- class vispy.glsl.build_spatial_filters.Lanczos#
Bases:
SpatialFilter
Lanczos filter (radius = 4).
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- class vispy.glsl.build_spatial_filters.Linear(radius=1)#
Bases:
SpatialFilter
Linear filter (radius = 1).
Weight function:
w(x) = 1 - x
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- class vispy.glsl.build_spatial_filters.Mitchell(b=0.3333333333333333, c=0.3333333333333333)#
Bases:
SpatialFilter
Mitchell-Netravali filter (radius = 2).
Weight function:
| 0 ≤ x < 1: p0 + x^2*(p2 + x*p3) w(x) = | 1 ≤ x < 2: q0 + x*(q1 + x*(q2 + x*q3)) | 2 ≤ x : 0
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- class vispy.glsl.build_spatial_filters.Quadric#
Bases:
SpatialFilter
Quadric filter (radius = 1.5).
Weight function:
| 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
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- class vispy.glsl.build_spatial_filters.Sinc#
Bases:
SpatialFilter
Sinc filter (radius = 4).
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- class vispy.glsl.build_spatial_filters.SpatialFilter(radius=1)#
Bases:
object
- call_code(index)#
- kernel(size=2048)#
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- class vispy.glsl.build_spatial_filters.Spline16#
Bases:
SpatialFilter
Spline16 filter (radius = 2).
Weight function:
| 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)
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- class vispy.glsl.build_spatial_filters.Spline36#
Bases:
SpatialFilter
Spline36 filter (radius = 3).
Weight function:
| 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)
- weight(x)#
Return filter weight for a distance x.
- Parameters:
x
0 < float < ceil(self.radius)Distance to be used to compute weight.
- vispy.glsl.build_spatial_filters.generate_filter_code(radius)#
- vispy.glsl.build_spatial_filters.main()#