An image processing apparatus performs image processing based on image data and ranging data output from an image sensor. The ranging data represents a distance between the image sensor and a subject. The image sensor is configured to receive reflected light of illumination light reflected from the subject and to output the image data and the ranging data. The image processing apparatus includes a processor configured to: calculate a parameter of the illumination light emitted onto a point on the subject, based on the ranging data; calculate a parameter of the reflected light, based on a gradient of a depth on the point on the subject calculated from the ranging data; and calculate the distance between the image sensor and the subject in a direction orthogonal to a light-receiving surface of the image sensor, based on the image data and the parameters of the illumination light and the reflected light.