

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: INNER  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object  +javax.media.jai.Interpolation
An object encapsulating a particular algorithm for image interpolation (resampling). An Interpolation captures the notion of performing sampling on a regular grid of pixels using a local neighborhood. It is intended to be used by operations that resample their sources, including affine mapping and warping.
Resampling is the action of computing a pixel value at a possibly nonintegral 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 nearestneighbor, 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 bandlimited 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 bandlimited 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 twodimensional interpolation methods directly, yielding more precise results, while others may implement these using a twopass 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 2^{n}  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 externallyprovided 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 onedimensional 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 2^{subsampleBits} exclusive for integer interpolations.
Horizontal Vertical s_ s0 . s1 s2 s_ ^ xfrac s0 .< yfrac s1 s2
The diagram below illustrates the pixels involved in twodimensional 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 Sunprovided 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.
InterpolationNearest
,
InterpolationBilinear
,
InterpolationBicubic
,
InterpolationBicubic2
,
InterpolationTable
, Serialized FormField Summary  
protected int 
bottomPadding
The number of pixels lying below the interpolation kernel key position. 
protected int 
height
The height of the interpolation kernel in pixels. 
static int 
INTERP_BICUBIC
A constant specifying interpolation by the InterpolationBicubic class. 
static int 
INTERP_BICUBIC_2
A constant specifying interpolation by the InterpolationBicubic2 class. 
static int 
INTERP_BILINEAR
A constant specifying interpolation by the InterpolationBilinear class. 
static int 
INTERP_NEAREST
A constant specifying interpolation by the InterpolationNearest class. 
protected int 
leftPadding
The number of pixels lying to the left of the interpolation kernel key position. 
protected int 
rightPadding
The number of pixels lying to the right of the interpolation kernel key position. 
protected int 
subsampleBitsH
The numbers of bits used for the horizontal subsample position. 
protected int 
subsampleBitsV
The number of bits used for the vertical subsample position. 
protected int 
topPadding
The number of pixels lying above the interpolation kernel key position. 
protected int 
width
The width of the interpolation kernel in pixels. 
Constructor Summary  
protected 
Interpolation()
Constructs an Interpolation object with no fields set. 

