1. An image processing apparatus comprising: a defined binary image generating unit configured to generate a defined binary image associated with a level image, which is associated with an input image, the level image having pixel values of individual pixels represented using a first value indicating the level of a pixel value in a foreground image region in the input image, the defined binary image being generated by regarding, in a case where the first value of a pixel in the level image is close to a maximum value or close to a minimum value, the pixel as a defined region pixel located in a defined region and setting the pixel to have a predetermined second value, and by regarding, in a case where the first value of a pixel in the level image is neither close to the maximum value nor the minimum value, the pixel as an undefined region pixel located in an undefined region and setting the pixel to have a predetermined third value; an estimated foreground color image generation unit configured to generate an estimated foreground color image associated with the input image, in which the pixel values of the individual pixels that are regarded as the undefined region pixels and that are set to have the predetermined third value in the defined binary image are set to pixel values of pixels in the input image corresponding to pixels for which distances each obtained from an integrated value of the amounts of change in continuity information are shortest from among the pixels that are regarded as the defined region pixels and that are set to have the predetermined second value; a weighted-image generating unit configured to apply a weight to each of the individual pixels that are regarded as the undefined region pixels and that are set to have the predetermined third value in the defined binary image and generating a weighted image associated with the defined binary image; a matrix generating unit configured to generate a Laplacian matrix in accordance with path information in which the individual pixels in the level image are expressed by a graph structure; a function generating unit configured to generate an energy function employing a foreground color image as a parameter in accordance with the weighted image, the Laplacian matrix, and the estimated foreground color image; and a foreground color image calculating unit configured to calculate a foreground color image for which a minimum energy function is obtained.