I see two basic methods, all of which generates a grayscale map of match probabilities
- Sub-image compare (very slow)
- Using Morphology - hit-n-miss, or Correlation
- Fast Fourier Transforms Multiply (actually a convolve, which with a 180 rotation of sub-image generates a correlation)
"Compare" first handles color images, but does not handle transparency (replace with a grey or some other general background color). The other two techniques are really gray scale channel matching, and not true color vector distance matching.
Code: Select all
convert search_image_orig.png -background gray50 -flatten search_image.png
compare -subimage-search -dissimilarity-threshold 100% \
search_orig.png search_image.png search_results-%d.png
Inputs...
results:
Two images are generates, a 'best match highlight image' and the 'greyscale match probably map image'
Note the four very bright spots where the 'best matches' were found.
NOTE the probably map image is smaller, as "compare" makes no attempt to find a partial match!
The two morphology methods needs you to convert the sub-image into one or more arrays of floating point values. The script
image2kernel can do this.
What is more these can handle shaped images! basically the transparent parts are converted to 'non-values' (NaN or Not a Number, special floating point values) I designed it that way!!!!!
For examples see... Correlation and Shape Searching
http://www.imagemagick.org/Usage/convol ... ate_search
this also goes into enhancing the probability map to locate the 'peaks' better.
FFT is the faster method for larger search images, but involves converting the image into a very different form of data (frequency maps). unfortunately it does not handle shapes, so like sub-image search map the transparency to a general background color.
WARNING: None of the above handles rotations of the search image! For that much more complex methods are needed, or multiple search patterns.