Class ImageBase<T extends ImageBase>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable
    Direct Known Subclasses:
    ImageGray, ImageMultiBand

    public abstract class ImageBase<T extends ImageBase>
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Cloneable
    Base class for all image types.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int height
      Number of rows in the image.
      ImageType imageType
      Description of the image data structure
      int startIndex
      Index of the first pixel in the data array
      int stride
      How many elements need to be skipped over to go one row down.
      boolean subImage
      Indicates if it is a sub-image or not
      int width
      Number of columns in the image.
    • Constructor Summary

      Constructors 
      Constructor Description
      ImageBase()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      T clone()
      Creates an identical image.
      abstract void copyCol​(int col, int row0, int row1, int offset, java.lang.Object array)
      Copies the column into the array.
      abstract void copyRow​(int row, int col0, int col1, int offset, java.lang.Object array)
      Copies the row into the array.
      abstract T createNew​(int imgWidth, int imgHeight)
      Returns a new image.
      T createSameShape()
      Creates a new image of the same type which also has the same shape.
      int getHeight()  
      ImageType<T> getImageType()
      Description of the image data structure
      int getIndex​(int x, int y)  
      int getStartIndex()  
      int getStride()  
      int getWidth()  
      Point2D_I32 indexToPixel​(int index)  
      boolean isInBounds​(int x, int y)
      Returns true if the pixel coordinate is inside the image or false if not.
      boolean isSubimage()
      If this matrix is a sub-image or not.
      void matchShape​(ImageBase image)
      Reshapes this image so that it's shape matches the input image
      abstract void reshape​(int width, int height)
      Changes the width and height of the image.
      void setHeight​(int height)  
      void setStartIndex​(int startIndex)  
      void setStride​(int stride)  
      abstract void setTo​(T orig)
      Sets the value of 'this' image to be identical to the passed in image.
      void setWidth​(int width)  
      T subimage​(int x0, int y0, int x1, int y1)
      Same as subimage(int, int, int, int, ImageBase), but sets the storage for the input subimage to null.
      abstract T subimage​(int x0, int y0, int x1, int y1, T subimage)
      Creates a rectangular sub-image from 'this' image.
      int totalPixels()
      Returns the number of pixels in the image.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • startIndex

        public int startIndex
        Index of the first pixel in the data array
      • stride

        public int stride
        How many elements need to be skipped over to go one row down.
      • width

        public int width
        Number of columns in the image.
      • height

        public int height
        Number of rows in the image.
      • subImage

        public boolean subImage
        Indicates if it is a sub-image or not
      • imageType

        public ImageType imageType
        Description of the image data structure
    • Constructor Detail

      • ImageBase

        public ImageBase()
    • Method Detail

      • subimage

        public abstract T subimage​(int x0,
                                   int y0,
                                   int x1,
                                   int y1,
                                   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).

        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.
      • subimage

        public T subimage​(int x0,
                          int y0,
                          int x1,
                          int y1)
        Same as subimage(int, int, int, int, ImageBase), but sets the storage for the input subimage to null.
        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.
        Returns:
        A sub-image of 'this' image.
      • reshape

        public abstract void reshape​(int width,
                                     int height)
        Changes the width and height of the image. If the image data array isn't large enough to hold an image of this size then a new array is declared. Otherwise the image data array is left unchanged and only the width and height variables are modified.
        Parameters:
        width - Desired image width
        height - Desired image height
      • matchShape

        public void matchShape​(ImageBase image)
        Reshapes this image so that it's shape matches the input image
        Parameters:
        image - Image whose shape will be matched
      • setTo

        public abstract void setTo​(T orig)
        Sets the value of 'this' image to be identical to the passed in image. All structural attributes of the images must be the same.
        Parameters:
        orig - Image for which 'this' is to be a copy of.
      • isSubimage

        public boolean isSubimage()
        If this matrix is a sub-image or not.
        Returns:
        true if it is a subimage, otherwise false.
      • isInBounds

        public final boolean isInBounds​(int x,
                                        int y)
        Returns true if the pixel coordinate is inside the image or false if not.
        Parameters:
        x - pixel location x-axis
        y - pixel location y-axis
        Returns:
        true if inside and false if outside
      • getIndex

        public int getIndex​(int x,
                            int y)
      • getWidth

        public final int getWidth()
      • setWidth

        public final void setWidth​(int width)
      • getHeight

        public final int getHeight()
      • setHeight

        public final void setHeight​(int height)
      • getStartIndex

        public int getStartIndex()
      • setStartIndex

        public void setStartIndex​(int startIndex)
      • getStride

        public int getStride()
      • setStride

        public void setStride​(int stride)
      • indexToPixel

        public Point2D_I32 indexToPixel​(int index)
      • createNew

        public abstract T createNew​(int imgWidth,
                                    int imgHeight)
        Returns a new image. If either width or height are set to -1 then none of the class parameters set. Otherwise a new image is created with the specified dimensions which has all other parameters the same as the original matrix.
        Parameters:
        imgWidth - Width of the new image
        imgHeight - height of the new image
        Returns:
        new image
      • getImageType

        public ImageType<T> getImageType()
        Description of the image data structure
        Returns:
        Description of the image data structure
      • createSameShape

        public T createSameShape()
        Creates a new image of the same type which also has the same shape. This is the same as calling createNew(int, int) with this image's width and height.
        Returns:
        new image with the same shape as this.
      • totalPixels

        public int totalPixels()
        Returns the number of pixels in the image. width*height
      • copyRow

        public abstract void copyRow​(int row,
                                     int col0,
                                     int col1,
                                     int offset,
                                     java.lang.Object array)
        Copies the row into the array.
        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 abstract void copyCol​(int col,
                                     int row0,
                                     int row1,
                                     int offset,
                                     java.lang.Object array)
        Copies the column into the array.
        Parameters:
        col - Which column to copy.
        row0 - First row. Inclusive.
        row1 - Last row. Exclusive.
        offset - First index in output array
        array - Output array
      • clone

        public T clone()
        Creates an identical image. Note that if this image is a sub-image portions of hte image which are not part of the sub-image are not copied.
        Overrides:
        clone in class java.lang.Object
        Returns:
        Clone of this image.