Interpolation(int width,
int height,
int leftPadding,
int rightPadding,
int topPadding,
int bottomPadding,
int subsampleBitsH,
int subsampleBitsV)
Construct interpolation object with all parameters set. 
Method Summary  
int 
getBottomPadding()
Returns the number of samples required below the key element. 
int 
getHeight()
Returns the number of samples required for vertical resampling. 
static Interpolation 
getInstance(int type)
Creates an interpolation of one of the standard types. 
int 
getLeftPadding()
Returns the number of samples required to the left of the key element. 
int 
getRightPadding()
Returns the number of samples required to the right of the key element. 
int 
getSubsampleBitsH()
Returns the number of bits used to index subsample positions in the horizontal direction. 
int 
getSubsampleBitsV()
Returns the number of bits used to index subsample positions in the vertical direction. 
int 
getTopPadding()
Returns the number of samples required above the key element. 
int 
getWidth()
Returns the number of samples required for horizontal resampling. 
double 
interpolate(double[][] samples,
float xfrac,
float yfrac)
Performs interpolation on a 2dimensional array of double samples. 
double 
interpolate(double s__,
double s_0,
double s_1,
double s_2,
double s0_,
double s00,
double s01,
double s02,
double s1_,
double s10,
double s11,
double s12,
double s2_,
double s20,
double s21,
double s22,
float xfrac,
float yfrac)
Performs interpolation on a 4x4 grid of double samples. 
double 
interpolate(double s00,
double s01,
double s10,
double s11,
float xfrac,
float yfrac)
Performs interpolation on a 2x2 grid of double samples. 
float 
interpolate(float[][] samples,
float xfrac,
float yfrac)
Performs interpolation on a 2dimensional array of floatingpoint samples. 
float 
interpolate(float s00,
float s01,
float s10,
float s11,
float xfrac,
float yfrac)
Performs interpolation on a 2x2 grid of floatingpoint samples. 
float 
interpolate(float s__,
float s_0,
float s_1,
float s_2,
float s0_,
float s00,
float s01,
float s02,
float s1_,
float s10,
float s11,
float s12,
float s2_,
float s20,
float s21,
float s22,
float xfrac,
float yfrac)
Performs interpolation on a 4x4 grid of floatingpoint samples. 
int 
interpolate(int[][] samples,
int xfrac,
int yfrac)
Performs interpolation on a 2dimensional array of integral samples. 
int 
interpolate(int s00,
int s01,
int s10,
int s11,
int xfrac,
int yfrac)
Performs interpolation on a 2x2 grid of integral samples. 
int 
interpolate(int s__,
int s_0,
int s_1,
int s_2,
int s0_,
int s00,
int s01,
int s02,
int s1_,
int s10,
int s11,
int s12,
int s2_,
int s20,
int s21,
int s22,
int xfrac,
int yfrac)
Performs interpolation on a 4x4 grid of integral samples. 
abstract double 
interpolateH(double[] samples,
float xfrac)
Performs horizontal interpolation on a 1dimensional array of double samples representing a row of samples. 
double 
interpolateH(double s_,
double s0,
double s1,
double s2,
float xfrac)
Performs horizontal interpolation on a quadruple of double samples. 
double 
interpolateH(double s0,
double s1,
float xfrac)
Performs horizontal interpolation on a pair of double samples. 
abstract float 
interpolateH(float[] samples,
float xfrac)
Performs horizontal interpolation on a 1dimensional array of floatingpoint samples representing a row of samples. 
float 
interpolateH(float s0,
float s1,
float xfrac)
Performs horizontal interpolation on a pair of floatingpoint samples. 
float 
interpolateH(float s_,
float s0,
float s1,
float s2,
float xfrac)
Performs horizontal interpolation on a quadruple of floatingpoint samples. 
abstract int 
interpolateH(int[] samples,
int xfrac)
Performs horizontal interpolation on a 1dimensional array of integral samples. 
int 
interpolateH(int s0,
int s1,
int xfrac)
Performs horizontal interpolation on a pair of integral samples. 
int 
interpolateH(int s_,
int s0,
int s1,
int s2,
int xfrac)
Performs horizontal interpolation on a quadruple of integral samples. 
double 
interpolateV(double[] samples,
float yfrac)
Performs vertical interpolation on a 1dimensional array of double samples representing a column of samples. 
double 
interpolateV(double s_,
double s0,
double s1,
double s2,
float yfrac)
Performs vertical interpolation on a quadruple of double samples. 
double 
interpolateV(double s0,
double s1,
float yfrac)
Performs vertical interpolation on a pair of double samples. 
float 
interpolateV(float[] samples,
float yfrac)
Performs vertical interpolation on a 1dimensional array of floatingpoint samples representing a column of samples. 
float 
interpolateV(float s0,
float s1,
float yfrac)
Performs vertical interpolation on a pair of floatingpoint samples. 
float 
interpolateV(float s_,
float s0,
float s1,
float s2,
float yfrac)
Performs vertical interpolation on a quadruple of floatingpoint samples. 
int 
interpolateV(int[] samples,
int yfrac)
Performs vertical interpolation on a 1dimensional array of integral samples. 
int 
interpolateV(int s0,
int s1,
int yfrac)
Performs vertical interpolation on a pair of integral samples. 
int 
interpolateV(int s_,
int s0,
int s1,
int s2,
int yfrac)
Performs vertical interpolation on a quadruple of integral samples. 
boolean 
isSeparable()
Returns true if the interpolation can be performed in a separable manner, that is, by performing a separate pass in each dimension. 
Methods inherited from class java.lang.Object 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
Field Detail 
public static final int INTERP_NEAREST
public static final int INTERP_BILINEAR
public static final int INTERP_BICUBIC
public static final int INTERP_BICUBIC_2
protected int leftPadding
protected int rightPadding
protected int topPadding
protected int bottomPadding
protected int subsampleBitsH
protected int subsampleBitsV
protected int width
protected int height
Constructor Detail 
protected Interpolation()
public Interpolation(int width, int height, int leftPadding, int rightPadding, int topPadding, int bottomPadding, int subsampleBitsH, int subsampleBitsV)
Method Detail 
public static Interpolation getInstance(int type)
type
 one of:
