Conversion to grayscale
Contents
[
Hide
]
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 function for converting an image to grayscale before proceeding with preprocessing or OCR.
Grayscale conversion is automatically performed when applying the median filter.
Grayscale conversion
To convert the image to grayscale, run the image through OCR_IMG_PREPROCESS_GRAYSCALE
preprocessing filter.
std::string image_path = "source.png";
custom_preprocessing_filters filters_;
filters_.filter_1 = OCR_IMG_PREPROCESS_GRAYSCALE;
asposeocr_preprocess_page_and_save(image_path.c_str(), "result.png", filters_);
Usage scenarios
Grayscale conversion is recommended for the following images:
- Photos.
- Scanned ID cards and other personal documents.
- Full-color scans.
Improvements in recognition accuracy and preprocessing enhancements will be highly dependent on the original image and should be empirically tested.