Class Image


  • public class Image
    extends java.lang.Object
    Image abstraction class used for performing neighbourhood ( N8 ) ops with ease, works only on grayscale image

    Any pixel ( instance of Position class ) can stay in one of possible three states

    0 - Pixel is in inactive state

    1 - Pixel is in active state

    2 - Pixel is in dead state

    • Constructor Summary

      Constructors 
      Constructor Description
      Image​(int width, int height)
      Constructor to be used if you don't have all pixel intensities available right away, those can be updated later
      Image​(int width, int height, Position[][] positions)
      Constructor to be used if you've all pixel intensities available right away in form of matrix
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Image fromBufferedImage​(java.awt.image.BufferedImage img)
      Given a buffered image, it'll compute instance of Image class holding same information, but this class has utility methods which can help us in doing neighbourhood ops in a better fashion
      java.util.ArrayList<Position> getNeighbourhoodOfOrderX​(Position position, int order)
      Can obtain all valid pixel locations around specified pixel P, for specific order of neighbourhood
      java.util.ArrayList<Position> getNeighbourhoodOfOrderXInclusive​(Position position, int order)
      Can obtain all valid pixel locations around specified pixel P, for specific order of neighbourhood
      Position getPosition​(int x, int y)
      Returns pixel information at I[y][x]
      Position[][] getPositions()
      Returns a matrix of all pixels present in image, in ordered fashion
      java.util.ArrayList<Position> getUnexploredN8​(Position position)
      Obtains only those pixel locations ( in order 1 neighbourhood - N8 ) which are in inactive state ( state 0 )
      void setActive​(int x, int y)
      Set pixel state at I[y][x] to active ( 1 )
      void setPosition​(int x, int y, Position position)
      Sets pixel information at I[y][x]
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Image

        public Image​(int width,
                     int height,
                     Position[][] positions)
        Constructor to be used if you've all pixel intensities available right away in form of matrix
        Parameters:
        width - Width of image
        height - Height of image
        positions - Pixel locations of image ( in form of matrix ), in number width * height
      • Image

        public Image​(int width,
                     int height)
        Constructor to be used if you don't have all pixel intensities available right away, those can be updated later
        Parameters:
        width - Width of image
        height - Height of image
    • Method Detail

      • fromBufferedImage

        public static Image fromBufferedImage​(java.awt.image.BufferedImage img)
        Given a buffered image, it'll compute instance of Image class holding same information, but this class has utility methods which can help us in doing neighbourhood ops in a better fashion
        Parameters:
        img - Buffered image from which Image instance to be created
        Returns:
        Instance of Image class, holding information grabbed from `img`
      • getPosition

        public Position getPosition​(int x,
                                    int y)
        Returns pixel information at I[y][x]
        Parameters:
        x - X-coordinate of Pixel position
        y - Y-coordinate of Pixel position
        Returns:
        Returns pixel at I[y][x]
      • setPosition

        public void setPosition​(int x,
                                int y,
                                Position position)
        Sets pixel information at I[y][x]
        Parameters:
        x - X-coordinate of Pixel position
        y - Y-coordinate of Pixel position
        position - Pixel information we want to set at I[y][x]
      • getNeighbourhoodOfOrderX

        public java.util.ArrayList<Position> getNeighbourhoodOfOrderX​(Position position,
                                                                      int order)
        Can obtain all valid pixel locations around specified pixel P, for specific order of neighbourhood

        Doesn't include itself in neighbourhood, for inclusive version, check below implementation

        Parameters:
        position - Location of pixel around which neighbouring pixels to be extracted
        order - Order of neighbourhood to be considered
        Returns:
        List of all pixel locations around it, present in order-X neighbourhood ( except itself )
      • getNeighbourhoodOfOrderXInclusive

        public java.util.ArrayList<Position> getNeighbourhoodOfOrderXInclusive​(Position position,
                                                                               int order)
        Can obtain all valid pixel locations around specified pixel P, for specific order of neighbourhood

        Includes itself in neighbourhood, for exclusive version, check above implementation

        Parameters:
        position - Location of pixel around which neighbouring pixels to be extracted
        order - Order of neighbourhood to be considered
        Returns:
        List of all pixel locations around it, present in order-X neighbourhood ( including itself )
      • getUnexploredN8

        public java.util.ArrayList<Position> getUnexploredN8​(Position position)
        Obtains only those pixel locations ( in order 1 neighbourhood - N8 ) which are in inactive state ( state 0 )
        Parameters:
        position - Pixel location
        Returns:
        Set of pixels in order 1 neighbourhood of `position`, which are in *inactive* state
      • setActive

        public void setActive​(int x,
                              int y)
        Set pixel state at I[y][x] to active ( 1 )
        Parameters:
        x - X-coordinate of Pixel
        y - Y-coordinate of Pixel
      • getPositions

        public Position[][] getPositions()
        Returns a matrix of all pixels present in image, in ordered fashion
        Returns:
        All pixels present in image