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, characterized in that the subject distance measurement unit is configured to measure the subject distance for the first image based on a correlation value in out-of-focus amount between the first image and the corrected image, wherein the image processing apparatus receives the first image, the second image, and a third image, the second image being captured during a time interval between the first image and the third image, and the third image being captured in the first focus state at a time different from a time when the first image is captured, and the target motion amount estimation unit includes: a first motion amount estimation unit configured to estimate a first motion amount that represents an amount of shift in a position of the subject between the first image and the third image; and a target motion amount determination unit configured to estimate the target motion amount using the first motion amount. 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, characterized in that the subject distance measurement unit is configured to measure the subject distance for the first image based on a correlation value in out-of-focus amount between the first image and the corrected image, wherein the image processing apparatus receives the first image, the second image, and a third image, the second image being captured during a time interval between the first image and the third image, and the third image being captured in the first focus state at a time different from a time when the first image is captured, and the target motion amount estimation unit includes: a first motion amount estimation unit configured to estimate a first motion amount that represents an amount of shift in a position of the subject between the first image and the third image; and a target motion amount determination unit configured to estimate the target motion amount using the first motion amount. a first motion amount estimation unit configured to estimate a first motion amount that represents an amount of shift in a position of the subject between the first image and the third image; and a target motion amount determination unit configured to estimate the target motion amount using the first motion amount.