Conversion to grayscale

In most cases, color is not needed for recognition and can even mislead OCR algorithms. Grayscale allows images to be processed more efficiently, resulting in less specks, cleaner backgrounds, and crisper text than color images. Converting to grayscale can also improve the results of other preprocessing filters, such as automatic deskewing.

Aspose.OCR provides a method for converting an image to grayscale before proceeding with preprocessing or OCR.

Grayscale conversion

To convert the image to grayscale, run the image through ToGrayscale preprocessing filter.

AsposeOCR api = new AsposeOCR();
// Apply automatic grayscale conversion
PreprocessingFilter filters = new PreprocessingFilter();
filters.add(PreprocessingFilter.ToGrayscale());
// Prepare batch
OcrInput images = new OcrInput(InputType.SingleImage, filters);
images.add("image.png");
// Save processed images to the folder
ImageProcessing.Save(images, "C:\\images");
Color image Grayscale image

Usage scenarios

Grayscale conversion is recommended for the following images:

  • Photos.
  • Scanned ID cards and other personal documents.
  • Full-color scans.