Patent ID: 8787675

Claim:
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; wherein the determination section includes: a division section configured to divide the subject-present image obtained by the obtaining section into a plurality of image blocks; a first determination section configured to determine whether or not a value of the nonflatness of each of the plurality of image blocks resulting from the division by the division section is less than or equal to a predetermined value; and a second determination section configured to determine whether or not a number of image blocks, which are determined by the first determination section to have the value of the nonflatness less than or equal to the predetermined value, accounts for at least a predetermined rate of a total number of image blocks; and wherein the background generation section generates the extraction background image from the image blocks when the second determination section determines that the number of image blocks, which have the value of the nonflatness less than or equal to the predetermined value, accounts for at least the predetermined rate of the total number of image blocks.