1. A pattern inspection apparatus comprising: an optical image acquisition unit configured to acquire an optical image of a target workpiece to be inspected on which a pattern is formed; a reference image generation unit configured to generate a reference image to be compared with the optical image; a least-squares method calculation unit configured, by using a mathematical model in which a parallel shift amount displaced from a position where the optical image and the reference image are aligned by a pixel unit, an expansion and contraction error coefficient, a rotation error coefficient, a gray-level offset and an image transmission loss ratio are parameters, to calculate each of the parameters by a least-squares method; a corrected image generation unit configured to generate a corrected image by shifting a position of the reference image by a displacement amount displaced from the position aligned by the pixel unit, based on the each of the parameters; and a comparison unit configured to compare the corrected image with the optical image.