Class LeptUtils


  • public class LeptUtils
    extends java.lang.Object
    Various utility methods for Leptonica.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static float deg2rad  
      (package private) static java.lang.String JAI_IMAGE_WRITER_MESSAGE  
      static java.lang.String SEL_STR2
      HMT (with just misses) for speckle up to 2x2
      static java.lang.String SEL_STR3
      HMT (with just misses) for speckle up to 3x3
      (package private) static java.lang.String TIFF_FORMAT  
    • Constructor Summary

      Constructors 
      Constructor Description
      LeptUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static Pix convertImageToPix​(java.awt.image.BufferedImage image)
      Deprecated.
      static Pix convertImageToPix​(java.awt.image.RenderedImage image)
      Converts RenderedImage to Leptonica Pix .
      static java.awt.image.BufferedImage convertPixToImage​(Pix pix)
      Converts Leptonica Pix to BufferedImage.
      static Pix despeckle​(Pix pixs, java.lang.String selStr, int selSize)
      Reduces speckle noise in image.
      static void dispose​(com.sun.jna.Structure resource)
      Disposes of Leptonica native resource.
      static void disposePix​(Pix pix)
      Disposes of Pix resource.
      static java.nio.ByteBuffer getImageByteBuffer​(java.awt.image.RenderedImage image)
      Gets image data of a RenderedImage object.
      static java.lang.String removeLines​(java.lang.String imageFile)
      Remove lines from image file.
      static Pix removeLines​(Pix pixs)
      Removes horizontal lines from a grayscale image.
      • Methods inherited from class java.lang.Object

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

      • JAI_IMAGE_WRITER_MESSAGE

        static final java.lang.String JAI_IMAGE_WRITER_MESSAGE
        See Also:
        Constant Field Values
      • SEL_STR2

        public static final java.lang.String SEL_STR2
        HMT (with just misses) for speckle up to 2x2
        "oooo"
        "oC o"
        "o  o"
        "oooo"
        See Also:
        Constant Field Values
      • SEL_STR3

        public static final java.lang.String SEL_STR3
        HMT (with just misses) for speckle up to 3x3
        "ooooo"
        "oC  o"
        "o   o"
        "o   o"
        "ooooo"
        See Also:
        Constant Field Values
    • Constructor Detail

      • LeptUtils

        public LeptUtils()
    • Method Detail

      • convertPixToImage

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

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

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

        public static java.nio.ByteBuffer getImageByteBuffer​(java.awt.image.RenderedImage image)
                                                      throws java.io.IOException
        Gets image data of a RenderedImage object.
        Parameters:
        image - a RenderedImage object
        Returns:
        a byte buffer of image data
        Throws:
        java.io.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:
        line-removal
      • removeLines

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

        public static Pix despeckle​(Pix pixs,
                                    java.lang.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.