Bilinear spline interpolation

Bilinear spline is a fast (although less precise than bicubic spline) two-dimensional interpolation method. ALGLIB package contains an implementation of 2D splines available in several programming languages:

Our implementation of 2D splines:

The rest of this article focuses on bilinear splines. More information on bicubic splines can be found in the corresponding article.

Contents

    1 Getting started and examples
           Getting started
           Examples
    2 Comparison with bicubic splines
    3 Fitting 2D splines to scattered data
    4 Downloads section

Getting started and examples

Getting started

Bilinear spline interpolation functionality is provided by the spline2d subpackage of ALGLIB package. A bilinear spline can be created from the data sampled at the regular grid (to be exact, more general rectilinear one) with spline2dbuildbilinearv function. This function supports both scalar and vector-valued splines.

After an instance of spline object is built, you can perform following operations:

Examples

ALGLIB Reference Manual includes following examples which show how to work with bilinear splines:

Comparison with bicubic splines

Bilinear spline is a fast and compact method for interpolation of 2D data. For the same amount of input data it needs 4x less memory than bicubic spline. Spline calculation/evaluation is an order of magnitude faster than that of bicubic splines.

From the other side, following drawbacks can be noted:

  1. bilinear spline has nonsmooth first derivative; it has a discontinuity at the boundary between spline "cells"
  2. precision of bilinear splines is typically less than that of bicubic ones

Thus, unless you have really tight memory and performance constraints, we recommend you to use bicubic splines in your work.

Fitting 2D splines to scattered data

Although internally all 2D splines use a rectilinear grid as the basis, it is possible to fit a spline to scattered (irregular) data with least squares solver.

ALGLIB has two high-performance algorithms which can do so. However, because of inherent non-smoothness and low precision of bilinear splines, these algorithms fit only bicubic splines. See corresponding part of the article on bicubic splines for more information.

This article is licensed for personal use only.

Download ALGLIB for C++ / C# / Java / Python / ...

ALGLIB Project offers you two editions of ALGLIB:

ALGLIB Free Edition:
+delivered for free
+offers full set of numerical functionality
+extensive algorithmic optimizations
-no multithreading
-non-commercial license

ALGLIB Commercial Edition:
+flexible pricing
+offers full set of numerical functionality
+extensive algorithmic optimizations
+high performance (SMP, SIMD)
+commercial license with support plan

Links to download sections for Free and Commercial editions can be found below:

ALGLIB 4.01.0 for C++

C++ library.
Delivered with sources.
Monolithic design.
Extreme portability.
Editions:   FREE   COMMERCIAL

ALGLIB 4.01.0 for C#

C# library with native kernels.
Delivered with sources.
VB.NET and IronPython wrappers.
Extreme portability.
Editions:   FREE   COMMERCIAL

ALGLIB 4.01.0 for Java

Java wrapper around HPC core.
Delivered with sources.
Seamless integration with Java.
Editions:   FREE   COMMERCIAL

ALGLIB 4.01.0 for Delphi

Delphi wrapper around C core.
Delivered as precompiled binary.
Compatible with FreePascal.
Editions:   FREE   COMMERCIAL

ALGLIB 4.01.0 for CPython

CPython wrapper around C core.
Delivered as precompiled binary.
Editions:   FREE   COMMERCIAL