Image pre-processing for Tesseract

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
sayshot
Posts: 3
Joined: 2016-10-28T10:13:46-07:00
Authentication code: 1151

Image pre-processing for Tesseract

Post 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 (:
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image pre-processing for Tesseract

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image pre-processing for Tesseract

Post 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
sayshot
Posts: 3
Joined: 2016-10-28T10:13:46-07:00
Authentication code: 1151

Re: Image pre-processing for Tesseract

Post 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?
sayshot
Posts: 3
Joined: 2016-10-28T10:13:46-07:00
Authentication code: 1151

Re: Image pre-processing for Tesseract

Post 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
Post Reply