Resampling is the action of computing a pixel value at a possibly non-integral position of an image. The image defines pixel values at integer lattice points, and it is up to the resampler to produce a reasonable value for positions not falling on the lattice. A number of techniques are used in practice, the most common being nearest-neighbor, which simply takes the value of the closest lattice point; bilinear, which interpolates linearly between the four closest lattice points; and bicubic, which applies a piecewise polynomial function to a 4x4 neighborhood of nearby points. The area over which a resampling function needs to be computed is referred to as its support; thus the standard resampling functions have supports of 1, 4, and 16 pixels respectively. Mathematically, the ideal resampling function for a band-limited image (one containing no energy above a given frequency) is the sinc function, equal to sin(x)/x. This has practical limitations, in particular its infinite support, which lead to the use of the standard approximations described above.
Other interpolation functions may be required to solve problems other than the resampling of band-limited image data. When shrinking an image, it is common to use a function that combines area averaging with resampling in order to remove undesirable high frequencies as part of the interpolation process. Other application areas may use interpolating functions that operate under other assumptions about image data, such as taking the maximum value of a 2x2 neighborhood. The interpolation class provides a framework in which a variety of interpolation schemes may be expressed.
Many interpolations are separable, that is, they may be equivalently rewritten as a horizontal interpolation followed by a vertical one (or vice versa). In practice, some precision may be lost by the rounding and truncation that takes place between the passes. The Interpolation class assumes separability and implements all vertical interpolation methods in terms of corresponding horizontal methods, and defines isSeparable() to return true. A subclass may override these methods to provide distinct implementations of horizontal and vertical interpolation. Some subclasses may implement the two-dimensional interpolation methods directly, yielding more precise results, while others may implement these using a two-pass approach.
A minimal Interpolation subclass must call the Interpolation constructor (super()) and then set at least the following fields.
leftPadding rightPadding topPadding bottomPadding width height subsampleBitsH subsampleBitsV
It must also implement at least the following methods.
int interpolateH(int[] samples, int xfrac) float interpolateH(float[] samples, float xfrac) double interpolateH(double[] samples, float xfrac)All other methods are defined in terms of these methods for ease of implementation of new Interpolation subclasses.
Since interpolation is generally performed for every pixel of a destination image, efficiency is important. In particular, passing source samples by means of arrays is likely to be unacceptably slow. Accordingly, methods are provided for the common cases of 2x1, 1x2, 4x1, 1x4, 2x2, and 4x4 input grids. These methods are defined in the superclass to package their arguments into arrays and forward the call to the array versions, in order to simplify implementation. They should be called only on Interpolation objects with the correct width and height. In other words, an implementor of an Interpolation subclass may implement "interpolateH(int s0, int s1, int xfrac)" assuming that the interpolation width is in fact equal to 2, and does not need to enforce this constraint.
The fractional position of interpolation (xfrac, yfrac) is always between 0.0 and 1.0 (not including 1.0). For integral image data, the fraction is represented as a scaled integer between 0 and 2n - 1, where n is a small integer. The value of n in the horizontal and vertical directions may be obtained by calling getSubsampleBitsH() and getSubsampleBitsV(). In general, code that makes use of an externally-provided Interpolation object must query that object to determine its desired positional precision.
For float and double images, a float between 0.0F and 1.0F (not including 1.0F) is used as a positional specifier in the interest of greater accuracy.
It is important to understand that the subsampleBits precision is used only to indicate the scaling implicit in the fractional locations (xfrac, yfrac) for integral image data types. For example, for subsampleBitsH=8, xfrac must lie between 0 and 255 inclusive. An implementation is not required to actually quantize its interpolation coefficients to match the specified subsampling precision.
The diagrams below illustrate the pixels involved in one-dimensional interpolation. Point s0 is the interpolation kernel key position. xfrac and yfrac, indicated by the dots, represent the point of interpolation between two pixels. This value lies between 0.0 and 1.0 exclusive for floating point and 0 and 2subsampleBits exclusive for integer interpolations.
Horizontal Vertical s_ s0 . s1 s2 s_ ^ xfrac s0 .< yfrac s1 s2
The diagram below illustrates the pixels involved in two-dimensional interpolation. Point s00 is the interpolation kernel key position.
s__ s_0 s_1 s_2 s0_ s00 s01 s02 . < yfrac s1_ s10 s11 s12 s2_ s20 s21 s22 ^ xfrac
The subclasses of Interpolation include InterpolationNearest, InterpolationBilinear, InterpolationBicubic, and InterpolationBicubic2 (a variant defined by a different polynomial function). These subclasses are marked 'final,' so users may identify them by name (using 'instanceof') and write specialized code for them. This may also allow inlining to occur on some virtual machines. These classes do provide correct, if less than optimal code for performing their interpolations, so it is possible to use any Interpolation object in a generic manner. The Sun-provided InterpolationBilinear and InterpolationBicubic classes provide a more optimal implementation while using the same semantics.
The InterpolationTable class is a subclass of Interpolation that divides the set of subsample positions into a fixed number of "bins" and stores a kernel for each bin. InterpolationBicubic and InterpolationBicubic2 are implemented in terms of InterpolationTable since a direct implementation is very expensive. @see InterpolationNearest @see InterpolationBilinear @see InterpolationBicubic @see InterpolationBicubic2 @see InterpolationTable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|