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 processing filters, such as automatic deskewing.

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

Grayscale conversion

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

Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
// Convert image to grayscale
Aspose.OCR.Models.PreprocessingFilters.PreprocessingFilter filters = new Aspose.OCR.Models.PreprocessingFilters.PreprocessingFilter();
// Add an image to OcrInput object and apply processing filters
Aspose.OCR.OcrInput input = new Aspose.OCR.OcrInput(Aspose.OCR.InputType.SingleImage, filters);
// Save processed image to the folder
Aspose.OCR.ImageProcessing.Save(input, @"C:\result");
// Recognize image
List<Aspose.OCR.RecognitionResult> results = recognitionEngine.Recognize(input);
foreach(Aspose.OCR.RecognitionResult result in results)
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.

In addition, grayscale conversion may decrease the original image size.