Fred's ImageMagick Scripts
|
Computes the normalized cross correlation surface to find where a small image best matches within a larger image. |
last modified: August 25, 2009
|
USAGE: normcrosscorr [-s] [-p] [-m mode] [-c color] smallfile largefile corrfile [matchfile]
-s .............. stretch the correlation surface to full dynamic range so PURPOSE: To compute the normalized cross correlation surface to find where a small image best matches within a larger image. DESCRIPTION: NORMCROSSCORR compute the normalized cross correlation surface (image) to find where a small (first) image best matches within a larger (second) image. Since the matching may differ for each channel, the two input images will be converted to grayscale. Any alpha channel on either image will be removed automatically before processing. WARNING: I believe due to the way ImageMagick normalizes images internally to a dynamic range of 0 to 1 before doing any processing, the correlation surface will not generally have a perfect match score of +1, but will be image dependent and smaller than 1. Nevertheless, it does seem to find the correct best match location. ARGUMENTS: -s ... Stretch the normalized cross correlation surface image to full dynamic range so that the best match is full white. Default is no stretch -p ... Apply a pseudocoloring to the normalized cross correlation surface image where red corresponds to the highest values and purple to the lowest values. Default is no pseudocoloring. -m mode ... MODE is the layout mode for the optional matchfile image. Choices are draw (or d) or overlay (or o). Draw simply draws a colored box outline at the best match subsection in the larger image. Overlay inserts the small image at the match location of a one-half transparent version of the larger image. The default="draw". Ignored if no matchfile specified. -c color ... COLOR is the color to use to draw the outline of the best matching subsection in the larger image when mode=1. Any valid IM color specification may be used. The default=black. REQUIREMENTS: IM version 6.5.4-7 or higher, but compiled with HDRI enabled in any quantum level of Q8, Q16 or Q32. Also requires the FFTW delegate library. See Fourier Transform Processing with ImageMagick, for more details. CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk. |
|
Small Image |
Large Image |
|
|
|
Arguments: |
|
|
Correlation Image |
Match Location |
|
|
|
Arguments: |
|
|
Correlation Image |
Match Location |
|
|
|
Small Image |
Large Image |
|
|
|
|
Arguments: |
|
|
Correlation Image |
Match Location |
|
|
|
What the script does is as follows:
See the script for actual code details. Or for more mathematical detail |