This works to extract the black letters on the white background. But you have to extract the largest white area count (12119) from the terminal (or write script code to filter the list and get the area count). I can solve that in unix, but do not know windows.
# make the image binary and change the white border to black
Code: Select all
convert 405_B.jpg -threshold 50% -bordercolor white -border 10 -fill black -draw "color 0,0 floodfill" -alpha off -shave 10x10 405_B_floodfill.gif
# get the connected components list of objects -- note the first line is the black backgrouknd and the second line is the largest white region, which is what you want.
Code: Select all
convert 405_B_floodfill.gif -define connected-components:verbose=true -connected-components 4 405_B_objects.png
0: 1272x158+0+0 660.7,78.4 160167 srgb(0,0,0)
39: 179x96+517+23 604.5,70.9
12119 srgb(255,255,255)
102: 154x80+100+42 175.4,83.4 4022 srgb(255,255,255)
126: 132x70+958+52 1026.8,89.1 2660 srgb(255,255,255)
67: 121x78+317+33 362.7,71.1 2133 srgb(255,255,255)
81: 118x77+741+36 785.5,73.5 1972 srgb(255,255,255)
80: 57x67+321+36 347.0,72.5 1942 srgb(0,0,0)
...
# filter the objects so you keep only the black background
Code: Select all
convert 405_B_objects.png -define connected-components:area-threshold=12119 -connected-components 4 -auto-level -morphology erode octagon:1 405_B_objects_ccl.png
# make composite the images to make the background transparent in your original image and then trim and convert the transparent areas to white.
Code: Select all
[code]convert 405_B.jpg 405_B_objects_ccl.png -alpha off -compose copy_opacity -composite -trim +repage -background white -alpha background -alpha off 405_B_result.gif
[/code]
You can now do connected components to extract each black letter in a similar manner. See
http://www.imagemagick.org/script/conne ... onents.php
How much are you paying!