INTERP_NEAREST,
INTERP_BILINEAR,
INTERP_BICUBIC, or
INTERP_BICUBIC_2IllegalArgumentException
 if an unrecognized type is supplied.public int getLeftPadding()
public int getRightPadding()
public int getTopPadding()
public int getBottomPadding()
public int getWidth()
public int getHeight()
public boolean isSeparable()
public int getSubsampleBitsH()
In general, the caller is responsible for determining the number of subsample bits of any Interpolation object it receives and setting up its position variables accordingly. Some Interpolation objects allow the number of bits to be set at construction time.
public int getSubsampleBitsV()
public abstract int interpolateH(int[] samples, int xfrac)
An implementation is not required to actually quantize its interpolation coefficients to match the specified subsampling precision. However, the supplied value of xfrac (or yfrac) must match the precision of its corresponding subsampleBits. For example, with a subsampleBitsH value of 8, xfrac must lie between 0 and 255.
samples
 an array of ints.xfrac
 the subsample position, multiplied by 2^{(subsampleBitsH)}.public int interpolateV(int[] samples, int yfrac)
By default, vertical interpolation is defined to be the same as horizontal interpolation. Subclasses may choose to implement them differently.
samples
 an array of ints.yfrac
 the Y subsample position, multiplied by 2^{(subsampleBitsV)}.interpolateH(int[], int)
public int interpolate(int[][] samples, int xfrac, int yfrac)
samples
 a twodimensional array of ints.xfrac
 the X subsample position, multiplied by 2^{(subsampleBitsH)}.yfrac
 the Y subsample position, multiplied by 2^{(subsampleBitsV)}.interpolateH(int[], int)
public int interpolateH(int s0, int s1, int xfrac)
s0
 the central sample.s1
 the sample to the right of the central sample.xfrac
 the subsample position, ranging from zero to
2^{(subsampleBitsH)}  1.interpolateH(int[], int)
public int interpolateH(int s_, int s0, int s1, int s2, int xfrac)
s_
 the sample to the left of the central sample.s0
 the central sample.s1
 the sample to the right of the central sample.s2
 the sample to the right of s1.xfrac
 the subsample position, multiplied by 2^{(subsampleBitsH)}.interpolateH(int[], int)
public int interpolateV(int s0, int s1, int yfrac)
By default, vertical interpolation is identical to horizontal interpolation. Subclasses may choose to implement them differently.
s0
 the central sample.s1
 the sample below the central sample.yfrac
 the Y subsample position, multiplied by 2^{(subsampleBitsV)}.interpolateH(int[], int)
public int interpolateV(int s_, int s0, int s1, int s2, int yfrac)
By default, vertical interpolation is identical to horizontal interpolation. Subclasses may choose to implement them differently.
s_
 the sample above the central sample.s0
 the central sample.s1
 the sample below the central sample.s2
 the sample below s1.yfrac
 the Y subsample position, multiplied by 2^{(subsampleBitsV)}.interpolateH(int[], int)
public int interpolate(int s00, int s01, int s10, int s11, int xfrac, int yfrac)
s00
 the central sample.s01
 the sample to the right of the central sample.s10
 the sample below the central sample.s11
 the sample below and to the right of the central sample.xfrac
 the X subsample position, multiplied by 2^{(subsampleBitsH)}.yfrac
 the Y subsample position, multiplied by 2^{(subsampleBitsV)}.interpolateH(int[], int)
