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)

  • 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/
class vispy.glsl.build_spatial_filters.Bessel

Bases: vispy.glsl.build_spatial_filters.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
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

class vispy.glsl.build_spatial_filters.Bicubic

Bases: vispy.glsl.build_spatial_filters.SpatialFilter

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(x)
weight(x)

Return filter weight for a distance x.

Parameters
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

class vispy.glsl.build_spatial_filters.Bilinear

Bases: vispy.glsl.build_spatial_filters.SpatialFilter

Bilinear filter (radius = 1.0).

Weight function:

w(x) = 1 - x
weight(x)

Return filter weight for a distance x.

Parameters
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

class vispy.glsl.build_spatial_filters.Blackman(size=256, radius=4.0)

Bases: vispy.glsl.build_spatial_filters.SpatialFilter

Blackman filter (radius = 4.0).

weight(x)

Return filter weight for a distance x.

Parameters
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

class vispy.glsl.build_spatial_filters.CatRom(size=2048)

Bases: vispy.glsl.build_spatial_filters.SpatialFilter

Catmull-Rom filter (radius = 2.0).

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
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

class vispy.glsl.build_spatial_filters.Gaussian

Bases: vispy.glsl.build_spatial_filters.SpatialFilter

Gaussian filter (radius = 2.0).

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.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".
weight(x)

Return filter weight for a distance x.

Parameters
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

class vispy.glsl.build_spatial_filters.Hamming

Bases: vispy.glsl.build_spatial_filters.SpatialFilter

Hamming filter (radius = 1.0).

Weight function:

w(x) = 0.54 + 0.46 * cos(pi * x)
weight(x)

Return filter weight for a distance x.

Parameters
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

class vispy.glsl.build_spatial_filters.Hanning

Bases: vispy.glsl.build_spatial_filters.SpatialFilter

Hanning filter (radius = 1.0).

Weight function:

w(x) = 0.5 + 0.5 * cos(pi * x)
weight(x)

Return filter weight for a distance x.

Parameters
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

class vispy.glsl.build_spatial_filters.Hermite

Bases: vispy.glsl.build_spatial_filters.SpatialFilter

Hermite filter (radius = 1.0).

Weight function:

w(x) = (2*x-3)*x^2 + 1
weight(x)

Return filter weight for a distance x.

Parameters
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

class vispy.glsl.build_spatial_filters.Kaiser(b=6.33)

Bases: vispy.glsl.build_spatial_filters.SpatialFilter

Kaiser filter (radius = 1.0).

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
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

class vispy.glsl.build_spatial_filters.Lanczos(size=256, radius=4.0)

Bases: vispy.glsl.build_spatial_filters.SpatialFilter

Lanczos filter (radius = 4.0).

weight(x)

Return filter weight for a distance x.

Parameters
x0 < 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: vispy.glsl.build_spatial_filters.SpatialFilter

Mitchell-Netravali filter (radius = 2.0).

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
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

class vispy.glsl.build_spatial_filters.Nearest

Bases: vispy.glsl.build_spatial_filters.SpatialFilter

Nearest (=None) filter (radius = 0.5).

Weight function:

w(x) = 1
property code

filter functions code

weight(x)

Return filter weight for a distance x.

Parameters
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

class vispy.glsl.build_spatial_filters.Quadric

Bases: vispy.glsl.build_spatial_filters.SpatialFilter

Quadric filter (radius = 1.5).

Weight function:

       |  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
weight(x)

Return filter weight for a distance x.

Parameters
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

class vispy.glsl.build_spatial_filters.Sinc(size=256, radius=4.0)

Bases: vispy.glsl.build_spatial_filters.SpatialFilter

Sinc filter (radius = 4.0).

weight(x)

Return filter weight for a distance x.

Parameters
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

class vispy.glsl.build_spatial_filters.SpatialFilter(radius=1.0)

Bases: object

call_code(index)
filter_code()
kernel(size=2048)
weight(x)

Return filter weight for a distance x.

Parameters
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

class vispy.glsl.build_spatial_filters.Spline16

Bases: vispy.glsl.build_spatial_filters.SpatialFilter

Spline16 filter (radius = 2.0).

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
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

class vispy.glsl.build_spatial_filters.Spline36

Bases: vispy.glsl.build_spatial_filters.SpatialFilter

Spline36 filter (radius = 3.0).

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
x0 < float < ceil(self.radius)

Distance to be used to compute weight.

vispy.glsl.build_spatial_filters.main()