Class ImageAccessor

java.lang.Object
imagingbook.common.image.access.ImageAccessor
Direct Known Subclasses:
ScalarAccessor, VectorAccessor

public abstract class ImageAccessor extends Object

An 'image accessor' is a wrapper around some ImageProcessor object to allow unified (read and write) access to its pixels values. This abstract class defines unified access functionality to all 4 types of images available in ImageJ: 8-bit, 16-bit, float, and color images. All pixel values are of type float[], either containing a single element (for scalar-valued images) or three elements (for color images).

A generic ImageAccessor is created, e.g., by create(ImageProcessor), which returns an instance of ByteAccessor, ShortAccessor, FloatAccessor or RgbAccessor. ImageAccessor itself can access any ImageJ image using the methods getPix(int, int), getPix(double, double) for retrieving pixel values and setPix(int, int, float[]) to modify pixel values.

In addition, the accessors for scalar-valued images (ByteAccessor, ShortAccessor, FloatAccessor) provide the methods ScalarAccessor.getVal(int, int), ScalarAccessor.getVal(double, double) and ScalarAccessor.setVal(int, int, float) to read and write scalar-valued pixels passed as single float values.
The methods getPix(double, double) and ScalarAccessor.getVal(double, double) perform interpolation at non-integer coordinates using the specified InterpolationMethod.

A related concept for providing unified access to images is PixelPack, which copies all pixel data to internal float arrays. In contrast to PixelPack, ImageAccessor does not duplicate any data but reads and writes the original ImageProcessor pixel data directly.

Version:
2020/12/27
See Also:
  • Field Details

  • Method Details

    • create

      public static final ImageAccessor create(ImageProcessor ip)
      Creates a new ImageAccessor instance for the given image, using the default out-of-bounds strategy and interpolation method. The concrete type of the returned instance depends on the specified image.
      Parameters:
      ip - the source image
      Returns:
      a new ImageAccessor instance
    • create

      Creates a new ImageAccessor instance for the given image, using the specified out-of-bounds strategy and interpolation method. The concrete type of the returned instance depends on the specified image.
      Parameters:
      ip - the source image
      obs - the out-of-bounds strategy (use null for default settings)
      ipm - the interpolation method (use null for default settings)
      Returns:
      a new ImageAccessor instance
    • 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.
    • getProcessor

      Returns the source ImageProcessor associated with this ImageAccessor.
      Returns:
      the image processor
    • getDepth

      public abstract int getDepth()
      Returns the depth (number of components) of this image accessor. 1 is returned if the image is scalar-valued.
      Returns:
      the image depth.
    • getOutOfBoundsStrategy

      Returns the OutOfBoundsStrategy specified for this ImageAccessor.
      Returns:
      the out-of-bounds strategy
    • getInterpolationMethod

      Returns the InterpolationMethod specified for this ImageAccessor.
      Returns:
      the interpolation method
    • getPix

      public abstract float[] getPix(int u, int v)
      Returns the pixel value for the specified floating-point position as a float[] with either 1 element for scalar-valued images and or more elements (e.g., 3 for for RGB images).
      Parameters:
      u - the x-coordinate
      v - the y-coordinate
      Returns:
      the pixel value (float[])
    • getPix

      public abstract float[] getPix(double x, double y)
      Returns the interpolated pixel value for the specified floating-point position as a float[] with either 1 element for scalar-valued images and or more elements (e.g., 3 for for RGB images). Interpolation is used non-integer coordinates.
      Parameters:
      x - the x-coordinate
      y - the y-coordinate
      Returns:
      the interpolated pixel value (float[])
    • setPix

      public abstract void setPix(int u, int v, float[] val)
      Sets the pixel value at the specified integer position. The new value must be provided as float[] with 1 element for scalar-valued images or 3 elements for RGB images.
      Parameters:
      u - the x-coordinate
      v - the y-coordinate
      val - the new pixel value (float[])
    • getVal

      public abstract float getVal(int u, int v, int k)
      Returns the value of the pixel's k-th component at the specified position. If the associated image is scalar-valued, this is equivalent to component 0. See also getDepth().
      Parameters:
      u - the x-coordinate
      v - the y-coordinate
      k - the component index
      Returns:
      the component value (float)
    • getVal

      public abstract float getVal(double x, double y, int k)
      Returns the interpolated value of the pixel's k-th component at the specified position. If the associated image is scalar-valued, this is equivalent to component 0. See also getDepth().
      Parameters:
      x - the x-coordinate
      y - the y-coordinate
      k - the component index
      Returns:
      the interpolated component value (float[])
    • setVal

      public abstract void setVal(int u, int v, int k, float val)
      Sets the value of the pixel's k-th component at the specified position. If the associated image is scalar-valued, this is equivalent to component 0. See also getDepth().
      Parameters:
      u - the x-coordinate
      v - the y-coordinate
      k - the component index
      val - the new component value
    • getComponentAccessor

      public abstract ScalarAccessor getComponentAccessor(int k)
      Returns the ImageAccessor for the k-th component; the result is a sub-type of ScalarAccessor. In the case of a scalar-valued image, THIS object is returned.
      Parameters:
      k - the component index
      Returns:
      the component accessor.