Package com.itextpdf.pdfocr.onnxtr.util
Class BufferedImageUtil
java.lang.Object
com.itextpdf.pdfocr.onnxtr.util.BufferedImageUtil
Additional algorithms for working with
BufferedImage.
-
Method Summary
Modifier and TypeMethodDescriptionstatic List<BufferedImage>extractBoxes(BufferedImage image, Collection boxes) Extracts sub-images from an image, based on provided rotated 4-point boxes.static BufferedImagerotate(BufferedImage image, TextOrientation orientation) Rotates image based on text orientation.static FloatBufferMdArraytoBchwInput(Collection<BufferedImage> images, OnnxInputProperties properties) Converts a collection of images to a batched ML model input in a BCHW format with 3 channels.static BufferedImagetruncateToRatio(BufferedImage image, double ratioLimit) Truncates the input image, so that neither width/height, nor height/width ratios exceed the limit.
-
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
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
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
-
truncateToRatio
Truncates the input image, so that neither width/height, nor height/width ratios exceed the limit.If width/height ratio exceeds the limit, the image will be truncated on left and right equally.
If height/width ratio exceeds the limit, the image will be truncated on top and bottom equally.
- Parameters:
-
image- input image to truncate -
ratioLimit- target ratio limit - Returns:
- the truncated image
-