A first image and a second image are obtained; the amount of deformation of the first image is estimated by evaluating the degree of similarity between a deformed first image and the second image, using an evaluation function that evaluates the correlation between the distribution of corresponding pixel values within the two images; and an image, which is the first image deformed based on the estimated amount of deformation, is generated. The evaluation function evaluates the degree of similarity between the deformed first image and the second image, based on degrees of similarities of divided images that represent degrees of similarities among the distributions of pixel values of each pair of divided first images and divided second images, which respectively are images that the deformed first image is divided into and images that the second image is divided into, according to predetermined dividing conditions.