An image processing apparatus for generating a contour image in which the contour of an object included in an input image is emphasized, the image processing apparatus comprising: an edge extracting unit configured to extract edges from the input image to generate an edge image; a foreground processing unit configured to acquire a difference in background of the input image using a background image registered in advance and to extract a foreground including an object; a mask unit configured to generate a masked edge image obtained by eliminating, from the edge image generated by the edge extracting unit, edges in a region other than a foreground region specified by the foreground extracted by the foreground processing unit; a synthesis unit configured to synthesize the masked edge image generated by the mask unit and a foreground boundary image constructed of the boundary of the foreground region specified by the foreground extracted by the foreground processing unit so as to generate the contour image; and an output unit configured to output the contour image, wherein: the foreground processing unit is operable to determine that an appropriate foreground has not been extracted from the input image, in accordance with a predetermined criterion, and when the foreground processing unit determines that an appropriate foreground has not been extracted, the output unit outputs the edge image generated by the edge extracting unit as the contour image; and the foreground processing unit is operable to determine that an appropriate edge image has not been generated by the edge extracting unit, in accordance with a predetermined criterion, and when the foreground processing unit determines that an appropriate edge image has not been generated, the output unit outputs the foreground boundary image as the contour image. an edge extracting unit configured to extract edges from the input image to generate an edge image; a foreground processing unit configured to acquire a difference in background of the input image using a background image registered in advance and to extract a foreground including an object; a mask unit configured to generate a masked edge image obtained by eliminating, from the edge image generated by the edge extracting unit, edges in a region other than a foreground region specified by the foreground extracted by the foreground processing unit; a synthesis unit configured to synthesize the masked edge image generated by the mask unit and a foreground boundary image constructed of the boundary of the foreground region specified by the foreground extracted by the foreground processing unit so as to generate the contour image; and an output unit configured to output the contour image, the foreground processing unit is operable to determine that an appropriate foreground has not been extracted from the input image, in accordance with a predetermined criterion, and when the foreground processing unit determines that an appropriate foreground has not been extracted, the output unit outputs the edge image generated by the edge extracting unit as the contour image; and the foreground processing unit is operable to determine that an appropriate edge image has not been generated by the edge extracting unit, in accordance with a predetermined criterion, and when the foreground processing unit determines that an appropriate edge image has not been generated, the output unit outputs the foreground boundary image as the contour image.