The POLY_2D function performs polynomial warping of images. This function performs a geometrical transformation in which the resulting array is defined by:

*g [x, y] = f [x', y'] = f [a [x, y], b [x, y]]*

where *g*[*x*, *y*] represents the pixel in the output image at coordinate (*x*, *y*), and *f* [*x*', *y*'] is the pixel at (*x*', *y*') in the input image that is used to derive *g*[*x*, *y*]. The functions *a *(*x*, *y*) and *b* (*x*, *y*) are polynomials in *x* and *y* of degree *N*, whose coefficients are given by *P* and *Q*, and specify the spatial transformation:

Either the nearest neighbor or bilinear interpolation methods can be selected.

## Examples

Some simple linear (degree one) transformations are:

P |
P |
P |
P |
Q |
Q |
Q |
Q |
Effect |

0 |
0 |
1 |
0 |
0 |
1 |
0 |
0 |
Identity |

0 |
0 |
0.5 |
0 |
0 |
1 |
0 |
0 |
Stretch X by a factor of 2 |

0 |
0 |
1 |
0 |
0 |
2.0 |
0 |
0 |
Shrink Y by a factor of 2 |

z |
0 |
1 |
0 |
0 |
1 |
0 |
0 |
Shift left by z pixels |

0 |
1 |
0 |
0 |
0 |
0 |
1 |
0 |
Transpose |

POLY_2D is often used in conjunction with the POLYWARP procedure to warp images.

; Create and display a simple image:

A = BYTSCL(SIN(DIST(250)), TOP=!D.TABLE_SIZE) & TV, A

; Set up the arrays of original points to be warped:

XO = [61, 62, 143, 133]

YO = [89, 34, 38, 105]

; Set up the arrays of points to be fit:

XI = [24, 35, 102, 92]

YI = [81, 24, 25, 92]

; Use POLYWARP to generate the P and Q inputs to POLY_2D:

POLYWARP, XI, YI, XO, YO, 1, P, Q

; Perform an image warping based on P and Q:

B = POLY_2D(A, P, Q)

; Display the new image:

TV, B, 250, 250

Images can also be warped over irregularly gridded control points using the WARP_TRI procedure.

## Syntax

*Result* = POLY_2D( *Array*, *P*, *Q* [, *Interp* [, *Dim*_{x}, *Dim*_{y}]] [, CUBIC={-1 to 0}] [, MISSING=*value*] [, PIXEL_CENTER=*value*])

## Arguments

### Array

A two-dimensional array of any basic type except string. The result has the same type as *Array*.

### P and Q

*P* and *Q* are arrays containing the polynomial coefficients. Each array must contain (*N*+1)^{2} elements (where *N* is the degree of the polynomial). For example, for a linear transformation, *P* and *Q* contain four elements and can be a 2 x 2 array or a 4-element vector. *P*_{i,j} contains the coefficient used to determine *x’*, and is the weight of the term *x*^{j}*y*^{i}. The POLYWARP procedure can be used to fit *(x’, y’)* as a function of *(x, y)* and determines the coefficient arrays *P* and *Q*.

### Interp

Set this argument to 1 to perform bilinear interpolation. Set this argument to 2 to perform cubic convolution interpolation (as described under the CUBIC keyword, below). Otherwise, the nearest neighbor method is used. For the linear case, (*N*=1), bilinear interpolation requires approximately twice as much time as does the nearest neighbor method.

### Dim_{x}

If present, *Dim*_{x} specifies the number of columns in the output. If omitted, the output has the same number of columns as *Array*.

### Dim_{y}

If present, *Dim*_{y} specifies the number of rows in the output. If omitted, the output has the same number of rows as *Array*.

## Keywords

### CUBIC

Set this keyword to a value between -1 and 0 to use the cubic convolution interpolation method with the specified value as the interpolation parameter. Setting this keyword equal to a value greater than zero specifies a value of -1 for the interpolation parameter. Park and Schowengerdt (see reference below) suggest that a value of -0.5 significantly improves the reconstruction properties of this algorithm. Note that cubic convolution interpolation works only with one- and two-dimensional arrays.

Cubic convolution is an interpolation method that closely approximates the theoretically optimum sinc interpolation function using cubic polynomials. According to sampling theory, details of which are beyond the scope of this document, if the original signal, *f*, is a band-limited signal, with no frequency component larger than ω_{0}, and *f* is sampled with spacing less than or equal to 1/2ω_{0}, then *f* can be reconstructed by convolving with a sinc function: sinc (*x*) = sin (π*x*) / (π*x*).

In the one-dimensional case, four neighboring points are used, while in the two-dimensional case 16 points are used. Note that cubic convolution interpolation is significantly slower than bilinear interpolation.

For further details see:

Rifman, S.S. and McKinnon, D.M., “Evaluation of Digital Correction Techniques for ERTS Images; Final Report”, Report 20634-6003-TU-00, TRW Systems, Redondo Beach, CA, July 1974.

S. Park and R. Schowengerdt, 1983 “Image Reconstruction by Parametric Cubic Convolution”, Computer Vision, Graphics & Image Processing 23, 256.

### MISSING

Specifies the output value for points whose *x’, y’* is outside the bounds of *Array*. If MISSING is not specified, the resulting output value is extrapolated from the nearest pixel of *Array*.

### PIXEL_CENTER

Set this keyword to a floating-point value giving the offset of the center of each input pixel. The default is 0.0 which indicates the lower-left corner of the pixel. A typical value would be 0.5, which would be the center of the pixel.

### Thread Pool Keywords

This routine is written to make use of IDL’s *thread pool*, which can increase execution speed on systems with multiple CPUs. The values stored in the !CPU system variable control whether IDL uses the thread pool for a given computation. In addition, you can use the thread pool keywords TPOOL_MAX_ELTS, TPOOL_MIN_ELTS, and TPOOL_NOTHREAD to override the defaults established by !CPU for a single invocation of this routine. See Thread Pool Keywords for details.

## Version History

Original |
Introduced |

8.3 | Added PIXEL_CENTER keyword |

## See Also

## Notes

This page has no user notes yet. Be the first one!