public int interpolate(int s__, int s_0, int s_1, int s_2, int s0_, int s00, int s01, int s02, int s1_, int s10, int s11, int s12, int s2_, int s20, int s21, int s22, int xfrac, int yfrac)
s__
 the sample above and to the left of the central sample.s_0
 the sample above the central sample.s_1
 the sample above and one to the right of the central sample.s_2
 the sample above and two to the right of the central sample.s0_
 the sample to the left of the central sample.s00
 the central sample.s01
 the sample to the right of the central sample.s02
 the sample two to the right of the central sample.s1_
 the sample below and one to the left of the central sample.s10
 the sample below the central sample.s11
 the sample below and one to the right of the central sample.s12
 the sample below and two to the right of the central sample.s2_
 the sample two below and one to the left of the central sample.s20
 the sample two below the central sample.s21
 the sample two below and one to the right of the central sample.s22
 the sample two below and two to the right of the central sample.xfrac
 the X subsample position, multiplied by 2^{(subsampleBitsH)}.yfrac
 the Y subsample position, multiplied by 2^{(subsampleBitsV)}.interpolateH(int[], int)
public abstract float interpolateH(float[] samples, float xfrac)
samples
 an array of floats.xfrac
 the X subsample position, in the range [0.0F, 1.0F).public float interpolateV(float[] samples, float yfrac)
By default, vertical interpolation is identical to horizontal interpolation. Subclasses may choose to implement them differently.
samples
 an array of floats.yfrac
 the Y subsample position, in the range [0.0F, 1.0F).public float interpolate(float[][] samples, float xfrac, float yfrac)
samples
 an array of floats.xfrac
 the X subsample position, in the range [0.0F, 1.0F).yfrac
 the Y subsample position, in the range [0.0F, 1.0F).public float interpolateH(float s0, float s1, float xfrac)
s0
 the central sample.s1
 the sample to the right of the central sample.xfrac
 the subsample position, in the range [0.0F, 1.0F).public float interpolateH(float s_, float s0, float s1, float s2, float xfrac)
s_
 the sample to the left of the central sample.s0
 the central sample.s1
 the sample to the right of the central sample.s2
 the sample to the right of s1.xfrac
 the subsample position, in the range [0.0F, 1.0F).public float interpolateV(float s0, float s1, float yfrac)
By default, vertical interpolation is identical to horizontal interpolation. Subclasses may choose to implement them differently.
s0
 the central sample.s1
 the sample below the central sample.yfrac
 the Y subsample position, in the range [0.0F, 1.0F).public float interpolateV(float s_, float s0, float s1, float s2, float yfrac)
By default, vertical interpolation is identical to horizontal interpolation. Subclasses may choose to implement them differently.
s_
 the sample above the central sample.s0
 the central sample.s1
 the sample below the central sample.s2
 the sample below s1.yfrac
 the Y subsample position, in the range [0.0F, 1.0F).public float interpolate(float s00, float s01, float s10, float s11, float xfrac, float yfrac)
s00
 the central sample.s01
 the sample to the right of the central sample.s10
 the sample below the central sample.s11
 the sample below and to the right of the central sample.xfrac
 the X subsample position, in the range [0.0F, 1.0F).yfrac
 the Y subsample position, in the range [0.0F, 1.0F).public float interpolate(float s__, float s_0, float s_1, float s_2, float s0_, float s00, float s01, float s02, float s1_, float s10, float s11, float s12, float s2_, float s20, float s21, float s22, float xfrac, float yfrac)
