Color inversion

When working with white (or light) text on a black (or other dark) background, recognition accuracy may suffer. It can be greatly improved by reversing the colors of the image so that light areas appear dark and dark areas appear light. In addition, other colors are also swapped: red becomes cyan, green becomes magenta, blue becomes yellow, and so on.

Aspose.OCR provides the automated preprocessing filter that inverts colors in the image before proceeding to recognition.

Inverting image colors

To automatically invert colors in an image before recognition, run the image through OCR_IMG_PREPROCESS_INVERT preprocessing filter.

std::string image_path = "source.png";
custom_preprocessing_filters filters_;
filters_.filter_1 = OCR_IMG_PREPROCESS_INVERT;
asposeocr_preprocess_page_and_save(image_path.c_str(), "result.png", filters_);
White text on dark background Inverted image

Usage scenarios

Automatic color inversion is recommended for the following images:

  • White text on black background.
  • Advertisements.
  • Business cards.
  • Screenshots.