Class GridIndexer2D

java.lang.Object
imagingbook.common.image.GridIndexer2D
Direct Known Subclasses:
GridIndexer2D.DefaultValueIndexer, GridIndexer2D.ExceptionIndexer, GridIndexer2D.MirrorImageIndexer, GridIndexer2D.NearestBorderIndexer, GridIndexer2D.PeriodicImageIndexer

public abstract class GridIndexer2D extends Object

Instances of this class perform the transformation between 2D image coordinates and indexes into the associated 1D pixel array and vice versa. As usual images are assumed to be stored in row-major order. Instances of this class do not hold any image data themselves, they just perform the indexing task. This is used, for example, by class PixelPack, which provides a universal image data container which uses GridIndexer2D internally.

The (abstract) method getIndex(int, int) returns the 1D array index for a pair of 2D image coordinates. It is implemented by the inner subclasses GridIndexer2D.DefaultValueIndexer, GridIndexer2D.MirrorImageIndexer and GridIndexer2D.NearestBorderIndexer. They exhibit different behaviors when accessing out-of-image coordinates (see OutOfBoundsStrategy).

Version:
2022/09/17
See Also:
  • Field Details

  • Method Details

    • create

      public static GridIndexer2D create(int width, int height, OutOfBoundsStrategy obs)
      Creates and returns a new GridIndexer2D with the specified size and OutOfBoundsStrategy.
      Parameters:
      width - grid size (horizontal)
      height - grid size (vertical)
      obs - out-of-bounds strategy
      Returns:
      a new GridIndexer2D
    • create

      Creates and returns a new GridIndexer2D for the specified image and OutOfBoundsStrategy.
      Parameters:
      ip - the image to be associated with the returned indexer
      obs - out-of-bounds strategy
      Returns:
      a new GridIndexer2D
    • getIndex

      public abstract int getIndex(int u, int v)
      Returns the 1D array index for a given pair of image coordinates. For u, v coordinates outside the image, the returned index depends on the implementing subclass of GridIndexer2D. As a general rule, this method either returns a valid 1D array index or throws an exception. Subclasses implement (override) this method.
      Parameters:
      u - x-coordinate
      v - y-coordinate
      Returns:
      1D array index
    • getWithinBoundsIndex

      protected int getWithinBoundsIndex(int u, int v)
      Returns the 1D array index for a given pair of image coordinates, assuming that the specified position is inside the image.
      Parameters:
      u - x-coordinate
      v - y-coordinate
      Returns:
      the associated 1D index
    • getWidth

      public int getWidth()
      Returns the width of the associated image.
      Returns:
      the image width
    • getHeight

      public int getHeight()
      Returns the height of the associated image.
      Returns:
      the image height
    • getOutOfBoundsStrategy

      Returns the out-of-bounds strategy (see {qlink OutOfBoundsStrategy} used by this indexer.
      Returns:
      the out-of-bounds strategy