Binarization

While you can extract text from color or grayscale scans or photographs, Aspose.OCR for JavaScript via C++ engine always uses black and white images to detect text and perform automatic corrections. The conversion to black-and-white is performed automatically; this process is called binarization.

In some rare cases, you may need to override the automatic binarization settings to get more accurate recognition results:

  • Poor quality printouts such as faxes or receipts on thermal paper.
  • Photos with glares and gradients taken in low-light conditions.
  • Multicolored texts.

If you notice that part of the text disappears from the recognition results, try manually specifying the threshold criteria that determine whether a pixel is considered black or white. If a pixel is lighter than the threshold, it is considered a white pixel, otherwise it is considered a black pixel. In other words, the higher the threshold value, the more content will be sent for recognition, including words printed in very light colors. If the threshold set to 0, the black and white are assigned automatically based on the content of the image.

To specify binarization threshold, set threshold_value property in recognition setting. To rely on automatic processing, do not set the threshold_value.

var settings = Module.WasmAsposeOCRRecognitionSettings();
settings.threshold_value = 20;

Live demo

Source Binarization threshold: auto Binarization threshold: 50 Binarization threshold: 100 Binarization threshold: 150 Binarization threshold: 200
Threshold:

Code snippet

var source = Module.WasmAsposeOCRInput();
source.url = filename;
var content = new Module.WasmAsposeOCRInputs();
content.push_back(source);
// Set binarization threshold
var settings = Module.WasmAsposeOCRRecognitionSettings();
settings.threshold_value = 0;
// Recognize image
var result = Module.AsposeOCRRecognize(content, settings);
var result_str = Module.AsposeOCRSerializeResult(result, Module.ExportFormat.text);
console.log(result_str);

Recognition result

<specify threshold value to recognize the image>
Optical character recognition or
is the electronic or
conversion of images of typed,
handwritten ore text into
machine-encoded text, whether from a
scanned document, a photo of a document,
a scene-photo or from subtitle text
superImposed on an image.
Optical character recognition or
Is the or
conversion of images of typed,
or printed text into
machine-encoded text, whether from a
scanned document,
a or from subtitle text
superimposed on an image.
Optical character recognition or
is the electronic or
conversion of images of typed,
or printed text into
machine-encoded text, whether from a
scanned document, a photo of a document,
a or from subtitle text
superimposed or an Image.
Optical character recognition or
is the electronic or
conversion of images of typed,
handwritten or printed text into
machine-encoded text, whether from a
scanned document,a photo of a document,
a scene-photo or from subtitle text
superimposed on an image.
Optical character recognition or optical
character reader is the electronic or
mechanical conversion of images of typed,
handwritten or printed text into
machine-encoded text, whether from a
scanned document,a photo of a document,
a scene-photo or from subtitle text
superimposed on an image.

Usage scenarios

Specifying custom binarization threshold is recommended when recognizing:

  • Colored texts.
  • Images with low contrast between text and background.
  • Photos with glares caused by uneven lighting, such as spot lights or flash.