Class BufferedImageUtil

java.lang.Object
com.itextpdf.pdfocr.onnxtr.util.BufferedImageUtil

public final class BufferedImageUtil extends Object
Additional algorithms for working with BufferedImage.
  • Method Details

    • toBchwInput

      public static FloatBufferMdArray toBchwInput (Collection<BufferedImage> images, OnnxInputProperties properties)
      Converts a collection of images to a batched ML model input in a BCHW format with 3 channels. This does aspect-preserving image resizing to fit the input shape.
      Parameters:
      images - collection of images to convert to model input
      properties - model input properties
      Returns:
      batched BCHW model input MD-array
    • rotate

      public static BufferedImage rotate (BufferedImage image, TextOrientation orientation)
      Rotates image based on text orientation. If no rotation necessary, same image is returned.
      Parameters:
      image - image to rotate
      orientation - text orientation used to rotate the image
      Returns:
      new rotated image, or same image, if no rotation is required
    • extractBoxes

      public static List<BufferedImage> extractBoxes (BufferedImage image, Collection boxes)
      Extracts sub-images from an image, based on provided rotated 4-point boxes. Sub-images are transformed to fit the whole image without (in our use cases it is just rotation).
      Parameters:
      image - original image to be used for extraction
      boxes - list of 4-point boxes. Points should be in the following order: BL, TL, TR, BR
      Returns:
      list of extracted image boxes