Apparatus 20 for inspecting photomasks 26 and the like by comparison of duplicate die patterns, including improved defect detection. Two-dimensional pixel representations of two die patterns are formed, with pixels having values or black or white or shades or grey, depending upon the features of the die patterns. Defects in the die patterns are found by a defect detector circuit 60 at points of non-agreement between the pixel representations. Two window matrices 130 and 134 of adjacent pixels are defined for corresponding areas of the two die patterns. The center matrix of each window matrix is defined as a comparison matrix 132 and 136. An error value is computed for subsets of the window matrix by summing the squares of the differences between each of the pixel values of each subset and the corresponding pixel values of the opposite comparison matrix. If there is no defect and any misalignment between the two representations minimal, at least one error value will be less than a threshold error value. If none of the error values are less than the threshold error value, a defect is assumed. The magnitude of the threshold error value is automatically varied according to the number and type of edges within the window matrices to compensate for edge quantization errors of less than one pixel.