Page 1 of 1

Image pre-processing for Tesseract

Posted: 2016-10-28T11:02:46-07:00
by sayshot
Hello Everybody! I'm new in the forum, I mean, I have been using it but never posted before.

I'm trying to find the best way of pre-processing an image/photo of handwritting text to then give it to tesseract.
My objective is the background to be white and the characters to be black, but with a nice shape, and without thouse black dots/pixels in random places that shouldn't be there.

I have tried some basics thresholdings but the problem is that the binary one (this gave me the best result) some of the times adds a lot of black pixels where it shouldn't, and also only doing thresholding does not enhace the characters shape.

I have found this android market application: OCR Instantly Free. This app does a very pretty good enhace of the image and what I would love to know how does it does it! Any ideas how can I achive something like it?
The pretty interesting tool is that the user can change dinamically and in real-time two values named by the app like "Exposure" and "Noise reduction" but I'm not sure witch image magick parameters this are.

Image
Image
Image
Image
Image

Hope you can help me!
Regards,
A new user (:

Re: Image pre-processing for Tesseract

Posted: 2016-10-28T12:40:28-07:00
by snibgo
There are many threads that address this problem. I would start by making an image of just the background paper, made by a bilinear gradient from the four corners of the input. By subtraction (or division), we get a good image of dark text on a light background. This will certainly need thresholding, and possibly noise reduction.

Re: Image pre-processing for Tesseract

Posted: 2016-10-28T13:26:12-07:00
by fmw42
Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your exact command line and if possible your images.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at viewtopic.php?f=1&t=9620

For novices, see

viewtopic.php?f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/


Your images are rather small. Is this the original size?

Try

Code: Select all

convert original1.png -colorspace gray -negate -lat 10x10+2% -negate result.png

Re: Image pre-processing for Tesseract

Posted: 2016-10-31T21:02:36-07:00
by sayshot
snibgo wrote:There are many threads that address this problem. I would start by making an image of just the background paper, made by a bilinear gradient from the four corners of the input. By subtraction (or division), we get a good image of dark text on a light background. This will certainly need thresholding, and possibly noise reduction.
Thank you very much for your answer. Could you explain how to do this "bilinear gradient from the four corners of the input." and how to the de division between images? Also another question, should the two images have the exact same resolution/size?

Re: Image pre-processing for Tesseract

Posted: 2016-10-31T21:05:35-07:00
by sayshot
fmw42 wrote:Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your exact command line and if possible your images.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at viewtopic.php?f=1&t=9620

For novices, see

viewtopic.php?f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/


Your images are rather small. Is this the original size?

Try

Code: Select all

convert original1.png -colorspace gray -negate -lat 10x10+2% -negate result.png
Thank you very much for your answer.
My IM version is: Version: ImageMagick 6.8.9-9 Q16 x86_64 2016-06-01
My OS is Ubuntu 16.04 LTS

convert original1.png -colorspace gray -negate -lat 10x10+2% -negate result.png
That line is pretty good if you play with -lat values ! Is not perfect, but good