How to convert an image of text into a binary view in Node.JS using Deep Learning

Original article can be found here (source): Deep Learning on Medium

How to convert an image of text into a binary view in Node.JS using Deep Learning

Before optical character recognition can be properly performed on a text image, some pre-processing should be done to ensure more accurate results. Besides rotating the image (covered in a separate article), the most effective means of pre-processing is to convert it to binary view, or pure black and white. Today we will be using an API to take care of the Deep Learning aspect of this process and allow us to skip all of the pain and suffering.

So let’s start things up with a quick installation of our client via npm install:

npm install cloudmersive-ocr-api-client --save

Now input your image into this function here to start the binarization.

var CloudmersiveOcrApiClient = require('cloudmersive-ocr-api-client');var defaultClient = CloudmersiveOcrApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveOcrApiClient.PreprocessingApi();var imageFile = "/path/to/file"; // File | Image file to perform OCR on. Common file formats such as PNG, JPEG are supported.var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.preprocessingBinarizeAdvanced(imageFile, callback);

Done! The image will be returned to us in simple black and white, which will greatly enhance its OCR potential.