Other methods for binary symbols is to use morphology, or correlation, both of which is currently on the IM Examples page
http://www.imagemagick.org/Usage/morphology/
The disadvantage is that you currently can not generate a 'search pattern' using an image. However
I can see ways to generate a 'kernel' from an image. For example...
first a image of many symbols to search...
Code: Select all
convert label:"AWNSuj4CPqQ4w1XfBkmUMT-7
G,FyRtWIyvmmSfigTj5dYp25
Jnkfh,fxghFkGtTdVSu,1,u8
M-eXsDl1UIeeOMUoOskASTCG
QN,z0IstoiNtnNOBg5o7Rx,y" -threshold 50% -negate text.gif
now lets generate a 'symbol' image to search can convert it into a kernel string....
Code: Select all
convert label:"5" -threshold 50% -trim +repage -negate symbol.gif
convert symbol.gif -format '%wx%h:' info: > kernel.txt
convert symbol.gif -compress none pgm: | tail -n +4 | sed 's/255/1/g' >> kernel.txt
the 'kernel.txt' file now contains the search pattern...
Code: Select all
5x8:
1 1 1 1 0 1 0 0 0 0 1 1 1 1 0 1 0 0 1 1 0 0 0 0 1
0 0 0 0 1 1 0 0 1 1 1 1 1 1 0
Now you can search for that symbol in the above, using 'erode'
Code: Select all
convert text.gif -morphology erode "`cat kernel.txt`" show:
And it works... the result is a black image with 3 white pixels showing the locations
of the '5' characters.
NOTE the use of '@file' is not yet available for -morphology, just as generating a kernel from image is also not yet available.
NOTE When 'hit-n-miss' morphology development has finished that will not just match
the 'on' pixels as in the above, but also 'off' pixels.
NOTE: Correlation would not just find exact matches, but also 'near' matches, but by replacing the zeros in the kernel with -1 you can also match backgrounds ( as hit-n-mis morphology would.
Correlation can also be done using very LARGE search images (directly) using Fast Fourier Transform Techniques that are still being developed and added. However 'negative' correlations would need a HDRI version of IM.