A method for inspecting a substrate for defects, including: (a) obtaining
an inspected pixel and a reference pixel; (b) calculating an inspected
value and a reference value, the inspected value representative of the
inspected pixel and the reference value representative of the reference
pixel; (c) selecting a threshold in response to a selected value out of
the inspected value and the reference value; and (d) determining a
relationship between the selected threshold, the reference value and the
inspected value to indicate a presence of a defect.