A method is provided to automatically arrange scanned images so they can
be stitched into a composite image. Initially the scanned images are
reduced to low resolution and a gradient filter is applied. One scanned
image is selected as a possible first image in a stitching order. The
possible first image is rotated to one angle and correlated with
remaining scanned images rotated to two corresponding angles. Only four
scanned images that best correlate with the possible first image and pass
a threshold are saved as possible second images in the order. The steps
are repeated for subsequent places in the order and for the possible
first image at other angles. The method is repeated for other possible
first images to form other orders. At the end, a path through one of the
orders that produces the best sum of correlation values is set as the
correct stitching order.