Module NewOCR

Class SearchImage


  • public class SearchImage
    extends java.lang.Object
    Provides a way to easily get touching coordinates of black pixels. This uses a boolean array, because they will always be either black or white, and it's *much* faster than reading an image's color.
    Since:
    April 25, 2019
    • Constructor Summary

      Constructors 
      Constructor Description
      SearchImage​(boolean[][] values)
      Creates a SearchImage from a boolean grid.
    • Method Summary

      Modifier and Type Method Description
      int getHeight()
      Gets the height computed from the internal value 2D array.
      SearchImage getSubimage​(int x, int y, int width, int height)
      Gets a SearchImage from the bounds of the current image.
      boolean getValue​(int x, int y)
      Gets the coordinate of the given coordinates.
      boolean[][] getValues()
      Gets the raw values grid.
      int getWidth()
      Gets the width computed from the internal value 2D array.
      boolean hasValue​(int x, int y)
      Gets the value of the given coordinates.
      void scanFrom​(int originalX, int originalY, java.util.List<IntPair> coordinates)
      Adds the surrounding black pixels from the given coordinate to the coordinates parameter.
      java.awt.image.BufferedImage toImage()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • SearchImage

        public SearchImage​(boolean[][] values)
        Creates a SearchImage from a boolean grid.
        Parameters:
        values - The boolean grid of the image
    • Method Detail

      • scanFrom

        public void scanFrom​(int originalX,
                             int originalY,
                             java.util.List<IntPair> coordinates)
        Adds the surrounding black pixels from the given coordinate to the coordinates parameter. When a new value sis count, it is set to false to stop duplicates without checking each entry of the map.
        Parameters:
        originalX - The X location of the current black pixel
        originalY - The Y location of the current black pixel
        coordinates - The mutable list of coordinates that will have each new coordinate added to it
      • hasValue

        public boolean hasValue​(int x,
                                int y)
        Gets the value of the given coordinates. If it's true, it will set the value to false and return true.
        Parameters:
        x - The X coordinate to check
        y - The Y coordinate to check
        Returns:
        The value of the coordinate, or false if the position is inexistant
      • getValue

        public boolean getValue​(int x,
                                int y)
        Gets the coordinate of the given coordinates. Similar to hasValue(int, int), but it performs no mutation to the values grid.
        Parameters:
        x - The X coordinate to check
        y - The Y coordinate to check
        Returns:
        The value of the coordinates
      • getValues

        public boolean[][] getValues()
        Gets the raw values grid.
        Returns:
        The raw values grid
      • getWidth

        public int getWidth()
        Gets the width computed from the internal value 2D array.
        Returns:
        The width of the image
      • getHeight

        public int getHeight()
        Gets the height computed from the internal value 2D array.
        Returns:
        The height of the image
      • getSubimage

        public SearchImage getSubimage​(int x,
                                       int y,
                                       int width,
                                       int height)
        Gets a SearchImage from the bounds of the current image.
        Parameters:
        x - The X position to start at
        y - The Y position to start at
        width - The width of the sub image
        height - The height of the sub image
        Returns:
        The inner image from the coordinates given
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toImage

        public java.awt.image.BufferedImage toImage()