Next: Signal Processing (signal) Up: Interpolation (interpolate) Previous: Spline interpolation in 1-d

Two-dimensionsal spline representation (interpolate.bisplrep)

For (smooth) spline-fitting to a two dimensional surface, the function interpolate.bisplrep is available. This function takes as required inputs the 1-D arrays x, y, and z which represent points on the surface \( z=f\left( x,y\right) . \) The default output is a list \( \left[ tx,ty,c,kx,ky\right] \) whose entries represent respectively, the components of the knot positions, the coefficients of the spline, and the order of the spline in each coordinate. It is convenient to hold this list in a single object, tck, so that it can be passed easily to the function interpolate.bisplev. The keyword, s, can be used to change the amount of smoothing performed on the data while determining the appropriate spline. The default value is \( s=m-\sqrt{2m} \) where \( m \) is the number of data points in the x, y, and z vectors. As a result, if no smoothing is desired, then \( s=0 \) should be passed to interpolate.bisplrep.

To evaluate the two-dimensional spline and it's partial derivatives (up to the order of the spline), the function interpolate.bisplev is required. This function takes as the first two arguments two 1-D arrays whose cross-product specifies the domain over which to evaluate the spline. The third argument is the tck list returned from interpolate.bisplrep. If desired, the fourth and fifth arguments provide the orders of the partial derivative in the \( x \) and \( y \) direction respectively.

It is important to note that two dimensional interpolation should not be used to find the spline representation of images. The algorithm used is not amenable to large numbers of input points. The signal processing toolbox contains (soon) more appropriate algorithms for finding the spline representation of an image. The two dimensional interpolation commands are intended for use when interpolating a two dimensional function as shown in the example that follows (See also Figure 4). This example uses the grid command in SciPy which is useful for defining a ``mesh-grid'' in many dimensions. The number of output arguments and the number of dimensions of each argument is determined by the number of indexing objects passed in grid[].

>>> # Define function over sparse 20x20 grid
>>> x,y = grid[-1:1:20L,-1:1:20L]
>>> z = (x+y)*exp(-6.0*(x*x+y*y))
>>> xplt.plot3(x,y,z,shade=1,palette='rainbow')
>>> xplt.title3("Sparsely sampled function.")
>>> xplt.eps("2d_func")

>>> # Interpolate function over new 70x70 grid
>>> xnew,ynew = grid[-1:1:70L,-1:1:70L]
>>> tck = interpolate.bisplrep(x,y,z,s=0)
>>> znew = interpolate.bisplev(xnew[:,0],ynew[0,:],tck)
>>> xplt.plot3(xnew,ynew,znew,shade=1,palette='rainbow')
>>> xplt.title3("Interpolated function.")
>>> xplt.eps("2d_interp")



Figure 4: Example of two-dimensional spline interpolation.
\resizebox*{0.45\textwidth}{!}{\includegraphics{2d_func.epsi}}    \resizebox*{0.45\textwidth}{!}{\includegraphics{2d_interp.epsi}}





Next: Signal Processing (signal) Up: Interpolation (interpolate) Previous: Spline interpolation in 1-d
2001-07-27