s__
 the sample above and to the left of the central sample.s_0
 the sample above the central sample.s_1
 the sample above and one to the right of the central sample.s_2
 the sample above and two to the right of the central sample.s0_
 the sample to the left of the central sample.s00
 the central sample.s01
 the sample to the right of the central sample.s02
 the sample two to the right of the central sample.s1_
 the sample below and one to the left of the central sample.s10
 the sample below the central sample.s11
 the sample below and one to the right of the central sample.s12
 the sample below and two to the right of the central sample.s2_
 the sample two below and one to the left of the central sample.s20
 the sample two below the central sample.s21
 the sample two below and one to the right of the central sample.s22
 the sample two below and two to the right of the central sample.xfrac
 the X subsample position, in the range [0.0F, 1.0F).yfrac
 the Y subsample position, in the range [0.0F, 1.0F).public abstract double interpolateH(double[] samples, float xfrac)
samples
 an array of doubles.xfrac
 the X subsample position, in the range [0.0F, 1.0F).public double interpolateV(double[] samples, float yfrac)
By default, vertical interpolation is identical to horizontal interpolation. Subclasses may choose to implement them differently.
samples
 an array of doubles.yfrac
 the Y subsample position, in the range [0.0F, 1.0F).public double interpolate(double[][] samples, float xfrac, float yfrac)
samples
 an array of doubles.xfrac
 the X subsample position, in the range [0.0F, 1.0F).yfrac
 the Y subsample position, in the range [0.0F, 1.0F).public double interpolateH(double s0, double s1, float xfrac)
s0
 the central sample.s1
 the sample to the right of the central sample.xfrac
 the subsample position, in the range [0.0F, 1.0F).public double interpolateH(double s_, double s0, double s1, double s2, float xfrac)
s_
 the sample to the left of the central sample.s0
 the central sample.s1
 the sample to the right of the central sample.s2
 the sample to the right of s1.xfrac
 the subsample position, in the range [0.0F, 1.0F).public double interpolateV(double s0, double s1, float yfrac)
By default, vertical interpolation is identical to horizontal interpolation. Subclasses may choose to implement them differently.
s0
 the central sample.s1
 the sample below the central sample.yfrac
 the Y subsample position, in the range [0.0F, 1.0F).public double interpolateV(double s_, double s0, double s1, double s2, float yfrac)
By default, vertical interpolation is identical to horizontal interpolation. Subclasses may choose to implement them differently.
s_
 the sample above the central sample.s0
 the central sample.s1
 the sample below the central sample.s2
 the sample below s1.yfrac
 the Y subsample position, in the range [0.0F, 1.0F).public double interpolate(double s00, double s01, double s10, double s11, float xfrac, float yfrac)
s00
 the central sample.s01
 the sample to the right of the central sample.s10
 the sample below the central sample.s11
 the sample below and to the right of the central sample.xfrac
 the X subsample position, in the range [0.0F, 1.0F).yfrac
 the Y subsample position, in the range [0.0F, 1.0F).public double interpolate(double s__, double s_0, double s_1, double s_2, double s0_, double s00, double s01, double s02, double s1_, double s10, double s11, double s12, double s2_, double s20, double s21, double s22, float xfrac, float yfrac)
s__
 the sample above and to the left of the central sample.s_0
 the sample above the central sample.s_1
 the sample above and one to the right of the central sample.s_2
 the sample above and two to the right of the central sample.s0_
 the sample to the left of the central sample.s00
 the central sample.s01
 the sample to the right of the central sample.s02
 the sample two to the right of the central sample.s1_
 the sample below and one to the left of the central sample.s10
 the sample below the central sample.s11
 the sample below and one to the right of the central sample.s12
 the sample below and two to the right of the central sample.s2_
 the sample two below and one to the left of the central sample.s20
 the sample two below the central sample.s21
 the sample two below and one to the right of the central sample.s22
 the sample two below and two to the right of the central sample.xfrac
 the X subsample position, in the range [0.0F, 1.0F).yfrac
 the Y subsample position, in the range [0.0F, 1.0F).


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: INNER  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 