Image processing

The accuracy and reliability of text recognition is highly dependent on the quality of the original image. Aspose.OCR offers a large number of fully automated and manual image processing filters that enhance an image before it is sent to the OCR engine.

Each preprocessing filter increases the image processing time. The approximate amount of additional time required for pre-processing (as a percentage of the minimum image processing pipeline) is listed in the Performance Impact column.

Filter Action Performance impact Usage scenarios
Skew correction Automatically straighten images aligned at a slight angle to the horizontal. 12% Skewed images
Rotation Manually rotate severely skewed images. 7.5% Rotated images
Noise removal Automatically remove dirt, spots, scratches, glare, unwanted gradients, and other noise from photos and scans. 175% extra time
38% more memory (1)
Photos
Old books
Newspapers
Postcards
Documents with stains and dirt
Contrast correction Automatically adjust the image contrast. 7.5% Photos
Old papers
Text on a background
Resizing Proportionally scale images up / down, or manually define the width and height of the image. up to 100% (2) Medication guides
Food labels
Full-sized photos from modern cameras and smartphones
Scanned images at very high DPI
Binarization Convert images to black and white automatically or manually adjust the criteria that determines whether a pixel is considered black or white. 0.9% Always used for text detection and most automatic image corrections
Conversion to grayscale Discard color information from images and leave only shades of gray. 0.5% Photos
Scanned ID cards
Full-color scans
Color inversion Swap image colors so that light areas appear dark and dark areas appear light. 0.25% White text on black background
Advertisements
Business cards
Screenshots
Dilation Increase the thickness of characters in an image by adding pixels to the edges of high-contrast objects, such as letters. 3.1% Receipts
Printouts with very thin font
Median filter Blur noisy images while preserving the edges of high-contrast objects like letters. 6.25% Photos taken in low light conditions
Poor quality printouts
Highly compressed JPEG’s
Dewarping Straighten page curvature and fix camera lens distortion for page photos.
This method requires significant resources and time! Consider using it only if the image has geometric distortions preventing accurate recognition.
30-40 seconds;
Up to 4 times more memory (3)
Photos of curved pages
Ultra wide-angle and fisheye photos
Photos from entry-level smartphones

Notes

  1. Automatic noise removal uses a powerful artificial intelligence algorithm that consumes significant computing resources and RAM. Use it with care, especially when developing public websites and mobile apps.
  2. Resizing takes between 6% and 100% more time than the minimum processing pipeline, depending on the original image size.
  3. Due to the high complexity of the underlying neural network, dewarping is resource- and time-intensive. Actual numbers may vary greatly depending on the performance of the computer and the characteristics of the original image.

Chaining preprocessing filters

Multiple preprocessing filters can be applied to the same image to further improve the recognition quality. The filters are applied one by one in the order they are added to PreprocessingFilter object.

Note that each filter requires additional time and resources on the computer running the application. Do not add extra filters if you are satisfied with the recognition accuracy, especially when developing web applications.

PreprocessingFilter filters = new PreprocessingFilter();

Approximate increase of processing time: 0%

Image regions preprocessing

Most preprocessing filters can be applied to specific regions of an image. For example, you can invert a newspaper headline written in white on black, leaving the rest of the article unchanged.

Multiple preprocessing filters can be applied to different regions of the same image. If the regions intersect each other, filters are applied to the intersection in their chaining order in PreprocessingFilter object.

Applying preprocessing to intersecting regions

To apply a filter to an area, specify its top left corner along with width and height as Rectangle object. If the region is omitted, the filter is applied to the entire image.

// Define image regions
Rectangle blackRectangle = new Rectangle(5, 161, 340, 113);
PreprocessingFilter filters = new PreprocessingFilter();
// (1) Invert black region
filters.add(PreprocessingFilter.Invert(blackRectangle));
// (2) Denoise entire image
filters.add(PreprocessingFilter.AutoDenoising());

The following filters can be applied to regions:

Previewing and saving processed images

Aspose.OCR for Java offers an easy way to access or save processed images using the methods of the static ImageProcessing class:

Method Return value Description
Render OcrInput Applies processing filters to all images in a batch and returns a new batch with processed images. This batch can later be submitted for recognition or used for optimization.
Save OcrInput Applies processing filters to all images in batch and saves the resulting images in the specified folder. That method also returns a new batch with processed images, that can be later submitted for the recognition.

You can use these methods to analyze the effectiveness of processing filters, exclude unnecessary filters that consume resources without affecting the result, or show the result of image processing in the user interface.

  • Processing filters are applied to all images in the batch, including those without text.
  • PDF documents can contain more than one image per page. Therefore, the resulting OcrInput object can contain more images than the number of pages in the document.
// Set processing filters
PreprocessingFilter filters = new PreprocessingFilter();
filters.add(PreprocessingFilter.AutoDenoising());
filters.add(PreprocessingFilter.Median());
// Prepare batch
OcrInput images = new OcrInput(InputType.SingleImage, filters);
images.add("image1.png");
images.add("image2.jpg");
// Save processed images from the provided PDF to the folder
ImageProcessing.Save(images, "C:\\images");
Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.