Next: Filtering Up: Signal Processing (signal) Previous: Signal Processing (signal)

B-splines

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 \( \Delta x \), then the B-spline approximation to a 1-dimensional function is the finite-basis expansion.

\begin{displaymath}
y\left( x\right) \approx \sum _{j}c_{j}\beta ^{o}\left( \frac{x}{\Delta x}-j\right) .\end{displaymath}

In two dimensions with knot-spacing \( \Delta x \) and \( \Delta y \), the function representation is

\begin{displaymath}
z\left( x,y\right) \approx \sum _{j}\sum _{k}c_{jk}\beta ^{o...
...elta x}-j\right) \beta ^{o}\left( \frac{y}{\Delta y}-k\right) .\end{displaymath}

In these expressions, \( \beta ^{o}\left( \cdot \right) \) is the space-limited B-spline basis function of order, \( o \). The requirement of equally-spaced knot-points and equally-spaced data points, allows the development of fast (inverse-filtering) algorithms for determining the coefficients, \( c_{j} \), from sample-values, \( y_{n} \). Unlike the general spline interpolation algorithms, these algorithms can quickly find the spline coefficients for large images.

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

\begin{displaymath}
y\prime ^{\prime \prime }\left( x\right) =\frac{1}{\Delta x^...
...{j}\beta ^{o\prime \prime }\left( \frac{x}{\Delta x}-j\right) .\end{displaymath}

Using the property of B-splines that

\begin{displaymath}
\frac{d^{2}\beta ^{o}\left( w\right) }{dw^{2}}=\beta ^{o-2}\...
...) -2\beta ^{o-2}\left( w\right) +\beta ^{o-2}\left( w-1\right) \end{displaymath}

it can be seen that

\begin{displaymath}
y^{\prime \prime }\left( x\right) =\frac{1}{\Delta x^{2}}\su...
...ht) +\beta ^{o-2}\left( \frac{x}{\Delta x}-j-1\right) \right] .\end{displaymath}

If \( o=3 \), then at the sample points,

\begin{eqnarray*}
\Delta x^{2}\left. y^{\prime }\left( x\right) \right\vert _{x=...
...a _{n-j}+c_{j}\delta _{n-j-1},\\
& = & c_{n+1}-2c_{n}+c_{n-1}.
\end{eqnarray*}



Thus, the second-derivative signal can be easily calculated from the spline fit. if desired, smoothing splines can be found to make the second-derivative less sensitive to random-errors.

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, \( \beta ^{o}\left( x\right) \) for arbitrary order and \( x. \) For large \( o \), the B-spline basis function can be approximated well by a zero-mean Gaussian function with standard-deviation equal to \( \sigma _{o}=\left( o+1\right) /12 \):

\begin{displaymath}
\beta ^{o}\left( x\right) \approx \frac{1}{\sqrt{2\pi \sigma _{o}^{2}}}\exp \left( -\frac{x^{2}}{2\sigma _{o}}\right) .\end{displaymath}

A function to compute this Gaussian for arbitrary \( x \) and \( o \) is also available (signal.gauss_spline). The following code and Figure uses spline-filtering to compute an edge-image (the second-derivative of a smoothed spline) of Lena's face which is an array returned by the command lena(). The command signal.sepfir2d was used to apply a separable two-dimensional FIR filter with mirror-symmetric boundary conditions to the spline coefficients. This function is ideally suited for reconstructing samples from spline coefficients and is faster than signal.convolve2d which convolves arbitrary two-dimensional filters and allows for choosing mirror-symmetric boundary conditions.


>>> 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')

Figure 5: Example of using smoothing splines to filter images.
\resizebox*{0.45\textwidth}{!}{\includegraphics{lena_image.epsi}}    \resizebox*{0.45\textwidth}{!}{\includegraphics{lena_edge.epsi}}



Next: Filtering Up: Signal Processing (signal) Previous: Signal Processing (signal)
2001-07-27