1. An image processing apparatus for measuring a subject distance using a plurality of captured images acquired by capturing the same subject in a plurality of focus states, the image processing apparatus comprising: a target motion amount estimation unit configured to estimate a target motion amount that represents an amount of shift in a position of the subject between a first image and a second image among the captured images, the first image being captured in a first focus state, and the second image being captured in a second focus state different from the first focus state; a corrected image generation unit configured to generate a corrected image by performing motion compensation on the second image based on the target motion amount; and a subject distance measurement unit configured to measure a subject distance for the first image based on a correlation value in out-of-focus amount between the first image and the corrected image.