Class LeptUtils

java.lang.Object
net.sourceforge.lept4j.util.LeptUtils

public class LeptUtils extends Object
Various utility methods for Leptonica.
  • Field Details

  • Constructor Details

    • LeptUtils

      public LeptUtils()
  • Method Details

    • convertPixToImage

      public static BufferedImage convertPixToImage(Pix pix) throws IOException
      Converts Leptonica Pix to BufferedImage.
      Parameters:
      pix - source pix
      Returns:
      BufferedImage output image
      Throws:
      IOException
    • convertImageToPix

      @Deprecated public static Pix convertImageToPix(BufferedImage image) throws IOException
      Deprecated.
      Converts BufferedImage to Leptonica Pix .
      Parameters:
      image - source image
      Returns:
      Pix output pix
      Throws:
      IOException
    • convertImageToPix

      public static Pix convertImageToPix(RenderedImage image) throws IOException
      Converts RenderedImage to Leptonica Pix .
      Parameters:
      image - source image
      Returns:
      Pix output pix
      Throws:
      IOException
    • getImageByteBuffer

      public static ByteBuffer getImageByteBuffer(RenderedImage image) throws IOException
      Gets image data of a RenderedImage object.
      Parameters:
      image - a RenderedImage object
      Returns:
      a byte buffer of image data
      Throws:
      IOException
    • removeLines

      public static Pix removeLines(Pix pixs)
      Removes horizontal lines from a grayscale image. The algorithm is based on Leptonica lineremoval.c example.
      To remove vertical lines, rotate the image 90 degrees first, remove the horizontal lines, and rotate it back.
      Parameters:
      pixs - input pix
      Returns:
      pix with lines removed
      See Also:
    • removeLines

      public static String removeLines(String imageFile) throws IOException
      Remove lines from image file.
      Parameters:
      imageFile - input image
      Returns:
      temporary multi-page TIFF image file
      Throws:
      IOException
    • despeckle

      public static Pix despeckle(Pix pixs, String selStr, int selSize)
      Reduces speckle noise in image. The algorithm is based on Leptonica speckle_reg.c example demonstrating morphological method of removing speckle.
      Parameters:
      pixs - input pix
      selStr - hit-miss sels in 2D layout; SEL_STR2 and SEL_STR3 are predefined values
      selSize - 2 for 2x2, 3 for 3x3
      Returns:
      pix with speckle removed
    • disposePix

      public static void disposePix(Pix pix)
      Disposes of Pix resource.
      Parameters:
      pix -
    • dispose

      public static void dispose(com.sun.jna.Structure resource)
      Disposes of Leptonica native resource.
      Parameters:
      resource - A Leptonica object, such as Pix, Pixa, Box, Boxa, PixColormap, etc.