1. An image processing apparatus comprising: an acquisition unit configured to acquire a boundary between a target area and a non-target area from an image; a setting unit configured to set an undefined area on the periphery of the boundary in a width based on feature quantities of peripheral pixels of the boundary; and a generating unit configured to define an area excluding the undefined area from the target area as the foreground area, define an area excluding the undefined area from the non-target area as the background area, and generate area information that specifies the foreground area, the background area, and the undefined area.