1. An image processing apparatus comprising: an obtaining section configured to obtain a background image only of a background in which a subject is not present, and a subject-present image in which a subject is present; a determination section configured to specify an image area which is contained in the subject-present image obtained by the obtaining section and in which a value of nonflatness is less than or equal to a predetermined value, and to determine whether or not a range of the specified image area is greater than or equal to a predetermined range; a background generation section configured to generate an extraction background image used to extract a subject area from the subject-present image based on information on the image area when the determination section determines that the range of the image area is greater than or equal to the predetermined range; a judgment section configured to determine whether generation of the extraction background image by the background generation section has succeeded or failed; and a subject extraction section configured to extract the subject area from the subject-present image based on the generated extraction background image when the judgment section determines that the generation of the extraction background image has succeeded, and to obtain the background image by the obtaining section and extract the subject area from the subject-present image based on the obtained background image when the judgment section determines that the generation of the extraction background image has failed.