Class ImageGray<T extends ImageGray<T>>

java.lang.Object
boofcv.struct.image.ImageBase<T>
boofcv.struct.image.ImageGray<T>
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
GrayF, GrayI, GrayS64

public abstract class ImageGray<T extends ImageGray<T>> extends ImageBase<T>

A base class for a single band intensity image. The image is an rectangular array where each pixel represents an intensity measurement from an imaging sensor. Internally the pixels are stored a 1D array in a row-major format. Different primitive types (e.g. byte, short, float, double) are implemented by children of this class. This image format is designed to allow quick and easy read/write access to each pixel and automatically supports sub-images.

Most image operations work off of direct children of this class. For operations which support images with multiple bands or colors (e.g. RGB or planar cameras) there is the ImageInterleaved class and others.

The image is defined by the following parameters:

width
number of columns in the image.
height
number of rows in the image.
startIndex
The index of the first pixel in the data array.
stride
Number of elements which need to be skipped over in the data array between rows.

Sub-images are images that are a rectangular image inside of a larger image. The original image and the sub-image share the same data array, so an operation in one will affect the other. They are useful when only part of the image needs to be processed. All image processing operations support sub-images.

Pixels can be directly accessed by elements. For example, to access the pixel at (x = 3, y = 10) one would do:
pixelValue = img.data[ startIndex + 10*stride ]

See Also:
  • Constructor Details

    • ImageGray

      protected ImageGray(int width, int height)
      Creates a new image with all of its parameters initialized, including the data array.
      Parameters:
      width - Image's width.
      height - Image's height.
    • ImageGray

      protected ImageGray()
  • Method Details

    • initialize

      protected void initialize(int width, int height)
    • subimage

      public T subimage(int x0, int y0, int x1, int y1, @Nullable T subimage)

      Creates a rectangular sub-image from 'this' image. The subimage will share the same internal array that stores each pixel's value. Any changes to pixel values in the original image or the sub-image will affect the other. A sub-image must be a sub-set of the original image and cannot specify a bounds larger than the original.

      When specifying the sub-image, the top-left corner is inclusive and the bottom right corner exclusive. Thus, a sub-image will contain all the original pixels if the following is used: subimage(0,0,width,height,null).

      Specified by:
      subimage in class ImageBase<T extends ImageGray<T>>
      Parameters:
      x0 - x-coordinate of top-left corner of the sub-image, inclusive.
      y0 - y-coordinate of top-left corner of the sub-image, inclusive.
      x1 - x-coordinate of bottom-right corner of the sub-image, exclusive.
      y1 - y-coordinate of bottom-right corner of the sub-image, exclusive.
      subimage - Optional output for sub-image. If not null the subimage will be written into this image.
      Returns:
      A sub-image of 'this' image.
    • reshape

      public void reshape(int width, int height)
      Changes the image's width and height without declaring new memory. If the internal array is not large enough to store the new image an IllegalArgumentException is thrown.
      Specified by:
      reshape in class ImageBase<T extends ImageGray<T>>
      Parameters:
      width - The new width.
      height - The new height.
    • reshape

      public void reshape(ImageBase img)
      Reshape to match the input image's width and height
    • setTo

      public T setTo(T orig)
      Sets the values of each pixel equal to the pixels in the specified matrix. If the images are not the same shape this will be resized.
      Specified by:
      setTo in class ImageBase<T extends ImageGray<T>>
      Parameters:
      orig - The original image whose value is to be copied into this one
      Returns:
      Instance of 'this' to allow chaining.
    • createSameShape

      public <B extends ImageGray<B>> B createSameShape(Class<B> type)
      Creates a single band image of the specified type that will have the same shape as this image
    • create

      public static <B extends ImageGray<B>> B create(Class<B> type, int width, int height)
    • copyRow

      public void copyRow(int row, int col0, int col1, int offset, Object array)
      Description copied from class: ImageBase
      Copies the row into the array.
      Specified by:
      copyRow in class ImageBase<T extends ImageGray<T>>
      Parameters:
      row - Which row to copy.
      col0 - First column. Inclusive.
      col1 - Last column. Exclusive.
      offset - First index in output array
      array - Output array
    • print

      public abstract void print()
      Prints the image to standard out
    • _getData

      protected abstract Object _getData()
      Returns the data array the image is stored in.
      Returns:
      data array;
    • getDataType

      public abstract ImageDataType getDataType()
      Returns image type information
      Returns:
      The type of image.
    • _setData

      public abstract void _setData(Object data)
      Sets the image's internal data array.
      Parameters:
      data - data array