Edges of layers are detected from an input image to create a boundary line candidate image that represents the detected edges. A luminance value of the input image is differentiated to create a luminance value-differentiated image that represents luminance gradient of the layers. An evaluation score image is created which is obtained by weighting calculation at an optimum ratio between a boundary line position probability image and the luminance value-differentiated image. The boundary line position probability image is obtained from the boundary line candidate image and an existence probability image that represents existence of a boundary line to be extracted. A route having the highest total evaluation score is extracted as the boundary line. According to such an image processing apparatus and image processing method, boundary lines of layers can be extracted with a high degree of accuracy from a captured image of a target object composed of a plurality of layers.