A B-spline is an approximation of a continuous function over a finite-domain
in terms of B-spline coefficients and knot points. If the knot-points
are equally spaced with spacing , then the B-spline
approximation to a 1-dimensional function is the finite-basis expansion.
The advantage of representing a set of samples via B-spline basis
functions is that continuous-domain operators (derivatives, re-sampling,
integral, etc.) which assume that the data samples are drawn from
an underlying continuous function can be computed with relative ease
from the spline coefficients. For example, the second-derivative of
a spline is
The savvy reader will have already noticed that the data samples are related to the knot coefficients via a convolution operator, so that simple convolution with the sampled B-spline function recovers the original data from the spline coefficients. The output of convolutions can change depending on how boundaries are handled (this becomes increasingly more important as the number of dimensions in the data-set increases). The algorithms relating to B-splines in the signal-processing sub package assume mirror-symmetric boundary conditions. Thus, spline coefficients are computed based on that assumption, and data-samples can be recovered exactly from the spline coefficients by assuming them to be mirror-symmetric also.
Currently the package provides functions for determining seond- and
third-order cubic spline coefficients from equally spaced samples
in one- and two-dimensions (signal.qspline1d, signal.qspline2d,
signal.cspline1d, signal.cspline2d). The package also supplies a
function (signal.bspline) for evaluating the bspline basis
function,
for arbitrary order and
For large
, the B-spline basis function can be approximated
well by a zero-mean Gaussian function with standard-deviation equal
to
:
>>> image = lena().astype(Float32) >>> derfilt = array([1.0,-2,1.0],Float32) >>> ck = signal.cspline2d(image,8.0) >>> deriv = signal.sepfir2d(ck, derfilt, [1]) + \ >>> signal.sepfir2d(ck, [1], derfilt) >>> >>> ## Alternatively we could have done: >>> ## laplacian = array([[0,1,0],[1,-4,1],[0,1,0]],Float32) >>> ## deriv2 = signal.convolve2d(ck,laplacian,mode='same',boundary='symm') >>> >>> xplt.imagesc(image[::-1]) # flip image so it looks right-side up. >>> xplt.title('Original image') >>> xplt.eps('lena_image') >>> xplt.imagesc(deriv[::-1]) >>> xplt.title('Output of spline edge filter') >>> xplt.eps('lena_edge')