Examples of com.lightcrafts.mediax.jai.Interpolation

• com.lightcrafts.mediax.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 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.

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

 69707172737475767778798081828384858687888990 return java.awt.Image.UndefinedProperty;             }             ROI srcROI = (ROI)property;             // Retrieve the Interpolation object.             Interpolation interp = (Interpolation)pb.getObjectParameter(1);             // Determine the effective source bounds.             Rectangle srcBounds = null;             PlanarImage dst = op.getRendering();             if (dst instanceof GeometricOpImage &&                 ((GeometricOpImage)dst).getBorderExtender() == null) {                 srcBounds =                     new Rectangle(src.getMinX() + interp.getLeftPadding(),                                   src.getMinY() + interp.getTopPadding(),                                   src.getWidth() - interp.getWidth() + 1,                                   src.getHeight() - interp.getHeight() + 1);             } else {                 srcBounds = new Rectangle(src.getMinX(),             src.getMinY(),             src.getWidth(),             src.getHeight());
View Full Code Here

 68697071727374757677 }         int scaleX = paramBlock.getIntParameter(0);         int scaleY = paramBlock.getIntParameter(1);         float [] qsFilter = (float [])paramBlock.getObjectParameter(2);         Interpolation interp = (Interpolation)paramBlock.getObjectParameter(3);         return new MlibFilteredSubsampleOpImage(source, extender, (Map)renderHints, layout,                                     scaleX, scaleY, qsFilter, interp);     } // create
View Full Code Here

 69707172737475767778798081828384858687888990 return java.awt.Image.UndefinedProperty;             }             ROI srcROI = (ROI)property;             // Retrieve the Interpolation object.             Interpolation interp = (Interpolation)pb.getObjectParameter(3);             // Determine the effective source bounds.             Rectangle srcBounds = null;             PlanarImage dst = op.getRendering();             if (dst instanceof GeometricOpImage &&                 ((GeometricOpImage)dst).getBorderExtender() == null) {                 srcBounds =                     new Rectangle(src.getMinX() + interp.getLeftPadding(),                                   src.getMinY() + interp.getTopPadding(),                                   src.getWidth() - interp.getWidth() + 1,                                   src.getHeight() - interp.getHeight() + 1);             } else {                 srcBounds = new Rectangle(src.getMinX(),             src.getMinY(),             src.getWidth(),             src.getHeight());
View Full Code Here

 6162636465666768697071 ImageLayout layout = RIFUtil.getImageLayoutHint(hints);         // Get operation parameters.         AffineTransform transform =             (AffineTransform)args.getObjectParameter(0);         Interpolation interp = (Interpolation)args.getObjectParameter(1);         double[] backgroundValues = (double[])args.getObjectParameter(2);         RenderedImage source = args.getRenderedSource(0);           if (!MediaLibAccessor.isMediaLibCompatible(args, layout) ||
View Full Code Here

 9899100101102103104105106107108 AffineTransform xform = AffineTransform.getScaleInstance(xMagnification, yMagnification);             RenderingHints formatHints = new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(BorderExtender.BORDER_COPY));             Interpolation interp = Interpolation.getInstance(Interpolation.INTERP_BICUBIC_2);             ParameterBlock params = new ParameterBlock();             params.addSource(printImage);             params.add(xform);             params.add(interp);             printImage = JAI.create("Affine", params, formatHints);
View Full Code Here

 126127128129130131132133134135136 if (scale > 0) {             AffineTransform transform = AffineTransform.getScaleInstance(scale, scale);             transform.preConcatenate(AffineTransform.getTranslateInstance(imageBounds.x, imageBounds.y));             RenderingHints formatHints = new RenderingHints(JAI.KEY_BORDER_EXTENDER,                                                             BorderExtender.createInstance(BorderExtender.BORDER_COPY));             Interpolation interp = Interpolation.getInstance(Interpolation.INTERP_BILINEAR);             ParameterBlock params = new ParameterBlock();             params.addSource(image);             params.add(transform);             params.add(interp);             RenderedOp scaled = JAI.create("Affine", params, formatHints);
View Full Code Here

 102103104105106107108109110111112 AffineTransform.getScaleInstance(scale, scale);                 RenderingHints extenderHint = new RenderingHints(                         JAI.KEY_BORDER_EXTENDER,                         BorderExtender.createInstance(BorderExtender.BORDER_COPY)                 );                 Interpolation interp = Interpolation.getInstance(                         Interpolation.INTERP_BILINEAR                 );                 image = AffineDescriptor.create(                         image, transform, interp, null, extenderHint                 ).getAsBufferedImage();
View Full Code Here

 7879808182838485868788 // Retrieve the transpose type and create a nearest neighbor             // Interpolation object.             TransposeType transposeType =                 (TransposeType)pb.getObjectParameter(0);             Interpolation interp =                 Interpolation.getInstance(Interpolation.INTERP_NEAREST);             // Return the transposed ROI.             return new ROI(JAI.create("transpose", srcROI.getAsImage(),                                       transposeType));
View Full Code Here

 69707172737475767778798081828384858687888990919293949596979899 return java.awt.Image.UndefinedProperty;             }             ROI srcROI = (ROI)property;             // Retrieve the Interpolation object.             Interpolation interp = (Interpolation)pb.getObjectParameter(4);             // Determine the effective source bounds.             Rectangle srcBounds = null;             PlanarImage dst = op.getRendering();             if (dst instanceof GeometricOpImage &&                 ((GeometricOpImage)dst).getBorderExtender() == null) {                 srcBounds =                     new Rectangle(src.getMinX() + interp.getLeftPadding(),                                   src.getMinY() + interp.getTopPadding(),                                   src.getWidth() - interp.getWidth() + 1,                                   src.getHeight() - interp.getHeight() + 1);             } else {                 srcBounds = new Rectangle(src.getMinX(),             src.getMinY(),             src.getWidth(),             src.getHeight());             }             // Set the nearest neighbor interpolation object.             Interpolation interpNN = interp instanceof InterpolationNearest ?                 interp :                 Interpolation.getInstance(Interpolation.INTERP_NEAREST);             // Retrieve the operation parameters.             float sv = pb.getFloatParameter(0);
View Full Code Here

 69707172737475767778798081828384858687888990 return java.awt.Image.UndefinedProperty;             }             ROI srcROI = (ROI)property;             // Retrieve the Interpolation object.             Interpolation interp = (Interpolation)pb.getObjectParameter(2);             // Determine the effective source bounds.             Rectangle srcBounds = null;             PlanarImage dst = op.getRendering();             if (dst instanceof GeometricOpImage &&                 ((GeometricOpImage)dst).getBorderExtender() == null) {                 srcBounds =                     new Rectangle(src.getMinX() + interp.getLeftPadding(),                                   src.getMinY() + interp.getTopPadding(),                                   src.getWidth() - interp.getWidth() + 1,                                   src.getHeight() - interp.getHeight() + 1);             } else {                 srcBounds = new Rectangle(src.getMinX(),             src.getMinY(),             src.getWidth(),             src.getHeight());
View Full Code Here