Mathematics |
Two-Dimensional Interpolation
The function interp2
performs two-dimensional interpolation, an important operation for image processing and data visualization. Its most general form is
Z
is a rectangular array containing the values of a two-dimensional function, and X
and Y
are arrays of the same size containing the points for which the values in Z
are given. XI
and YI
are matrices containing the points at which to interpolate the data. method
is an optional string specifying an interpolation method.
There are three different interpolation methods for two-dimensional data:
method = 'nearest'
). This method fits a piecewise constant surface through the data values. The value of an interpolated point is the value of the nearest point.
method = 'linear'
). This method fits a bilinear surface through existing data points. The value of an interpolated point is a combination of the values of the four closest points. This method is piecewise bilinear, and is faster and less memory-intensive than bicubic interpolation.
method = 'cubic'
). This method fits a bicubic surface through existing data points. The value of an interpolated point is a combination of the values of the sixteen closest points. This method is piecewise bicubic, and produces a much smoother surface than bilinear interpolation. This can be a key advantage for applications like image processing. Use bicubic interpolation when the interpolated data and its derivative must be continuous.
All of these methods require that X
and Y
be monotonic, that is, either always increasing or always decreasing from point to point. You should prepare these matrices using the meshgrid
function, or else be sure that the "pattern" of the points emulates the output of meshgrid
. In addition, each method automatically maps the input to an equally spaced domain before interpolating. If X
and Y
are already equally spaced, you can speed execution time by prepending an asterisk to the method
string, for example, '*cubic'
.
One-Dimensional Interpolation | Comparing Interpolation Methods |