1. A workpiece inspection apparatus comprising: a search unit responsive to input of a reference image for searching the input reference image for a first group of pixels containing therein a certain pixel and a second group of pixels having grayscale values within a predetermined threshold; a probability acquisition unit responsive to receipt of an optical image of a workpiece being tested and said reference image, for acquiring a probability value based on a grayscale value of said certain pixel in said reference image and a grayscale value of a pixel corresponding to said certain pixel in the second pixel group searched along with a grayscale value of a pixel of said optical image corresponding to said certain pixel in said reference image and a grayscale value of a pixel of said optical image corresponding to a pixel in said second pixel group corresponding to said certain pixel; and a determination unit operative to use said probability value to determine whether a defect is present at the pixel of said optical image corresponding to said certain pixel.