Page 1 of 1

"convert" command help - image to b&w text

Posted: 2012-05-07T01:33:04-07:00
by superdx
Hello,

I want to use the "convert" command to produce clear black & white images which I can then use to train OCR software.

The images contain numbers in the format NN.NN (i.e. 12.19 or 1.4 or 2.39 or 78.5), and they are taken from a robotic camera. I am looking for black & white output which shows the digits clearly. Here's a sample:
Image

I tried to C&P some code I found for captchas:

Code: Select all

convert test.png -colorspace Gray -gaussian-blur 9.0 -level 0,30%,0,1 -paint 1 -depth 1 -quality 100 -shave 40x20 test+_c.png
And after some fiddling, I get this:
Image

Notice that the digit 9 is now missing a chunk up top. I'd appreciate any help as I'm almost completely oblivious to image filters and their settings!

Re: "convert" command help - image to b&w text

Posted: 2012-05-07T11:06:55-07:00
by fmw42
try this

convert to HSB, separate the brightness channel (probably similar to -colorspace gray), apply median filter 5x5, use -lat with a large filter size (larger than the width of the letters) and play with the threshold a little, then use -morphology close to remove small noise remaining. Adjust the disk size as desired.

convert number1.png -colorspace HSB -channel blue -separate +channel -median 5x5 -lat 50x50-2% -morphology close disk:1.5 number1_result.png

Image

see
http://www.imagemagick.org/script/comma ... ns.php#lat
http://www.imagemagick.org/Usage/morphology/

Re: "convert" command help - image to b&w text

Posted: 2012-05-08T03:24:45-07:00
by superdx
Wow thank you so very much. This worked perfectly. Truly appreciate the help.