Class Planar<T extends ImageGray<T>>

All Implemented Interfaces:
Serializable, Cloneable

public class Planar<T extends ImageGray<T>>
extends ImageMultiBand<Planar<T>>

Multi-band image composed of discontinuous planar images for each band. The bands are discontinuous in that each one is an independent memory and are of type ImageGray. Planar images fully supports all functions inside of ImageBase. Each internal image has the same width, height, startIndex, and stride.

For example, in a RGB image there would be three bands one for each color, and each color would be stored in its own gray scale image. To access the image for a particular band call getBand(int). To get the RGB value for a pixel (x,y) one would need to:

 int red = image.getBand(0).get(x,y);
 int green = image.getBand(1).get(x,y);
 int blue = image.getBand(2).get(x,y);
 
Setting the RGB value of pixel (x,y) is done in a similar manner:
 image.getBand(0).set(x,y,red);
 image.getBand(1).set(x,y,green);
 image.getBand(2).set(x,y,blue);
 

May image processing operations can be run independently on each color band. This is useful since many operations have been written for ImageGray, but not Planar yet.

 for( int i = 0; i < image.numBands(); i++ ) {
     SomeGrayImageFilter.process( image.getBand(0) );
 }    
 

See Also:
Serialized Form
  • Field Details

    • type

      public Class<T extends ImageGray<T>> type
      Type of image in each band
    • bands

      public T extends ImageGray<T>[] bands
      Set of gray scale images
  • Constructor Details

    • Planar

      public Planar​(Class<T> type, int width, int height, int numBands)
      Creates a Planar image with the specified properties.
      Parameters:
      type - The type of image which each band is stored as.
      width - Width of the image.
      height - Height of the image.
      numBands - Total number of bands.
    • Planar

      public Planar​(Class<T> type, int numBands)
      Declares internal arrays for storing each band, but not the images in each band.
      Parameters:
      type - The type of image which each band is stored as.
      numBands - Number of bands in the image.
  • Method Details

    • getBandType

      public Class<T> getBandType()
      Type of image each band is stored as.
      Returns:
      The type of ImageGray which each band is stored as.
    • getNumBands

      public int getNumBands()
      Returns the number of bands or colors stored in this image.
      Specified by:
      getNumBands in class ImageMultiBand<Planar<T extends ImageGray<T>>>
      Returns:
      Number of bands in the image.
    • getBand

      public T getBand​(int band)
      Returns a band in the multi-band image.
      Parameters:
      band - Which band should be returned.
      Returns:
      Image band
    • subimage

      public Planar<T> subimage​(int x0, int y0, int x1, int y1, @Nullable @Nullable Planar<T> output)
      Creates a sub-image from 'this' image. The subimage will share the same internal array that stores each pixel's value, but will only pertain to an axis-aligned rectangular segment of the original.
      Specified by:
      subimage in class ImageBase<Planar<T extends ImageGray<T>>>
      Parameters:
      x0 - x-coordinate of top-left corner of the sub-image.
      y0 - y-coordinate of top-left corner of the sub-image.
      x1 - x-coordinate of bottom-right corner of the sub-image.
      y1 - y-coordinate of bottom-right corner of the sub-image.
      output - Optional storage for subimage
      Returns:
      A sub-image of this image.
    • setTo

      public void setTo​(Planar<T> orig)
      Sets the values of each pixel equal to the pixels in the specified matrix. Automatically resized to match the input image.
      Specified by:
      setTo in class ImageBase<Planar<T extends ImageGray<T>>>
      Parameters:
      orig - The original image whose value is to be copied into this one
    • 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<Planar<T extends ImageGray<T>>>
      Parameters:
      width - The new width.
      height - The new height.
    • reshape

      public void reshape​(int width, int height, int numberOfBands)
      Description copied from class: ImageMultiBand
      Reshape for MultiBand images which allows the number of bands to be changed a the same time too
      Overrides:
      reshape in class ImageMultiBand<Planar<T extends ImageGray<T>>>
      Parameters:
      width - Desired image width
      height - Desired image height
      numberOfBands - Desired number of bands
    • createNew

      public Planar<T> createNew​(int imgWidth, int imgHeight)
      Creates a new image of the same type and number of bands
      Specified by:
      createNew in class ImageBase<Planar<T extends ImageGray<T>>>
      Parameters:
      imgWidth - image width
      imgHeight - image height
      Returns:
      new image
    • 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<Planar<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
    • copyCol

      public void copyCol​(int col, int row0, int row1, int offset, Object array)
      Description copied from class: ImageBase
      Copies the column into the array.
      Specified by:
      copyCol in class ImageBase<Planar<T extends ImageGray<T>>>
      Parameters:
      col - Which column to copy.
      row0 - First row. Inclusive.
      row1 - Last row. Exclusive.
      offset - First index in output array
      array - Output array
    • partialSpectrum

      public Planar<T> partialSpectrum​(int... which)
      Returns a new Planar which references the same internal single band images at this one.
      Parameters:
      which - List of bands which will comprise the new image
      Returns:
      New image
    • reorderBands

      public void reorderBands​(int... order)
      Changes the bands order
      Parameters:
      order - The new band order
    • setNumberOfBands

      public void setNumberOfBands​(int numberOfBands)
      Changes the number of bands in the image. A new array is declared and individual bands are recycled if possible
      Specified by:
      setNumberOfBands in class ImageMultiBand<Planar<T extends ImageGray<T>>>
      Parameters:
      numberOfBands - New number of bands in the image.
    • get32u8

      public int get32u8​(int x, int y)
      Returns an integer formed from 4 bands. band[0]<<24 | band[1] << 16 | band[2]<<8 | band[3]. Assumes arrays are U8 type.
      Parameters:
      x - column
      y - row
      Returns:
      32 bit integer
    • get24u8

      public int get24u8​(int x, int y)
      Returns an integer formed from 3 bands. band[0]<<16| band[1] << 8 | band[2]
      Parameters:
      x - column
      y - row
      Returns:
      32 bit integer
    • set24u8

      public void set24u8​(int x, int y, int value)
    • set32u8

      public void set32u8​(int x, int y, int value)
    • setBandType

      public void setBandType​(Class<T> type)
    • getBands

      public T[] getBands()
    • setBands

      public void setBands​(T[] bands)
    • setBand

      public void setBand​(int which, T image)