Class Interpolation

java.lang.Object
org.apache.sis.image.Interpolation
Direct Known Subclasses:
LanczosInterpolation, Visualization.InterpConvert

public abstract class Interpolation extends Object
Algorithm for image interpolation (resampling). Interpolations are performed by sampling on a regular grid of pixels using a local neighborhood. The sampling is performed by the ResampledImage class, which gives the sample values to the interpolate(…) method of this interpolation.

All methods in this class shall be safe for concurrent use in multi-threading context. For example, interpolations may be executed in a different thread for each tile in an image.

This class is designed for interpolations in a two-dimensional space only.

Since:
1.1
Version:
1.2
  • Field Details

    • NEAREST

      public static final Interpolation NEAREST
      A nearest-neighbor interpolation using 1×1 pixel.
    • BILINEAR

      public static final Interpolation BILINEAR
      A bilinear interpolation using 2×2 pixels. If the interpolation result is NaN, this method fallbacks on nearest-neighbor.
    • LANCZOS

      public static final Interpolation LANCZOS
      Lanczos interpolation for photographic images. This interpolation is not recommended for images that may contain NaN values.
      See Also:
  • Constructor Details

    • Interpolation

      protected Interpolation()
      Creates a new interpolation.
  • Method Details

    • getSupportSize

      public abstract Dimension getSupportSize()
      Returns the size of the area over which the resampling function needs to provide values. Common values are:
      Common support sizes
      Interpolation Width Height
      Nearest-neighbor 1 1
      Bilinear 2 2
      Bicubic 4 4
      Lanczos 4 4
      Returns:
      number of sample values required for interpolations.
    • interpolate

      public abstract void interpolate(DoubleBuffer source, int numBands, double xfrac, double yfrac, double[] writeTo, int writeToOffset)
      Interpolates sample values for all bands using the given pixel values in local neighborhood. The given source is a buffer with the number of elements shown below, where support width and support height are given by getSupportSize():
      (number of bands) × (support width) × (support height)
      Values in source buffer are always given with band index varying fastest, then column index, then row index. Columns are traversed from left to right and rows are traversed from top to bottom (SequenceType.LINEAR iteration order).

      The interpolation point is in the middle. For example if the support size is 4×4 pixels, then the interpolation point is the dot below and the fractional coordinates are relative to the horizontal and vertical lines drawn below. This figure is for an image with only one band, otherwise all indices between brackets would need to be multiplied by numBands.

      On output, this method shall write the interpolation results as numBands consecutive values in the supplied writeTo array, starting at writeToOffset index. This method should not modify the buffer position (use DoubleBuffer.mark() and reset() if needed).
      Parameters:
      source - pixel values from the source image to use for interpolation.
      numBands - number of bands. This is the number of values to put in the writeTo array.
      xfrac - the X subsample position, usually (but not always) in the range [0 … 1).
      yfrac - the Y subsample position, usually (but not always) in the range [0 … 1).
      writeTo - the array where this method shall write interpolated values.
      writeToOffset - index of the first value to put in the writeTo array.
    • toCompatible

      Interpolation toCompatible(RenderedImage source)
      Returns NEAREST if interpolations on the given image should be restricted to nearest-neighbor. If the given image uses an index color model, interpolating the indexed values does not produce the expected colors. Safest approach is to disable completely interpolations in that case.
      Note: we could interpolate if we knew that all index values, without exception (i.e. no index for missing values), are related to measurements by a linear function. In practice it rarely happens, because there is usually at least one index value reserved for missing values. Scientific data in SIS are usually stored as floating point type (with missing values mapped to NaN), which cannot be associated to IndexColorModel. For now we do not try to perform a more sophisticated detection of which interpolations are allowed, but a future SIS version may revisit this policy if needed.
      Returns:
      NEAREST if interpolations should be restricted to nearest-neighbor, or this otherwise.