1. An image processing apparatus comprising a CPU, wherein the CPU is operable as: an image acquisition unit that acquires data of a plurality of captured images that are imaged at a plurality of focus positions; a sequence determination unit that determines a sequence of combination for combining data of a plurality of the captured images, the sequence of combination being different from both (i) a progressive sequence of focus distances and (ii) a sequence of imaging; a reference image specification unit that specifies a reference image to be a reference for combining; and a combination unit that, based on the reference image specified by the reference image specification unit, combines the data of the plurality of the captured images in the sequence of combination determined by the sequence determination unit, and creates data of an omnifocal image, wherein the sequence determination unit alters the sequence of combination based on relationships between focus positions of the captured images acquired by the image acquisition unit and a focus position of the reference image.