An image processing apparatus characterized by comprising: statistical model storage means for storing a plurality of statistical models, wherein each statistical model is generated by learning bokeh and outputs an estimated bokeh value in an input image as an estimated distance of a subject in the input image, whereby each statistical model corresponds to one lens of a plurality of lenses and an image sensor, whereby the one lens and the image sensor represent a first optical system, wherein bokeh that occurs in a first image affected by aberration of the first optical system varies non-linearly in accordance with a distance to a subject in the first image and wherein a statistical model for the first optical system outputs an estimated bokeh value as an estimated distance to a subject in an image; image acquisition means for acquiring a second image affected by aberration of a second optical system; aberration map storage means for storing a plurality of aberration maps wherein an aberration map is information indicating the distance dependence and the positional dependence of the bokeh in an image due to the aberration of an optical system, whereby each of the aberration maps is linked with a statistical model corresponding to the lens that caused the bokeh having a distance dependence and positional dependence indicated by the aberration map; statistical model selecting means for selecting statistical model for the second image, by calculating a degree of similarity of an aberration map estimated for a predetermined test pattern image with the aberration maps stored in the aberration maps storage means, and selecting the statistical model from the statistical model storage means that corresponds to the aberration map from the aberration map storage means which is most similar to the estimated aberration map for the predetermined test pattern image, wherein the second image and the test pattern image are obtained using the second optical system and same lens; and distance acquisition means configured to input the acquired second image into the statistical model selected by the statistical model selecting means to acquire distance information indicating a distance to a subject in the second image. statistical model storage means for storing a plurality of statistical models, wherein each statistical model is generated by learning bokeh and outputs an estimated bokeh value in an input image as an estimated distance of a subject in the input image, whereby each statistical model corresponds to one lens of a plurality of lenses and an image sensor, whereby the one lens and the image sensor represent a first optical system, wherein bokeh that occurs in a first image affected by aberration of the first optical system varies non-linearly in accordance with a distance to a subject in the first image and wherein a statistical model for the first optical system outputs an estimated bokeh value as an estimated distance to a subject in an image; image acquisition means for acquiring a second image affected by aberration of a second optical system; aberration map storage means for storing a plurality of aberration maps wherein an aberration map is information indicating the distance dependence and the positional dependence of the bokeh in an image due to the aberration of an optical system, whereby each of the aberration maps is linked with a statistical model corresponding to the lens that caused the bokeh having a distance dependence and positional dependence indicated by the aberration map; statistical model selecting means for selecting statistical model for the second image, by calculating a degree of similarity of an aberration map estimated for a predetermined test pattern image with the aberration maps stored in the aberration maps storage means, and selecting the statistical model from the statistical model storage means that corresponds to the aberration map from the aberration map storage means which is most similar to the estimated aberration map for the predetermined test pattern image, wherein the second image and the test pattern image are obtained using the second optical system and same lens; and distance acquisition means configured to input the acquired second image into the statistical model selected by the statistical model selecting means to acquire distance information indicating a distance to a subject in the second image.