moadeep
moadeep

Reputation: 4118

linux Getting text from table in image

I have several hundred images of the format below. I would like to extract the key value text from the table below the header detector 2 results. i.e key Isotope, Value Tc99m, key Peak, Value 140.3 kEV. Obviously, I would prefer to do this in a bash script rather than manually going through each image. I have heard of tools such as imagemagick and ocr which seem to do what I want. However, I have no experience of either tool. How should I approach this problem and is is solvable?

Would I be best to crop the approximate region containing the table, doing some contrast adjustment to clear up the text before running ocr?

enter image description here

Upvotes: 0

Views: 855

Answers (1)

rostok
rostok

Reputation: 2137

I had very similar case. Instead of identifying kEV I had to match employees identification numbers from salary reports. My approach was as follows: crop image to area with the number, OCR the cropped image and finally read the text file. Tools I used: PHP script for general batch job and page iteration, imagemagick to convert PDF to PNGs, PHP GD library to crop images and save them as PNGs (please note that imagemagick has command line support for cropping) and finally Tesseract to OCR the text. I found that Tesseract is quite reliable if image is B&W and computer generated, provided it is of high resolution ofcourse. In my case single digit was about 11x18 pixels.

Obviously you should know how to crop image with IM (http://www.imagemagick.org/Usage/crop/) and how to autolevel it (http://fmwconcepts.com/imagemagick/autolevel/index.php havent tried it). Cropping example for starters is below. However I believe you will need much bigger resolution. Also avoid passing table edges to OCR.

convert yrhxY.png -crop 44x12+146+204 -negate output.png

Finally answering your question: yes - first cropping, then OCR.

Upvotes: 1

Related Questions