A system and method for correcting surface height measurements for optical
aberration is provided. Heights determined by an autofocus tool, which
may depend on surface feature angles in a focus region of interest (ROI)
and on the ROI location in the field of view, are corrected based on a
novel error calibration. Error calibration data includes height
corrections for different feature angles in images, and for multiple
locations in a field of view. Height corrections are determined by
weighting and combining the angle dependent error calibration data, e.g.,
based on a gradient (edge) angle distribution determined in the ROIs.
When Z-heights are determined for multiple ROIs in a field of view,
storage of image data from particular images of a global image stack may
be efficiently controlled based on determining early in processing
whether a particular image is a sufficiently focused "near-peak" focused
image or not.