The present invention provides a high-precision alignment method, device
and code for inspections that compare an inspection image with a
reference image and detect defects from their differences. In one
embodiment an inspection image and a reference image are divided into
multiple regions. An offset is calculated for each pair of sub-images.
Out of these multiple offsets, only the offsets with high reliability are
used to determine an offset for the entire image. This allows
high-precision alignment with little or no dependency on pattern density
or shape, differences in luminance between images, and uneven luminance
within individual images. Also, detection sensitivity is adjusted as
necessary by monitoring alignment precision.