1. An image processing apparatus comprising: a unit which acquires a plurality of images captured in different exposure times; a setting unit which, when the plurality of images are aligned in order of exposure time, sets pairs each of two images adjacent on a line; a specification unit which, when an image having a longer exposure time out of two images contained in a pair of interest is defined as a long-time image and an image having a shorter exposure time is defined as a short-time image, specifies common regions in the long-time image and the short-time image, based on pixel value distributions of the long-time image and short-time image; a calculation unit which calculates a location error correction amount of the long-time image to make the common region in the long-time image match the common region in the short-time image when the long-time image and the short-time image are overlapped with each other; a processing unit which performs image processing for the long-time image based on the location error correction amount; and a unit which generates a composite image by compositing the plurality of images obtained by processing each pair by the processing unit, and outputs the generated composite image.